Author Topic: Respawn  (Read 3717 times)

For his purposes though he should use ::SpawnPlayer.

There's many ways to do it and it pretty much doesn't matter which one he uses because they all have quirks.

All classes have an onAdd member function. It's called when an object of that class is added to the world. There's two arguments, %this, which is the class for which a member has been added to the world, and %obj, or the object that has been added to the world. Armor::onAdd is called when an Armor is added to the world, which is gonna be any Players and AIPlayers. With this one, he's gonna wanna check to make sure that isObject(%obj.client) == true so that he doesn't net spawned bots.

GameConnection::SpawnPlayer is called to, well, spawn a player. It deletes the old player and creates a new player. The argument list is short and sweet; just the client to respawn.

GameConnection::CreatePlayer is what GameConnection::SpawnPlayer calls to actually create the player. GameConnection::SpawnPlayer is actually just a safety proxy for this function where it deletes an existing player alive if there is one, and sets %this.hasSpawnedOnce to true. Argument list is the same; just the client.

GameConnection::onSpawn is what's called a callback. The function itself does nothing. It's simply there so that you can put code there that you want to be called when the player respawns. Callbacks are usually considered the 'correct' way to do things like this, but other methods are not invalid.

There's probably at least one more way to detect when a player has (re)spawned. They don't really matter. I would personally parent either GameConnection::onSpawn or GameConnection::SpawnPlayer. It's up to you, as I said earlier the 'correct' way would probably be to parent the callback.