private async void LoadWeapons() { await LocalSession.UpdateData("Character.Inventory"); if (Client.Get <JobHandler>().OnDutyAsJob(JobType.EMS | JobType.Police)) { return; } var playerInv = new PlayerInventory(LocalSession.GetGlobalData("Character.Inventory", ""), LocalSession); var playerWeapons = playerInv.InventoryItems.FindAll(o => o.itemCode.Contains("WEAPON_")); var playerPed = Game.PlayerPed; playerPed.Weapons.RemoveAll(); playerWeapons.ForEach(o => { var weaponHash = (WeaponHash)Game.GenerateHash(o.itemCode); if (!playerPed.Weapons.HasWeapon(weaponHash)) { if (weaponHash == WeaponHash.PetrolCan) { playerPed.Weapons.Give(weaponHash, 2250, false, false); } else { playerPed.Weapons.Give(weaponHash, 0, false, false); } } }); setAmmoForWeaponType("pistol", playerInv.GetItem("pistolammo")?.itemAmount ?? 0); setAmmoForWeaponType("smg", playerInv.GetItem("smgammo")?.itemAmount ?? 0); setAmmoForWeaponType("rifle", playerInv.GetItem("rifleammo")?.itemAmount ?? 0); setAmmoForWeaponType("shotgun", playerInv.GetItem("shotgunammo")?.itemAmount ?? 0); }
public async void RefreshPlayerSkin() { while (LocalSession == null) { await BaseScript.Delay(0); } if (!string.IsNullOrEmpty(LocalSession.GetGlobalData("Character.SkinData", ""))) { var pedData = JsonConvert.DeserializeObject <PedData>(LocalSession.GetGlobalData("Character.SkinData", "")); CharacterEditorMenu.handleSkinCreate(pedData); } else { //BaseScript.TriggerEvent("Skin.StartCharacterCreation"); } }
private void removeAmmoFromWeapon(string weaponType, int newAmmoCount) { //await LocalSession.UpdateData("Character.Inventory"); var playerInv = new PlayerInventory(LocalSession.GetGlobalData("Character.Inventory", ""), LocalSession); var ammoObject = playerInv.GetItem($"{weaponType}ammo") ?? InventoryItems.GetInvItemData($"{weaponType}ammo"); if (ammoObject == null) { return; } var currentWeaponAmmo = ammoObject.itemAmount; var ammoToLose = currentWeaponAmmo - newAmmoCount; if (ammoToLose <= 0) { return; } Magicallity.Client.Client.Instance.TriggerServerEvent("Inventory.AddInvItem", JsonConvert.SerializeObject(ammoObject), -ammoToLose); }