[Release] Simple spawnmanager in C#

csharp
c

#1

Use this class anywhere in your project


#2

Neat, a spawn manager port to C#. Also you can look at the //todo comments in the spawnmanager.lua :o

Maybe something to consider:

  • List of spawn points, pick one randomly (if you don’t specify any coordinates).
  • Configurable if player wanted level gets cleared and the RemoveAllPedWeapons option configurable.
  • Automatic respawning, where you automatically spawn. (also configurable, i.e. useAutoSpawn and autoSpawnDelay)
  • Option to not spawn the player, but still shutdown the loadingscreen. (i.e. for any UI between the loadingscreen and actually spawning).
  • Trigger appropiate events so other scripts can use it x)
  • Use exports for the SpawnPlayer method instead of static :slight_smile:
  • Some export that will allow this: [help] to respawn timer

Enough to work on and make this a truly awesome resource x)


Here, have a more neat FreezePlayer function. Keeping it DRY x)

public static void FreezePlayer(int playerId, bool freeze)
{
    var ped = GetPlayerPed(playerId);

    //True when player was visible and frozen
    var visibility = freeze && IsEntityVisible(ped); 

    SetPlayerControl(playerId, !freeze, 0);
    SetEntityVisible(ped, visibility, false);
    SetEntityCollision(ped, !freeze, true);
    FreezeEntityPosition(ped, freeze);
    SetPlayerInvincible(playerId, freeze);
   
    if (IsPedFatallyInjured(ped))
    {
        ClearPedTasksImmediately(ped);
    }
}