mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-23 04:23:04 +00:00
sync weapon fire event
This commit is contained in:
parent
4a495cfd71
commit
e5ef9e03c7
4 changed files with 39 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
|
||||
void OnChangedWeaponByServer(int newSlot);
|
||||
|
||||
void OnWeaponFiredFromServer(Weapon weapon, Vector3 firePos);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue