- Documentation
- Server events
- onPlayerConnect
Event
onPlayerConnect
A player is connecting to the server, before their element is created. You can reject the connection, e.g. because of the nick or a ban.
Handler
addEventHandler("onPlayerConnect", root, function(playerNick, playerIP, playerUsername, playerSerial, playerVersionNumber, playerVersionString) ... end)Parameters
playerNickstring- Nick.
playerIPstring- IP address.
playerUsernamestring- Launcher account name.
playerSerialstring- Player serial.
playerVersionNumberint- Client version number.
playerVersionStringstring- Client version as text.
Source
source is root.
cancelEvent(true, "reason") rejects the connection; the player sees the reason.
Example
No nicks with a slash.
addEventHandler("onPlayerConnect", root, function(nick)
if nick:find("/", 1, true) then
cancelEvent(true, "Nick nie może mieć ukośnika.")
end
end)
See also
onPlayerJoinA player joined the server. A good place for a greeting, login and the first spawn.getCancelReasonReturns the reason given incancelEvent(true, reason)by the last event cancellation, e.g. the reason for rejecting a connection inonPlayerConnect.cancelEventCancels the current event from inside its handler. For events that allow it, it blocks the default action, e.g.onPlayerChat(the message will not appear in chat),onPickupHit(the pickup will not be collected),onVehicleStartEnter(the player will not get in). Other handlers still run and can check the state withwasEventCancelled. On the server you can give a reason, readable withgetCancelReason.