diff --git a/EXILED/Exiled.API/Features/Ragdoll.cs b/EXILED/Exiled.API/Features/Ragdoll.cs
index 8cde5d8cb2..bbc781ee4e 100644
--- a/EXILED/Exiled.API/Features/Ragdoll.cs
+++ b/EXILED/Exiled.API/Features/Ragdoll.cs
@@ -205,6 +205,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.
///
@@ -223,11 +228,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();
}
}
@@ -239,11 +250,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();
}
}
@@ -255,11 +272,17 @@ public Vector3 Scale
get => Base.transform.localScale;
set
{
- NetworkServer.UnSpawn(GameObject);
+ if (!IsSpawned)
+ {
+ Base.transform.localScale = value;
+ return;
+ }
+
+ UnSpawn();
Base.transform.localScale = value;
- NetworkServer.Spawn(GameObject);
+ Spawn();
}
}
@@ -397,19 +420,65 @@ 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()
+ {
+ if (!IsSpawned)
+ {
+ NetworkServer.Spawn(GameObject);
+ }
+ }
+
+ ///
+ /// Spawns the ragdoll on the network with a specified owner.
+ ///
+ /// The owner of the ragdoll.
+ public void Spawn(GameObject ownerPlayer)
+ {
+ if (!IsSpawned)
+ {
+ NetworkServer.Spawn(GameObject, ownerPlayer);
+ }
+ }
+
+ ///
+ /// Spawns the ragdoll on the network with a specified network connection or asset ID.
///
- public void Spawn() => NetworkServer.Spawn(GameObject);
+ /// The network connection of the owner.
+ /// The optional asset ID of the ragdoll.
+ public void Spawn(NetworkConnection ownerConnection, uint? assetId = null)
+ {
+ if (!IsSpawned)
+ {
+ if (assetId.HasValue)
+ NetworkServer.Spawn(GameObject, assetId.Value, ownerConnection);
+ else
+ NetworkServer.Spawn(GameObject, ownerConnection);
+ }
+ }
///
/// Un-spawns the ragdoll.
///
- public void UnSpawn() => NetworkServer.UnSpawn(GameObject);
+ public void UnSpawn()
+ {
+ if (IsSpawned)
+ {
+ NetworkServer.UnSpawn(GameObject);
+ }
+ }
///
/// Returns the Ragdoll in a human-readable format.