OnPlayerJoin: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
This event is triggered when a player joins the server.


This event is triggered when someone joins the server.
==Parameters==
The '''source''' of this event is the player who joined.


==Example==
==Example==
This example gets the joining client's name and outputs a welcome message including his name once he joins.
This example gets the joined client's name and sends him a welcome message including his name.


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
 
-- we register greetPlayer as a handler for the event
addEventHandler ( "onPlayerJoin", root, "onPlayerJoin" )
addEventHandler ( "onPlayerJoin", getRootElement(), "greetPlayer" )
function onPlayerJoin ( )
function greetPlayer ( )
joinplayer = getClientName ( source )
-- we store the player's name
outputChatBox ( "Welcome " ..joinplayer.. " to the Server!" , source, 255, 255, 255 )
local joinedPlayerName = getClientName ( source )
-- and send him a greeting
outputChatBox ( "Welcome " ..joinedPlayerName.. " to the server!" , source, 255, 255, 255 )
end
end
</syntaxhighlight>


</syntaxhighlight>
==See also==
{{Event functions}}

Revision as of 18:05, 22 April 2007

This event is triggered when a player joins the server.

Parameters

The source of this event is the player who joined.

Example

This example gets the joined client's name and sends him a welcome message including his name.

-- we register greetPlayer as a handler for the event
addEventHandler ( "onPlayerJoin", getRootElement(), "greetPlayer" )
function greetPlayer ( )
	-- we store the player's name
	local joinedPlayerName = getClientName ( source )
	-- and send him a greeting
	outputChatBox ( "Welcome " ..joinedPlayerName.. " to the server!" , source, 255, 255, 255 )
end

See also