OnPlayerQuit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(21 intermediate revisions by 13 users not shown)
Line 1: Line 1:
[[Category:Incomplete Event]]
__NOTOC__
{{Server event}}
This event is triggered when a player disconnects from the server.


__NOTOC__
==Parameters==
This event is triggered when a player leaves the game, for whatever reason.
 
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void [[onPlayerQuit]] ( string reason
string quitType, string reason, element responsibleElement
</syntaxhighlight>  
</syntaxhighlight>  


==Example==  
*'''quitType''': How the player left. Possible values:
This example does...
**''"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 [[event system#Event source|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.
 
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
outputDebugString ( "Kills blip when player exits" ) --Outputs to debug console
-- we register quitPlayer as a handler for the event
function onPlayerQuit () --When the player quits
function quitPlayer ( quitType )
destroyBlipsAttachedTo ( source ) --Destorys the blips
-- send the message to the server telling players that the player has left.
removePlayerFromTeam ( source ) --Also removes player from the previously selected team
outputChatBox ( getPlayerName(source).. " has left the server (" .. quitType .. ")" )
end
end
addEventHandler ( "onPlayerQuit", root, quitPlayer )
</syntaxhighlight>


addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) --The event
{{See also/Server event|Player events}}
</syntaxhighlight>

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