sync weapon fire event

This commit is contained in:
in0finite 2019-07-08 16:17:55 +02:00
parent 4a495cfd71
commit e5ef9e03c7
4 changed files with 39 additions and 0 deletions

View file

@ -448,6 +448,9 @@ namespace SanAndreasUnity.Behaviours.Peds.States
// play firing sound
F.RunExceptionSafe (() => weapon.PlayFireSound() );
// notify clients
Net.PedSync.OnWeaponFired(m_ped, weapon, weapon.GetFirePos());
return true;
}

View file

@ -285,6 +285,16 @@ namespace SanAndreasUnity.Behaviours.Peds.States
m_ped.WeaponHolder.SwitchWeapon(newSlot);
}
public virtual void OnWeaponFiredFromServer(Weapon weapon, Vector3 firePos)
{
// update gun flash
if (weapon.GunFlash != null)
weapon.GunFlash.gameObject.SetActive (true);
weapon.UpdateGunFlashRotation ();
weapon.PlayFireSound();
}
}
}

View file

@ -29,6 +29,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
void OnChangedWeaponByServer(int newSlot);
void OnWeaponFiredFromServer(Weapon weapon, Vector3 firePos);
}
}

View file

@ -137,5 +137,29 @@ namespace SanAndreasUnity.Net
}
public static void OnWeaponFired(Ped ped, Weapon weapon, Vector3 firePos)
{
foreach (var p in Player.AllPlayersEnumerable)
p.GetComponent<PedSync>().TargetOnWeaponFired(p.connectionToClient, ped.gameObject, weapon.gameObject, firePos);
}
[TargetRpc]
void TargetOnWeaponFired(NetworkConnection conn, GameObject pedGo, GameObject weaponGo, Vector3 firePos)
{
if (NetStatus.IsServer)
return;
if (null == weaponGo || null == pedGo)
return;
F.RunExceptionSafe( () => {
var ped = pedGo.GetComponent<Ped>();
var weapon = weaponGo.GetComponent<Weapon>();
if (ped.CurrentState != null)
ped.CurrentState.OnWeaponFiredFromServer(weapon, firePos);
});
}
}
}