getPlayerFromName | Multi Theft Auto: Wiki Skip to content

getPlayerFromName

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


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

Syntax

getPlayerFromName ( )

Code Examples

server

This example finds aplayeras 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