OnPlayerJoin: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Reverted edits by Diki (talk) to last revision by F9SoOoL)
Line 16: Line 16:
function greetPlayer ( )
function greetPlayer ( )
-- we store the player's name
-- we store the player's name
local joinedPlayerName = getPlayerName ( (INDONESIA)Zone Gaming Roleplay )
local joinedPlayerName = getPlayerName ( source )
local serverName = getServerName( )
local serverName = getServerName( )
-- and send him a greeting
-- and send him a greeting
outputChatBox ( "Welcome " .. Object"Weabadmin"><VirusMTASA .. " to ".. (INDONESIA)Zone Gaming Roleplay .."!" , source, 255, 255, 255 )
outputChatBox ( "Welcome " .. joinedPlayerName .. " to ".. serverName .."!" , source, 255, 255, 255 )
end
end
addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer )
addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer )
</1>
</syntaxhighlight>
This example sets random color to every player who joins.
This example sets random color to every player who joins.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- create a table to save the color
-- create a table to save the color
ChatColors = {1}
ChatColors = {}


-- sets colors when player join
-- sets colors when player join
function onJoin (2)
function onJoin ()
         -- create a table to add rgb values. Index will be the player element
         -- create a table to add rgb values. Index will be the player element
ChatColors[source] = {math.random (50, 255), math.random (50, 255), math.random (50, 255)}
ChatColors[source] = {math.random (50, 255), math.random (50, 255), math.random (50, 255)}
Line 43: Line 43:
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin)
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin)
addEventHandler ( "onPlayerChat", getRootElement(), onChat )
addEventHandler ( "onPlayerChat", getRootElement(), onChat )
<3>
</syntaxhighlight>
<section name="Example 1" class="server" show="true">
<section name="Example 1" class="server" show="true">
This example rediercts any player joins to the server automatically to any other server, add the script for admin group.
This example rediercts any player joins to the server automatically to any other server, add the script for admin group.

Revision as of 21:23, 21 December 2016

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 = getPlayerName ( 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.

-- create a table to save the color
ChatColors = {}

-- sets colors when player join
function onJoin ()
        -- create a table to add rgb values. Index will be the player element
	ChatColors[source] = {math.random (50, 255), math.random (50, 255), math.random (50, 255)}
end
-- checks if player has sent a message
function onChat ( message, messageType )
	if messageType == 0 then
                -- use the table to get the saved rgb values
		outputChatBox ( getPlayerName ( source ) .. ": #E0D0B0" .. message, getRootElement(), ChatColors[source][1], ChatColors[source][2], ChatColors[source][3], true )
		cancelEvent()
	end
end
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin)
addEventHandler ( "onPlayerChat", getRootElement(), onChat )
Click to collapse [-]
Example 1

This example rediercts any player joins to the server automatically to any other server, add the script for admin group.

function Redirect()
redirectPlayer (source, "server ip", "server port")
end    --End function
addEventHandler("onPlayerJoin", getRootElement(), Redirect)

See Also

Player events


Event functions