From bae667619665c580acd32814fdf1a27e3dc6ebf0 Mon Sep 17 00:00:00 2001 From: in0finite Date: Sat, 13 Jul 2019 00:25:57 +0200 Subject: [PATCH] using fire direction from client when trying to fire --- Assets/Scripts/Behaviours/Ped/Ped_Networking.cs | 1 + .../Behaviours/Ped/States/BaseAimMovementState.cs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Behaviours/Ped/Ped_Networking.cs b/Assets/Scripts/Behaviours/Ped/Ped_Networking.cs index 96cd8b23..ccb4c182 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped_Networking.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped_Networking.cs @@ -16,6 +16,7 @@ namespace SanAndreasUnity.Behaviours [SyncVar] GameObject m_net_playerOwnerGameObject; internal GameObject NetPlayerOwnerGameObject { set { m_net_playerOwnerGameObject = value; } } + public Player PlayerOwner => Player.GetOwningPlayer(this); [SyncVar(hook=nameof(Net_OnIdChanged))] int m_net_pedId = 0; diff --git a/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs b/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs index bc275472..ca17d5b8 100644 --- a/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs @@ -415,7 +415,15 @@ namespace SanAndreasUnity.Behaviours.Peds.States protected virtual bool TryFire () { if (m_weapon != null) - return this.TryFire(m_weapon.GetFirePos(), m_weapon.GetFireDir()); + { + if (m_isServer) + { + if (m_ped.IsControlledByLocalPlayer || null == m_ped.PlayerOwner) + return this.TryFire(m_weapon.GetFirePos(), m_weapon.GetFireDir()); + else // this ped is owned by remote client + return this.TryFire(m_weapon.GetFirePos(), m_ped.NetFireDir); + } + } return false; } @@ -428,6 +436,9 @@ namespace SanAndreasUnity.Behaviours.Peds.States if (!m_isServer) // for now, do this only on server return false; + if (Net.NetStatus.IsClientOnly && ! ped.IsControlledByLocalPlayer) + return false; + if (null == weapon) return false; @@ -461,7 +472,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States F.RunExceptionSafe( () => weapon.FireProjectile (firePos, fireDir) ); // send fire event to server - if (Net.NetStatus.IsClientOnly) + if (Net.NetStatus.IsClientOnly && ped.IsControlledByLocalPlayer) { }