RedirectPlayer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 10: Line 10:
===Required Arguments===
===Required Arguments===
*'''thePlayer:''' The player you want to redirect
*'''thePlayer:''' The player you want to redirect
*'''serverIP:''' The IP address (or domain name that resolves to the IP address) of the server you want to redirect the player to
*'''serverIP:''' The IP address (or domain name that resolves to the IP address) of the server you want to redirect the player to. Use an empty string to reconnect to the same server.
*'''serverPort:''' The game port of the server you want to redirect the player to, this is usually 22003
*'''serverPort:''' The game port of the server you want to redirect the player to, this is usually 22003


Line 41: Line 41:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function rejoinMe(thePlayer, theCommand)
function rejoinMe(thePlayer, theCommand)
     redirectPlayer(thePlayer) -- This only works in 1.1.1-9.03429 and onwards
     redirectPlayer(thePlayer,"",0)
end
end
addCommandHandler("rejoin", rejoinMe) -- Attach rejoin command to our function
addCommandHandler("rejoin", rejoinMe) -- Attach rejoin command to our function

Revision as of 19:26, 23 November 2013

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 address (or domain name that resolves to the IP address) of the server you want to redirect the player to. Use an empty string to reconnect to the same server.
  • serverPort: The game port of the server you want to redirect the player to, this is usually 22003

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) 

This example adds a "rejoin" command like the inbuilt reconnect command.

function rejoinMe(thePlayer, theCommand)
    redirectPlayer(thePlayer,"",0)
end
addCommandHandler("rejoin", rejoinMe) -- Attach rejoin command to our function

See Also