OnPlayerQuit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(added kick/ban reason, renamed old reason arg to quitType)
(Added resp. argument, updated list, updated example.)
Line 5: Line 5:
==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string quitType, string reason
string quitType, string reason, element responsibleElement
</syntaxhighlight>  
</syntaxhighlight>  


*'''quitType''': How the player left.
*'''quitType''': How the player left.
This argument can be:
This argument can be:
- "Unknown"
* "Unknown"
- "Quit"
* "Quit"
- "Kicked"
* "Kicked"
- "Banned"
* "Banned"
- "Bad Connection"
* "Bad Connection"
- "Timed out"
* "Timed out"


{{New feature|3|1.0|
*'''reason''': If the player was kicked or banned, the reason given goes here. If the player was '''not''' kicked or banned, this will be false.
*'''reason''': If the player was kicked or banned, the reason given goes here. If the player was '''not''' kicked or banned, this will be false.
*'''responsibleElement''': The element that was responsible for kicking or banning the player. This is commonly another player, but can also be the console element.
}}


==Source==
==Source==
Line 27: Line 32:
<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 ( reason )
function quitPlayer ( quitType )
-- 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 (" .. reason .. ")" )
outputChatBox ( quittingPlayerName .. " has left the server (" .. quitType .. ")" )
end
end
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer )
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer )

Revision as of 04:45, 18 May 2009

This event is triggered when a player disconnects from the server.

Parameters

string quitType, string reason, element responsibleElement
  • quitType: How the player left.

This argument can be:

  • "Unknown"
  • "Quit"
  • "Kicked"
  • "Banned"
  • "Bad Connection"
  • "Timed out"


  • reason: If the player was kicked or banned, the reason given goes here. If the player was not kicked or banned, this will be false.
  • responsibleElement: The element that was responsible for kicking or banning the player. This is commonly another player, but can also be the console element.

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 ( quitType )
	-- we store the player's name
	local quittingPlayerName = getClientName ( source )
	-- and send the message to the server
	outputChatBox ( quittingPlayerName .. " has left the server (" .. quitType .. ")" )
end
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer )

See Also

Player events


Event functions