Skip to content

OnPlayerConnect

The handshake is done and the client is loading the level.

The player has a name and an address and no position yet; they are not in the world until OnPlayerSpawn. A returning player’s record is already readable (GetSavedPlayer). Also called for everyone on the server after a reload.

function OnPlayerConnect(pid)
-- ...
end
Parameter Type
pid number the player

nothing

function OnPlayerConnect(pid)
local saved = GetSavedPlayer(pid)
if saved and saved.visits > 1 then
SendClientMessage(pid, COLOUR_SERVER, string.format("Welcome back, %s (visit %d)", GetPlayerName(pid), saved.visits))
else
SendClientMessage(pid, COLOUR_SERVER, "Welcome, " .. GetPlayerName(pid) .. ". /help for the commands.")
end
SendClientMessageToAll(COLOUR_SERVER, GetPlayerName(pid) .. " joined")
end

OnPlayerRequestSpawn · OnPlayerDisconnect · GetSavedPlayer · the Players group of the index