Radius Limiter

Continuing the discussion from Take Control Of Any NPC:

This is also something I am wondering about, on past scripts I have seen people use radius limiters but i have never figured out how to write one. Does anyone know how?

Hey,

You can use this native

And then compare the result in an if statement.

Withing a loop obviously.

local pedCoods = GetEntityCoords(PlayerPedId())
local coords = vector3(x, y, z)

if Vdist2(pedCoods, coords) < 20 then
-- do stuff
end

Stay the F away from GetPlayedPed(-1) - use PlayerPedId() instead. The former is deprecated and is considerably slower.

1 Like

Okay, thanks for the advice didn’t knew that