Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 56 additions & 8 deletions EXILED/Exiled.API/Features/Ragdoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,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 @@ -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();
}
}

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

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

Expand Down Expand Up @@ -406,15 +429,40 @@ 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() => 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) => NetworkServer.Spawn(GameObject, ownerPlayer);

/// <summary>
/// Spawns the ragdoll on the network with a specified network connection or asset ID.
/// </summary>
/// <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 (assetId.HasValue)
NetworkServer.Spawn(GameObject, assetId.Value, ownerConnection);
else
NetworkServer.Spawn(GameObject, ownerConnection);
}

/// <summary>
/// Un-spawns the ragdoll.
/// </summary>
Expand Down