OnPlayerQuit: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 25: | Line 25: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- we register quitPlayer as a handler for the event | -- we register quitPlayer as a handler for the event | ||
function quitPlayer ( ) | function quitPlayer ( reason ) | ||
-- we store the player's name | -- we store the player's name | ||
local quittingPlayerName = getClientName ( source ) | local quittingPlayerName = getClientName ( source ) | ||
-- and send the message to the server | -- and send the message to the server | ||
outputChatBox ( quittingPlayerName .. " has left the server" ) | outputChatBox ( quittingPlayerName .. " has left the server (" .. reason .. ")" ) | ||
end | end | ||
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) | addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) |
Revision as of 16:57, 5 January 2008
This event is triggered when a player disconnects from the server.
Parameters
string reason
- reason: A string containing the reason why the player left.
Quit reason string can be: - "Unknown" - "Quit" - "Kicked" - "Banned" - "Bad Connection" - "Timed out"
Source
The source of this event is the player that left the server.
Example
This example gets the quitting client's name and outputs that he is gone
-- we register quitPlayer as a handler for the event function quitPlayer ( reason ) -- we store the player's name local quittingPlayerName = getClientName ( source ) -- and send the message to the server outputChatBox ( quittingPlayerName .. " has left the server (" .. reason .. ")" ) end addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer )