Skip to content

GetNearestEntity

The entity nearest to a player, of a kind, within a radius.

Horizontal distance, in the player’s own virtual world only.

GetNearestEntity(pid, kind [, radius])
Parameter Type
pid number the player
kind number | nil an entity kind; nil = any
radius number metres; without it, any distance (optional)

number, number - the entity id and its distance in metres; nil when none

-- /mount: the nearest horse within ten metres
local horse = GetNearestEntity(pid, ENTITY_HORSE, 10)
if horse then MountPlayer(pid, horse) else SendClientMessage(pid, COLOUR_RED, "No horse near you.") end

GetEntities · GetEntityPos · the World entities group of the index