GetNearestPlayer2D: Difference between revisions
From Onset Developer Wiki
No edit summary |
FlyingFork (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{Info|Function|Server|1.0}} | {{Info|Function|Server|1.0}} | ||
{{FuncDescription| | {{FuncDescription|Gets the closest player in the specified range of XY. An important function which replaces the use of looping through all players and then checking if they are the closest.}} | ||
{{FuncSyntax|GetNearestPlayer2D(x, y)}} | {{FuncSyntax|GetNearestPlayer2D(x, y)}} | ||
Line 9: | Line 9: | ||
{{FuncParam|y|The Y axis}} | {{FuncParam|y|The Y axis}} | ||
{{FuncReturnValue| | {{FuncReturnValue|Returns the player identifier or '''false'''}} | ||
== Example == | == Example == | ||
<syntaxhighlight lang="Lua"> | |||
AddCommand("closest", function(player) | |||
local x, y, z = GetPlayerLocation(player) | |||
local target = GetNearestPlayer2D(x, y) | |||
return AddPlayerChat(player, "Closest player is: " .. GetPlayerName(target)) | |||
end) | |||
</syntaxhighlight> | |||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
{{ServerPlayerFunctions}} |
Latest revision as of 14:41, 26 June 2021
Description
Gets the closest player in the specified range of XY. An important function which replaces the use of looping through all players and then checking if they are the closest.
Syntax
GetNearestPlayer2D(x, y)
Parameters
- x
The X axis - y
The Y axis
Return Value
- Returns the player identifier or false
Example
AddCommand("closest", function(player)
local x, y, z = GetPlayerLocation(player)
local target = GetNearestPlayer2D(x, y)
return AddPlayerChat(player, "Closest player is: " .. GetPlayerName(target))
end)
See also
- GetPlayerBySteamId
- SetPlayerRagdoll
- SetPlayerDimension
- GetPlayerDimension
- SetPlayerPropertyValue
- GetPlayerPropertyValue
- IsValidPlayer
- GetPlayerCount
- GetAllPlayers
- GetNearestPlayer2D
- GetPlayersInRange2D
- GetPlayersInRange3D
- GetStreamedPlayersForPlayer
- SetPlayerName
- GetPlayerName
- GetPlayerSteamId
- GetPlayerNetworkStats
- SetPlayerSpawnLocation
- IsPlayerStreamedIn
- SetPlayerVoiceRange
- SetPlayerVoiceChannel
- IsPlayerVoiceChannel
- SetPlayerVoiceEnabled
- IsPlayerVoiceEnabled
- IsPlayerTalking
- AddPlayerChat
- AddPlayerChatRange
- AddPlayerChatAll
- GetPlayerState
- GetPlayerMovementMode
- GetPlayerMovementSpeed
- IsPlayerAiming
- IsPlayerReloading
- GetPlayerVehicle
- GetPlayerVehicleSeat
- SetPlayerInVehicle
- RemovePlayerFromVehicle
- SetPlayerLocation
- GetPlayerLocation
- SetPlayerWeaponStat
- SetPlayerWeapon
- GetPlayerWeapon
- GetPlayerEquippedWeaponSlot
- EquipPlayerWeaponSlot
- GetPlayerEquippedWeapon
- SetPlayerHeading
- GetPlayerHeading
- SetPlayerSpectate
- IsPlayerDead
- SetPlayerHealth
- GetPlayerHealth
- SetPlayerArmor
- GetPlayerArmor
- SetPlayerRespawnTime
- GetPlayerRespawnTime
- GetPlayerIP
- GetPlayerPing
- KickPlayer
- GetPlayerLocale
- GetPlayerGUID
- GetPlayerGameVersion
- SetPlayerAnimation
- AttachPlayerParachute
- SetPlayerHeadSize
- GetPlayerHeadSize