OnPlayerQuit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
(13 intermediate revisions by 7 users not shown)
Line 5: Line 5:
==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string reason
string quitType, string reason, element responsibleElement
</syntaxhighlight>  
</syntaxhighlight>  


*'''reason''': A string containing the reason why the player left.
*'''quitType''': How the player left. Possible values:
Quit reason string can be:
**''"Unknown"''
- "Unknown"
**''"Quit"''
- "Quit"
**''"Kicked"''
- "Kicked"
**''"Banned"''
- "Banned"
**''"Bad Connection"''
- "Bad Connection"
**''"Timed out"''
- "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==
==Source==
Line 21: Line 23:


==Example==
==Example==
This example gets the quitting client's name and outputs that he is gone
This example gets a quitting player's name and outputs that they left the server.


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


==See Also==
{{See also/Server event|Player events}}
{{Event_functions}}
[[Category:Incomplete]]

Revision as of 03:02, 27 September 2018

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

Parameters

string quitType, string reason, element responsibleElement
  • quitType: How the player left. Possible values:
    • "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 a quitting player's name and outputs that they left the server.

-- we register quitPlayer as a handler for the event
function quitPlayer ( quitType )
	-- send the message to the server telling players that the player has left.
	outputChatBox ( getPlayerName(source).. " has left the server (" .. quitType .. ")" )
end
addEventHandler ( "onPlayerQuit", root, quitPlayer )

See Also

Player events


Event functions