ped owner syncvar is assigned before spawning weapon

This commit is contained in:
in0finite 2019-07-07 01:50:07 +02:00
parent 99ee94229b
commit 8eaf0c956d
3 changed files with 14 additions and 7 deletions

View file

@ -155,7 +155,7 @@ namespace SanAndreasUnity.Behaviours
}
public static Weapon Create (int modelId)
public static Weapon Create (int modelId, Ped initialPedOwner)
{
NetStatus.ThrowIfNotOnServer();
@ -165,15 +165,20 @@ namespace SanAndreasUnity.Behaviours
if (null == go)
return null;
// assign model id before spawning it
go.GetComponentOrThrow<NetworkedWeapon>().ModelId = modelId;
// assign owner ped
// asign syncvars before spawning it
var networkedWeapon = go.GetComponentOrThrow<NetworkedWeapon>();
networkedWeapon.ModelId = modelId;
networkedWeapon.PedOwner = initialPedOwner;
// spawn game object here
NetManager.Spawn(go);
return CreatePart2(go, def, weaponData);
Weapon weapon = CreatePart2(go, def, weaponData);
if (initialPedOwner != null)
initialPedOwner.WeaponHolder.AddWeapon(weapon);
return weapon;
}
static GameObject CreatePart1(int modelId, out WeaponDef def, out WeaponData weaponData)

View file

@ -363,7 +363,7 @@ namespace SanAndreasUnity.Behaviours {
{
NetStatus.ThrowIfNotOnServer();
this.AddWeapon(Weapon.Create (weaponId));
Weapon.Create (weaponId, m_ped);
}
public Weapon GetWeaponAtSlot (int slotIndex)

View file

@ -21,6 +21,8 @@
- when (un)hiding weapons, you can't disable their game object
- add option to remove current weapon - for testing
- **vehicle is bumping on clients** - disable (or destroy) wheel colliders, and sync them - this should not be done on local player, see below