GetPlayerFromName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with '{{Server client function}} __NOTOC__ {{Deprecated}} This function returns a player element for the player with the name passed to the function. ==Syntax== <syntaxhighlight lang="lua"> …')
 
(oop syntax)
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Server client function}}
{{Server client function}}
__NOTOC__
__NOTOC__
{{Deprecated}}
This function returns a [[player]] [[element]] for the player with the name passed to the function.
This function returns a [[player]] [[element]] for the player with the name passed to the function.


Line 8: Line 7:
player getPlayerFromName ( string playerName )
player getPlayerFromName ( string playerName )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||[[Player]]||}}
===Required Arguments===
===Required Arguments===
* '''playerName''': 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
Line 43: Line 42:
==See Also==
==See Also==
{{Player functions}}
{{Player functions}}
[[ru:getPlayerFromName]]

Latest revision as of 23:06, 28 December 2014

This function returns a player element for the player with the name passed to the function.

Syntax

player getPlayerFromName ( string playerName )

OOP Syntax Help! I don't understand this!

Method: Player(...)


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 as specified in the command and outputs the direction and distance he is from the player who entered the command. For example: 'locate someguy'.

function locatePlayer( sourcePlayer, command, who )
	local targetPlayer = getPlayerFromName ( who )                -- find the player that was specified in the command
	if ( targetPlayer ) then                                      -- if a player was found
		local x,y,z = getElementPosition ( sourcePlayer )     -- save the position of the player who entered the command
		local xp,yp,zp = getElementPosition ( targetPlayer )  -- save the position of the player who should be located
		local dir = nil
		if (yp > y) then
			dir = "N"
		else
			dir = "S"
		end
		if (xp > x) then
			dir = dir .. "E"
		else
			dir = dir .. "W"
		end
		local distance = math.ceil ( getDistanceBetweenPoints3D(x, y, z, xp, yp, zp) )
		outputChatBox( who .. " found " .. dir .. " (" .. distance .. ")", sourcePlayer) -- output the message
	end
end
addCommandHandler ( "locate", locatePlayer )

See Also