C# Checking if the player was spawned for the first time

Is there any way to add an eventHandler to see if a player was spawned for first time, and if not, do something else?

You could have an event handler for playerSpawned and keep a bool firstSpawn variable somewhere. Then have that set to false as soon as the first event is triggered.
And in the event handler, just check what the current value is.

Example:

// Put this in the constructor of your class:
EventHandlers.Add("playerSpawned", new Action(HandlePlayerSpawned));

// Put this outside of the constructor:
private bool firstSpawn = true;

/// Function that handles the event.
private void HandlePlayerSpawned()
{
    if (firstSpawn)
    {
        firstSpawn = false; // and do some other stuff on first spawn
    }
    else
    {
// do everything that needs to happen when it's not the first spawn.
    }
}
1 Like

Ok this is ok, i will try this method, and i will try to set a flag into database :slight_smile: To keep the first spawning event :slight_smile: Thanks

@Vespura and
I’m especially interested in remembering the next connection if she has ever done the IF action

save it in the database :slight_smile: