/// <summary> /// Applies weapon set to player /// </summary> /// <param name="set">Weapon set</param> public static void ApplyWeaponSet(WeaponSet set) { foreach (SavedWeaponItem item in set.Weapons) { Function.Call(Hash.GIVE_WEAPON_TO_PED, Game.Player.Character.Handle, item.Hash, 1000, 0, 0); Function.Call(Hash.SET_PED_AMMO, Game.Player.Character.Handle, item.Hash, item.AmmoInWeapon); Function.Call(Hash.SET_AMMO_IN_CLIP, Game.Player.Character.Handle, item.Hash, item.AmmoInClip); if (item.HasTint) { Function.Call(Hash.SET_PED_WEAPON_TINT_INDEX, Game.Player.Character.Handle, item.Hash, item.Tint); } if (item.HasAttachment != null) { for (int i = 0; i < item.HasAttachment.Length; i++) { bool has = item.HasAttachment[i]; int hash = Function.Call<int>(Hash.GET_HASH_KEY, item.Data.GetAttachmentData(i).InternalValue); if (has) { Function.Call(Hash.GIVE_WEAPON_COMPONENT_TO_PED, Game.Player.Character.Handle, item.Hash, hash); } else { Function.Call(Hash.REMOVE_WEAPON_COMPONENT_FROM_PED, Game.Player.Character.Handle, item.Hash, hash); } } } } if (set.HasParachute) { Function.Call(Hash.GIVE_DELAYED_WEAPON_TO_PED, Game.Player.Character.Handle, WeaponStorage.PARACHUTE_HASH, 1, 0); } Function.Call(Hash.SET_PED_ARMOUR, Game.Player.Character.Handle, set.Armor); }
/// <summary> /// Gets the current player's weapon set /// </summary> /// <returns></returns> public static unsafe WeaponSet GetCurrentWeaponSet() { WeaponSet weaponSet = new WeaponSet(); List<SavedWeaponItem> items = new List<SavedWeaponItem>(WeaponStorage.TOTAL_WEAPONS_SLOTS); for (int i = 0; i < WeaponStorage.WEAPON_CATEGORY_COUNT; i++) { for (int j = 0; j < WeaponStorage.WEAPONS[i].Length; j++) { WeaponData weapon = WeaponStorage.WEAPONS[i][j]; int weaponHash = Function.Call<int>(Hash.GET_HASH_KEY, weapon.InternalValue); if (Function.Call<bool>(Hash.HAS_PED_GOT_WEAPON, Game.Player.Character.Handle, weaponHash, 0)) { SavedWeaponItem item = new SavedWeaponItem(); item.Data = weapon; item.Hash = weaponHash; item.AmmoInWeapon = Function.Call<int>(Hash.GET_AMMO_IN_PED_WEAPON, Game.Player.Character.Handle, weaponHash); int ammoInClip = 0; Function.Call(Hash.GET_AMMO_IN_CLIP, Game.Player.Character.Handle, weaponHash, &ammoInClip); item.AmmoInClip = ammoInClip; if (weapon.HasTint) { item.HasTint = true; item.Tint = Function.Call<int>(Hash.GET_PED_WEAPON_TINT_INDEX, Game.Player.Character.Handle, weaponHash); } if (weapon.AttachmentCount > 0) { item.HasAttachment = new bool[weapon.AttachmentCount]; for (int k = 0; k < weapon.AttachmentCount; k++) { WeaponAttachmentData attachment = weapon.GetAttachmentData(k); int attachmentHash = Function.Call<int>(Hash.GET_HASH_KEY, attachment.InternalValue); item.HasAttachment[k] = Function.Call<bool>(Hash.HAS_PED_GOT_WEAPON_COMPONENT, Game.Player.Character.Handle, weaponHash, attachmentHash); } } items.Add(item); } } } weaponSet.Weapons = items.ToArray(); weaponSet.HasParachute = Function.Call<bool>(Hash.HAS_PED_GOT_WEAPON, Game.Player.Character.Handle, WeaponStorage.PARACHUTE_HASH, 0); weaponSet.Armor = Function.Call<int>(Hash.GET_PED_ARMOUR, Game.Player.Character.Handle); return weaponSet; }