GetPlayerFromNick: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:


==Syntax==
==Syntax==
[[player]] [[getPlayerFromNick]] ( string name )
<syntaxhighlight lang="lua">
player getPlayerFromNick ( string playerName )
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
* '''name''': A string containing the name of the player you want to reference
* '''playerName''': A string containing the name of the player you want to reference
 
===Returns===
Returns a [[player]] [[element]] for the player with the nickname provided. If there is no player with that name, ''false'' is returned.


==Example==
==Example==
player = [[getPlayerFromNick]] ( "Vandalite" )
This example finds a [[player]] called ''Someguy'', and if he is found, he is killed and a message is displayed.
if ( [[killPlayer]] ( player ) ) then
<syntaxhighlight lang="lua">
  [[ serverChat ]] ( "Vandalite was found, and eliminated" )
-- Find the player with the nickname 'Someguy'
end
player = getPlayerFromNick ( "Someguy" )
-- If a player was returned (false is returned if the player isn't found)
if ( player ~= false )
-- If the player was killed succesfully then
if ( killPlayer ( player ) ) then
-- Say so in the chat
serverChat ( "Someguy was found, and eliminated" )
end
end
</syntaxhighlight>

Revision as of 00:47, 18 May 2006

Description

This function returns a player object from a name.

Syntax

player getPlayerFromNick ( string playerName )

Required Arguments

  • playerName: A string containing the name of the player you want to reference

Returns

Returns a player element for the player with the nickname provided. If there is no player with that name, false is returned.

Example

This example finds a player called Someguy, and if he is found, he is killed and a message is displayed.

-- Find the player with the nickname 'Someguy'
player = getPlayerFromNick ( "Someguy" )
-- If a player was returned (false is returned if the player isn't found)
if ( player ~= false )
	-- If the player was killed succesfully then
	if ( killPlayer ( player ) ) then
		-- Say so in the chat
		serverChat ( "Someguy was found, and eliminated" )
	end
end