using fire direction from client when trying to fire

This commit is contained in:
in0finite 2019-07-13 00:25:57 +02:00
parent 7983812074
commit bae6676196
2 changed files with 14 additions and 2 deletions

View file

@ -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;

View file

@ -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)
{
}