Example #1
0
        private void OnClientEventTrigger(Client sender, string eventName, object[] arguments)
        {
            if (eventName == "menu_handler_select_item")
            {
                if ((int)arguments[0] == 190)
                {
                    API.consoleOutput(arguments[1].ToString());
                    API.setEntityData(sender, "VehicleOfUsingShop", (int)arguments[1]);
                    List <string> Actions = new List <string>();
                    if (File.Exists("paints.xml"))
                    {
                        IEnumerable <XElement> Paints = xelement.Elements();
                        foreach (var p in Paints)
                        {
                            Actions.Add(p.Attribute("Name").Value.ToString());
                        }
                    }
                    API.triggerClientEvent(sender, "bettermenuManager", 191, "Concessionnaire", "Sélectionner une peinture:", false, Actions);
                }
                else if ((int)arguments[0] == 191)
                {
                    var    pnj = API.getEntityData(sender, "pnj");
                    double cx  = API.getEntityData(pnj, "cX");
                    double cy  = API.getEntityData(pnj, "cY");
                    double cz  = API.getEntityData(pnj, "cZ");

                    List <KeyValuePair <VehicleHash, int> > Products = new List <KeyValuePair <VehicleHash, int> >();
                    Products = API.getEntityData(sender, "ProductsOfUsingShop");
                    int VehicleChoise = API.getEntityData(sender, "VehicleOfUsingShop");
                    API.resetEntityData(sender, "ProductsOfUsingShop");
                    API.resetEntityData(sender, "VehicleOfUsingShop");
                    KeyValuePair <VehicleHash, int> veharray = Products[(int)VehicleChoise];
                    VehicleHash model = veharray.Key;
                    int         price = veharray.Value;
                    API.consoleOutput(model.ToString());
                    if ((int)model == 0)
                    {
                        API.sendNotificationToPlayer(sender, "~r~[ERREUR] ~s~Le véhicule que vous demandez n'est pas disponible."); return;
                    }
                    if (Money.TakeMoney(sender, price))
                    {
                        Vehicle car2  = API.createVehicle(model, new Vector3(cx, cy, cz), new Vector3(0, 0, 20), 111, 111);
                        string  plate = Vehicles.Vehicle.RandomPlate();
                        API.setVehicleNumberPlate(car2, plate);
                        API.setEntitySyncedData(car2, "Owner", sender.socialClubName);
                        API.setEntitySyncedData(car2, "OwnerName", sender.getSyncedData("Nom_Prenom"));
                        API.setEntitySyncedData(car2, "Plate", plate.ToString());
                        Items.Items.InventoryHolder ih = new Items.Items.InventoryHolder();
                        ih.Owner = car2.handle;
                        API.setEntityData(car2, "InventoryHolder", ih);
                        API.setEntitySyncedData(car2, "VEHICLE_FUEL", 100);
                        API.setEntitySyncedData(car2, "VEHICLE_FUEL_MAX", 100);
                        API.setEntityData(car2, "weight", 0);
                        API.setEntityData(car2, "weight_max", Vehicles.Vehicle.GetVehicleWeight(model));
                        API.setVehicleLocked(car2, true);
                        API.setEntitySyncedData(car2, "Locked", true);
                        string paint = xelement.Descendants("Vehicle").ElementAt((int)arguments[1]).Attribute("Color").Value;
                        int    color = Convert.ToInt32(paint);
                        API.setVehiclePrimaryColor(car2, color);
                        InsertVehicle(sender, model, plate, new Vector3(cx, cy, cz), color);
                        UpdatePlayerMoney(sender);
                        API.setVehicleEngineStatus(car2, false);
                        API.triggerClientEvent(sender, "display_subtitle", "Vendu! Voici les clefs de votre véhicule.", 3000);
                    }
                    else
                    {
                        API.triggerClientEvent(sender, "display_subtitle", "Désolé, vous n'avez pas assez d'argent sur vous!", 3000);
                    }
                }
            }
        }