Exemplo n.º 1
0
        public void ModdingGetMods(Player sender, params object[] arguments)
        {
            var modsList = new List <string[]>();

            var modType  = ModTypes.First(x => x.Value == (string)arguments[0]).Key;
            var manifest = VehicleInfo.Get(sender.Vehicle);

            foreach (var modid in manifest.ModIds(modType))
            {
                var price = GetModPrice(modType, modid);
                if (price == -1)
                {
                    continue;
                }

                var  m     = manifest.Mod(modType, modid);
                bool isVip = _vipMods.ContainsKey(modType) &&
                             (_vipMods[modType] == -1 || _vipMods[modType] == modid);

                modsList.Add(new string[]
                {
                    m.localizedName == "" ? "No Name" : (m.HasFlag("chrome") ? "CHROME - " + m.localizedName : m.localizedName), modType.ToString(), modid.ToString(), price.ToString(),
                    isVip == true ? "true" : "false"
                });
            }
            NAPI.ClientEvent.TriggerClientEvent(sender, "MODDING_FILL_MODS", NAPI.Util.ToJson(modsList.ToArray()));
        }
Exemplo n.º 2
0
        private void API_onClientEventTrigger(Client sender, string eventName, params object[] arguments)
        {
            switch (eventName)
            {
            case "MODDING_GETMODS":
            {
                var modsList = new List <string[]>();

                var modType  = ModTypes.First(x => x.Value == (string)arguments[0]).Key;
                var manifest = VehicleInfo.Get(sender.vehicle);
                foreach (var modid in manifest.ModIds(modType))
                {
                    var price = GetModPrice(modType, modid);
                    if (price == -1)
                    {
                        continue;
                    }

                    var  m     = manifest.Mod(modType, modid);
                    bool isVip = _vipMods.ContainsKey(modType) &&
                                 (_vipMods[modType] == -1 || _vipMods[modType] == modid);

                    modsList.Add(new string[]
                        {
                            m.localizedName == "" ? "No Name" : (m.HasFlag("chrome") ? "CHROME - " + m.localizedName : m.localizedName), modType.ToString(), modid.ToString(), price.ToString(),
                            isVip == true ? "true" : "false"
                        });
                }
                API.TriggerClientEvent(sender, "MODDING_FILL_MODS", API.ToJson(modsList.ToArray()));
                break;
            }

            case "MODDING_EXITMENU":
            {
                var vehicle = sender.vehicle;
                ClearVehicleMods(vehicle.handle.GetVehicle());
                ApplyVehicleMods(vehicle.handle.GetVehicle());
                API.SetEntityPosition(sender.vehicle, sender.getData("ModLastPos"));
                API.SetEntityDimension(sender.vehicle, 0);
                API.SetEntityDimension(sender, 0);
                if (sender.GetAccount().IsSpeedoOn)
                {
                    API.TriggerClientEvent(sender, "TOGGLE_SPEEDO");
                }
                break;
            }

            case "MODDONG_PURCHASE_ITEMS":
            {
                dynamic items     = JsonConvert.DeserializeObject((string)arguments[0]);
                int     allPrices = 0;
                int     itemCount = 0;
                foreach (var itm in items)
                {
                    var modType = int.Parse(itm[0].ToString().Trim());
                    int modId;
                    int.TryParse(itm[1].ToString().Trim(), out modId);

                    var price = GetModPrice(modType, modId);
                    allPrices += price;
                    itemCount++;
                }
                var prop = PropertyManager.Properties.First(x => x.Id == API.GetEntityData(sender, "MOD_ID"));
                if (prop.Supplies != -1 && prop.Supplies < itemCount * 5)
                {
                    API.TriggerClientEvent(sender, "MODDING_ERROR",
                                           "This modshop doesn't have enough supplies.");
                    return;
                }

                var c = sender.GetCharacter();
                if (Money.GetCharacterMoney(c) < allPrices)
                {
                    API.TriggerClientEvent(sender, "MODDING_ERROR",
                                           "You don't have enough money to purchase these mods. Your balance: " +
                                           Money.GetCharacterMoney(c));
                    return;
                }

                InventoryManager.DeleteInventoryItem <Money>(c, allPrices);
                InventoryManager.GiveInventoryItem(prop, new Money(), allPrices);

                if (prop.Supplies != -1)
                {
                    prop.Supplies -= itemCount * 5;
                }

                var veh = sender.vehicle.handle.GetVehicle();
                foreach (var itm in items)
                {
                    var modType = int.Parse(itm[0].ToString().Trim());
                    AddVehicleMod(veh, modType, itm[1].ToString().Trim());
                }
                ClearVehicleMods(veh);
                ApplyVehicleMods(veh);
                veh.Save();
                API.TriggerClientEvent(sender, "MODDING_CLOSE");
                API.SendChatMessageToPlayer(sender,
                                            "You have successfully purchased some vehicle mods for a total of ~g~" +
                                            allPrices.ToString("C"));
                API.SetEntityPosition(sender.vehicle, sender.getData("ModLastPos"));
                API.SetEntityDimension(sender.vehicle, 0);
                API.SetEntityDimension(sender, 0);
                if (sender.GetAccount().IsSpeedoOn)
                {
                    API.TriggerClientEvent(sender, "TOGGLE_SPEEDO");
                }
                break;
            }
            }
        }