Skip to content

Commit

Permalink
feat(server) spawn overloads for usability (#20)
Browse files Browse the repository at this point in the history
* Introduce Spawn overloads for usability

* Call the overload on Sync-Client

* Do not use cast for PedModel

---------

Co-authored-by: ramon.pawlowski <[email protected]>
  • Loading branch information
2 people authored and Doxoh committed Jun 27, 2024
1 parent 44e1e82 commit fffc533
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,24 @@ public void Spawn(Position position, uint delayMs = 0)
Player.Spawn(position, delayMs);
}
}

public void Spawn(uint model, Position position, uint delayMs = 0)
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsNullable(Player)) return;
Player.Spawn(model, position, delayMs);
}
}

public void Spawn(PedModel model, Position position, uint delayMs = 0)
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsNullable(Player)) return;
Player.Spawn(model, position, delayMs);
}
}

public void Despawn()
{
Expand Down
18 changes: 18 additions & 0 deletions api/AltV.Net/Elements/Entities/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ public interface IPlayer : ISharedPlayer, IEntity
/// <exception cref="EntityRemovedException">This entity was removed</exception>
void Spawn(Position position, uint delayMs = 0);

/// <summary>
/// Spawns a player with given model at the designated position with a optional delay in milliseconds
/// </summary>
/// <param name="model">the players model / skin</param>
/// <param name="position">position</param>
/// <param name="delayMs">delay in milliseconds until player is spawned</param>
/// <exception cref="EntityRemovedException">This entity was removed</exception>
void Spawn(uint model, Position position, uint delayMs = 0);

/// <summary>
/// Spawns a player with given model at the designated position with a optional delay in milliseconds
/// </summary>
/// <param name="model">the players model / skin</param>
/// <param name="position">position</param>
/// <param name="delayMs">delay in milliseconds until player is spawned</param>
/// <exception cref="EntityRemovedException">This entity was removed</exception>
void Spawn(PedModel model, Position position, uint delayMs = 0);

/// <summary>
/// Despawns a player
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions api/AltV.Net/Elements/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,26 @@ public void Spawn(Position position, uint delayMs)
Core.Library.Server.Player_Spawn(PlayerNativePointer, position, delayMs);
}
}

public void Spawn(uint model, Position position, uint delayMs = 0)
{
unsafe
{
CheckIfEntityExists();
Core.Library.Server.Player_SetModel(PlayerNativePointer, model);
Core.Library.Server.Player_Spawn(PlayerNativePointer, position, delayMs);
}
}

public void Spawn(PedModel model, Position position, uint delayMs = 0)
{
unsafe
{
CheckIfEntityExists();
Core.Library.Server.Player_SetModel(PlayerNativePointer, (uint) model);
Core.Library.Server.Player_Spawn(PlayerNativePointer, position, delayMs);
}
}

public void Despawn()
{
Expand Down

0 comments on commit fffc533

Please sign in to comment.