RustTip

OnPlayerSpawn

OxideCarbonPlayer

Called when a player is spawned.

object OnPlayerSpawn(BasePlayer basePlayer, Network.Connection connection)
Works — the game method in this build is the one the hook was written for.

Parameters

basePlayer
BasePlayer
connection
Network.Connection

Return value

objectReturn non-null to stop the game method.

Example

object — you can affect the game: return a value to change or cancel the action.

private object OnPlayerSpawn(BasePlayer basePlayer, Network.Connection connection)
{
    Puts("OnPlayerSpawn");

    // change nothing — the game continues as usual
    return null;

    // to affect the game:
    // return false; // non-null cancels the game action
}

Works in both Oxide and Carbon: Carbon loads Oxide plugins as is.

Injection point

Rust.opj (Oxide)
void ServerMgr.SpawnNewPlayer(Network.Connection)

Passes: BasePlayer basePlayer, Network.Connection connection

WorksReturnBehavior: ExitWhenNonNullAssembly-CSharp.dll

Where it is called (this branch's game code)

public BasePlayer SpawnNewPlayer(Connection connection)
{
	RelationshipManager.PlayerTeam playerTeam = RelationshipManager.ServerInstance.FindPlayersTeam(connection.userid);
	BasePlayer.SpawnPoint spawnPoint = FindSpawnPoint(null, playerTeam?.teamID ?? 0);
	BasePlayer basePlayer = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab", spawnPoint.pos, spawnPoint.rot).ToPlayer();
	if (Interface.CallHook("OnPlayerSpawn", basePlayer, connection) != null)
	{
		return basePlayer;
	}
	basePlayer.health = 0f;
	basePlayer.lifestate = BaseCombatEntity.LifeState.Dead;
	basePlayer.ResetLifeStateOnSpawn = false;
	basePlayer.limitNetworking = true;
	if (connection == null)
// …

Sources: Rust.opj from OxideMod/Oxide.Rust (MIT) and hook metadata of the Carbon documentation (MIT). Method code is decompiled from this branch's server.