diff --git a/EXILED/Exiled.API/Features/Ragdoll.cs b/EXILED/Exiled.API/Features/Ragdoll.cs index 011c092248..51878021cf 100644 --- a/EXILED/Exiled.API/Features/Ragdoll.cs +++ b/EXILED/Exiled.API/Features/Ragdoll.cs @@ -214,6 +214,11 @@ public bool IsConsumed } } + /// + /// Gets a value indicating whether this ragdoll is spawned. + /// + public bool IsSpawned => NetworkServer.spawned.ContainsValue(Base.netIdentity); + /// /// Gets the the ragdoll is located in. /// @@ -232,11 +237,17 @@ public Vector3 Position get => Base.transform.position; set { - NetworkServer.UnSpawn(GameObject); + if (!IsSpawned) + { + Base.transform.position = value; + return; + } + + UnSpawn(); Base.transform.position = value; - NetworkServer.Spawn(GameObject); + Spawn(); } } @@ -248,11 +259,17 @@ public Quaternion Rotation get => Base.transform.rotation; set { - NetworkServer.UnSpawn(GameObject); + if (!IsSpawned) + { + Base.transform.rotation = value; + return; + } + + UnSpawn(); Base.transform.rotation = value; - NetworkServer.Spawn(GameObject); + Spawn(); } } @@ -264,11 +281,17 @@ public Vector3 RagdollScale get => Base.transform.localScale; set { - NetworkServer.UnSpawn(GameObject); + if (!IsSpawned) + { + Base.transform.localScale = value; + return; + } + + UnSpawn(); Base.transform.localScale = value; - NetworkServer.Spawn(GameObject); + Spawn(); } } @@ -406,15 +429,40 @@ public static Ragdoll Get(BasicRagdoll ragdoll) => ragdoll == null ? null : public static IEnumerable Get(IEnumerable players) => players.SelectMany(pl => Ragdoll.List.Where(rd => rd.Owner == pl)); /// - /// Destroys the ragdoll. + /// Destroys the ragdoll immediately. /// public void Destroy() => Object.Destroy(GameObject); /// - /// Spawns the ragdoll. + /// Destroys the ragdoll after a specified delay. + /// + /// The delay in seconds before the ragdoll is destroyed. + public void Destroy(float delay) => Object.Destroy(GameObject, delay); + + /// + /// Spawns the ragdoll on the network. /// public void Spawn() => NetworkServer.Spawn(GameObject); + /// + /// Spawns the ragdoll on the network with a specified owner. + /// + /// The owner of the ragdoll. + public void Spawn(GameObject ownerPlayer) => NetworkServer.Spawn(GameObject, ownerPlayer); + + /// + /// Spawns the ragdoll on the network with a specified network connection or asset ID. + /// + /// The network connection of the owner. + /// The optional asset ID of the ragdoll. + public void Spawn(NetworkConnection ownerConnection, uint? assetId = null) + { + if (assetId.HasValue) + NetworkServer.Spawn(GameObject, assetId.Value, ownerConnection); + else + NetworkServer.Spawn(GameObject, ownerConnection); + } + /// /// Un-spawns the ragdoll. ///