RedirectPlayer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Why the hell did you remove the example?)
Line 20: Line 20:


==Example==  
==Example==  
This example redirects the player to another server when they join.
This example adds a "joinserver" command using the syntax, "/joinserver serverIP serverPort [serverPassword]".
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function joinserverHandlerFunction(playerSource)
function joinserverHandlerFunction (playerSource, commandName, serverIP, serverPort, serverPassword)
redirectPlayer (playerSource, "192.168.1.3", 22003, "potatoes") --redirect the player
if serverIP and serverPort then --if IP and Port were specified
if serverPassword then --if also a password was specified
redirectPlayer (playerSource, serverIP, tonumber(serverPort), serverPassword) --redirect the player
else -- else if no password was specified
redirectPlayer (playerSource, serverIP, tonumber(serverPort))  --redirect the player without using the serverPassword parameter
end
else -- if no IP or Port have been specified
outputChatBox ("Error! Correct Syntax: /joinserver IP Port [Password]", playerSource) --output an Error message to the chatbox
end
end
end


addEventHandler("onPlayerJoin",root, joinserverHandlerFunction)  
addCommandHandler ("joinserver", joinserverHandlerFunction)  
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Player_functions}}
{{Player_functions}}

Revision as of 10:57, 5 June 2011

This function redirects the player to a specified server.

Syntax

bool redirectPlayer ( player thePlayer, string serverIP, int serverPort, [ string serverPassword ] )

Required Arguments

  • thePlayer: The player you want to redirect
  • serverIP: The ip of the server you want to redirect the player to
  • serverPort: The game port of the server you want to redirect the player to

Optional Arguments

  • serverPassword: The password for the server if it's protected

Returns

Returns true if the player was redirected successfully, false if bad arguments were passed.

Example

This example adds a "joinserver" command using the syntax, "/joinserver serverIP serverPort [serverPassword]".

function joinserverHandlerFunction (playerSource, commandName, serverIP, serverPort, serverPassword)
	if serverIP and serverPort then --if IP and Port were specified
		if serverPassword then --if also a password was specified
			redirectPlayer (playerSource, serverIP, tonumber(serverPort), serverPassword) --redirect the player
		else -- else if no password was specified
			redirectPlayer (playerSource, serverIP, tonumber(serverPort))  --redirect the player without using the serverPassword parameter
		end
	else -- if no IP or Port have been specified
		outputChatBox ("Error! Correct Syntax: /joinserver IP Port [Password]", playerSource) --output an Error message to the chatbox
	end
end

addCommandHandler ("joinserver", joinserverHandlerFunction) 

See Also