diff --git a/Assets/Scripts/Behaviours/WeaponHolder.cs b/Assets/Scripts/Behaviours/WeaponHolder.cs index e225412b..f0e8151a 100644 --- a/Assets/Scripts/Behaviours/WeaponHolder.cs +++ b/Assets/Scripts/Behaviours/WeaponHolder.cs @@ -369,11 +369,11 @@ namespace SanAndreasUnity.Behaviours { this.SetWeaponAtSlot (weaponDef.Id, slot); } - public void SetWeaponAtSlot (int weaponId, int slotIndex) + public Weapon SetWeaponAtSlot (int weaponId, int slotIndex) { NetStatus.ThrowIfNotOnServer(); - Weapon.Create (weaponId, m_ped); + return Weapon.Create (weaponId, m_ped); } public Weapon GetWeaponAtSlot (int slotIndex) diff --git a/Assets/Scripts/Networking/PlayerRequests.cs b/Assets/Scripts/Networking/PlayerRequests.cs index cee41897..b1fa4a71 100644 --- a/Assets/Scripts/Networking/PlayerRequests.cs +++ b/Assets/Scripts/Networking/PlayerRequests.cs @@ -11,10 +11,12 @@ namespace SanAndreasUnity.Net public class PlayerRequests : NetworkBehaviour { Player m_player; + Ped m_ped => m_player.OwnedPed; public static PlayerRequests Local { get; private set; } float m_timeWhenSpawnedVehicle = 0f; float m_timeWhenChangedPedModel = 0f; + float m_timeWhenMadeWeaponRequest = 0f; @@ -123,6 +125,58 @@ namespace SanAndreasUnity.Net } } + + #region weapons + + public void AddRandomWeapons() => this.CmdAddRandomWeapons(); + + [Command] + void CmdAddRandomWeapons() + { + if (m_ped != null) + F.RunExceptionSafe( () => m_ped.WeaponHolder.AddRandomWeapons() ); + } + + public void RemoveAllWeapons() => this.CmdRemoveAllWeapons(); + + [Command] + void CmdRemoveAllWeapons() + { + if (m_ped != null) + F.RunExceptionSafe( () => m_ped.WeaponHolder.RemoveAllWeapons() ); + } + + public void GiveAmmo() => this.CmdGiveAmmo(); + + [Command] + void CmdGiveAmmo() + { + if (m_ped != null) + { + F.RunExceptionSafe( () => { + foreach (var w in m_ped.WeaponHolder.AllWeapons) + WeaponHolder.AddRandomAmmoAmountToWeapon(w); + } ); + } + } + + public void GiveWeapon(int modelId) => this.CmdGiveWeapon(modelId); + + [Command] + void CmdGiveWeapon(int modelId) + { + if (m_ped != null) + { + F.RunExceptionSafe( () => { + var w = m_ped.WeaponHolder.SetWeaponAtSlot(modelId, 0); + m_ped.WeaponHolder.SwitchWeapon(w.SlotIndex); + WeaponHolder.AddRandomAmmoAmountToWeapon(w); + } ); + } + } + + #endregion + } } diff --git a/Docs/Multiplayer.md b/Docs/Multiplayer.md index 807ed99c..59ca7020 100644 --- a/Docs/Multiplayer.md +++ b/Docs/Multiplayer.md @@ -17,7 +17,7 @@ - port the whole UI to multiplayer -- add option to remove current weapon - for testing +- add option to remove current weapon - for testing ; adapt weapons window ; - create weapon prefab ; add it to spawnable prefabs list ;