OnPlayerQuit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 4: Line 4:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void [[onPlayerQuit]] ( string reason )   
void onPlayerQuit ( string reason )   
</syntaxhighlight>  
</syntaxhighlight>  


==Example==  
==Example==  
This example does...
This example destroys the blips attached to a player and removes him from his team when he quits.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
outputDebugString ( "Kills blip when player exits" ) --Outputs to debug console
function onPlayerQuit ()                   -- When the player quits
function onPlayerQuit () --When the player quits
destroyBlipsAttachedTo ( source )   -- Destroy his blips
destroyBlipsAttachedTo ( source ) --Destorys the blips
removePlayerFromTeam ( source )     -- And remove him from the team he was in
removePlayerFromTeam ( source ) --Also removes player from the previously selected team
end
end


addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) --The event
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) -- Tell MTA to call above function when the event occurs
</syntaxhighlight>
</syntaxhighlight>

Revision as of 16:12, 14 September 2007

This event is triggered when a player leaves the game, for whatever reason.

Syntax

void onPlayerQuit ( string reason )   

Example

This example destroys the blips attached to a player and removes him from his team when he quits.

function onPlayerQuit ()                    -- When the player quits
	destroyBlipsAttachedTo ( source )   -- Destroy his blips
	removePlayerFromTeam ( source )     -- And remove him from the team he was in
end

addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) -- Tell MTA to call above function when the event occurs