Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.
89 changes: 79 additions & 10 deletions EXILED/Exiled.API/Features/Ragdoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ public bool IsConsumed
}
}

/// <summary>
/// Gets a value indicating whether this ragdoll is spawned.
/// </summary>
public bool IsSpawned => NetworkServer.spawned.ContainsValue(Base.netIdentity);

/// <summary>
/// Gets the <see cref="Features.Room"/> the ragdoll is located in.
/// </summary>
Expand All @@ -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();
}
}

Expand All @@ -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();
}
}

Expand All @@ -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();
}
}

Expand Down Expand Up @@ -397,19 +420,65 @@ public static Ragdoll Get(BasicRagdoll ragdoll) => ragdoll == null ? null :
public static IEnumerable<Ragdoll> Get(IEnumerable<Player> players) => players.SelectMany(pl => Ragdoll.List.Where(rd => rd.Owner == pl));

/// <summary>
/// Destroys the ragdoll.
/// Destroys the ragdoll immediately.
/// </summary>
public void Destroy() => Object.Destroy(GameObject);

/// <summary>
/// Spawns the ragdoll.
/// Destroys the ragdoll after a specified delay.
/// </summary>
/// <param name="delay">The delay in seconds before the ragdoll is destroyed.</param>
public void Destroy(float delay) => Object.Destroy(GameObject, delay);

/// <summary>
/// Spawns the ragdoll on the network.
/// </summary>
public void Spawn()
{
if (!IsSpawned)
{
NetworkServer.Spawn(GameObject);
}
}

/// <summary>
/// Spawns the ragdoll on the network with a specified owner.
/// </summary>
/// <param name="ownerPlayer">The owner of the ragdoll.</param>
public void Spawn(GameObject ownerPlayer)
{
if (!IsSpawned)
{
NetworkServer.Spawn(GameObject, ownerPlayer);
}
}

/// <summary>
/// Spawns the ragdoll on the network with a specified network connection or asset ID.
/// </summary>
public void Spawn() => NetworkServer.Spawn(GameObject);
/// <param name="ownerConnection">The network connection of the owner.</param>
/// <param name="assetId">The optional asset ID of the ragdoll.</param>
public void Spawn(NetworkConnection ownerConnection, uint? assetId = null)
{
if (!IsSpawned)
{
if (assetId.HasValue)
NetworkServer.Spawn(GameObject, assetId.Value, ownerConnection);
else
NetworkServer.Spawn(GameObject, ownerConnection);
}
}

/// <summary>
/// Un-spawns the ragdoll.
/// </summary>
public void UnSpawn() => NetworkServer.UnSpawn(GameObject);
public void UnSpawn()
{
if (IsSpawned)
{
NetworkServer.UnSpawn(GameObject);
}
}

/// <summary>
/// Returns the Ragdoll in a human-readable format.
Expand Down
Loading