OnPlayerJoin: Difference between revisions
Jump to navigation
Jump to search
Syytuvanaema (talk | contribs) |
|||
Line 22: | Line 22: | ||
end | end | ||
addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer ) | addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer ) | ||
</syntaxhighlight> | |||
This example sets random color to every player who joins. | |||
<syntaxhighlight lang="lua"> | |||
-- sets colors when player join | |||
function onJoin () | |||
g_Red, g_Green, g_Blue = randInt (50, 255), randInt (50, 255), randInt (50, 255) | |||
end | |||
-- checks if player has sent a message | |||
function onChat ( message, messageType ) | |||
if messageType == 0 then | |||
local root = getRootElement() | |||
outputChatBox ( getClientName ( source ) .. ": #E0D0B0" .. message, getRootElement(), g_Red, g_Green, g_Blue, true ) | |||
cancelEvent() | |||
end | |||
end | |||
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin) | |||
addEventHandler ( "onPlayerChat", getRootElement(), onChat ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Player events}} | {{See also/Server event|Player events}} |
Revision as of 20:14, 25 August 2008
This event is triggered when a player joins the server.
Parameters
No parameters.
Source
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 function greetPlayer ( ) -- we store the player's name local joinedPlayerName = getClientName ( source ) local serverName = getServerName( ) -- and send him a greeting outputChatBox ( "Welcome " .. joinedPlayerName .. " to ".. serverName .."!" , source, 255, 255, 255 ) end addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer )
This example sets random color to every player who joins.
-- sets colors when player join function onJoin () g_Red, g_Green, g_Blue = randInt (50, 255), randInt (50, 255), randInt (50, 255) end -- checks if player has sent a message function onChat ( message, messageType ) if messageType == 0 then local root = getRootElement() outputChatBox ( getClientName ( source ) .. ": #E0D0B0" .. message, getRootElement(), g_Red, g_Green, g_Blue, true ) cancelEvent() end end addEventHandler ( "onPlayerJoin", getRootElement(), onJoin) addEventHandler ( "onPlayerChat", getRootElement(), onChat )
See Also
Player events
- onPlayerACInfo
- onPlayerBan
- onPlayerChangeNick
- onPlayerChat
- onPlayerClick
- onPlayerCommand
- onPlayerConnect
- onPlayerContact
- onPlayerDamage
- onPlayerJoin
- onPlayerLogin
- onPlayerLogout
- onPlayerMarkerHit
- onPlayerMarkerLeave
- onPlayerModInfo
- onPlayerMute
- onPlayerNetworkStatus
- onPlayerPickupHit
- onPlayerPickupLeave
- onPlayerPickupUse
- onPlayerPrivateMessage
- onPlayerQuit
- onPlayerScreenShot
- onPlayerSpawn
- onPlayerStealthKill
- onPlayerTarget
- onPlayerUnmute
- onPlayerVehicleEnter
- onPlayerVehicleExit
- onPlayerVoiceStart
- onPlayerVoiceStop
- onPlayerWasted
- onPlayerWeaponFire
- onPlayerWeaponSwitch
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled