GetPlayerFromNick: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Changed "DeprecatedWithAlt" template to "Deprecated" for the last time) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | |||
{{Deprecated|getPlayerFromName|}} | |||
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 16: | Line 19: | ||
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'. | 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'. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function locatePlayer( | function locatePlayer( sourcePlayer, command, who ) | ||
local | local targetPlayer = getPlayerFromNick ( who ) -- find the player that was specified in the command | ||
if ( | if ( targetPlayer ) then -- if a player was found | ||
local x,y,z = getElementPosition( | local x,y,z = getElementPosition ( sourcePlayer ) -- save the position of the player who entered the command | ||
local xp,yp,zp = getElementPosition( | local xp,yp,zp = getElementPosition ( targetPlayer ) -- save the position of the player who should be located | ||
local dir = nil | local dir = nil | ||
if (yp > y) then | if (yp > y) then | ||
Line 28: | Line 31: | ||
end | end | ||
if (xp > x) then | if (xp > x) then | ||
dir = dir.."E" | dir = dir .. "E" | ||
else | else | ||
dir = dir.."W" | dir = dir .. "W" | ||
end | end | ||
local distance = math.ceil(getDistanceBetweenPoints3D(x,y,z,xp,yp,zp)) | local distance = math.ceil ( getDistanceBetweenPoints3D(x, y, z, xp, yp, zp) ) | ||
outputChatBox(who.." found "..dir.." ("..distance..")", | outputChatBox( who .. " found " .. dir .. " (" .. distance .. ")", sourcePlayer) -- output the message | ||
end | end | ||
end | end | ||
addCommandHandler("locate",locatePlayer) | addCommandHandler ( "locate", locatePlayer ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Player functions}} | {{Player functions}} |
Latest revision as of 16:45, 13 February 2015
This function is deprecated. This means that its use is discouraged and that it might not exist in future versions. | |
Please use getPlayerFromName instead. |
This function returns a player element for the player with the name passed to the function.
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 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 = getPlayerFromNick ( 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
- getPlayerTeam
- getPlayerBlurLevel
- setPlayerBlurLevel
- getPlayerSerial
- forcePlayerMap
- getPlayerScriptDebugLevel
- getPlayerFromName
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerMapForced
- isPlayerNametagShowing
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney
- countPlayersInTeam
- getPlayersInTeam
- isVoiceEnabled
- setControlState
- getControlState