if scheduler(e, 100) and g_text_lib then
if g_ml_cutscene_complete and g_carl_mode == 0 and
CloserThan(500, g_Entity[e]) then
....
function CloserThan(dist, Ent)
dist = dist or 100
local DX = g_PlayerPosX - Ent.x
local DY = g_PlayerPosY - Ent.y
local DZ = g_PlayerPosZ - Ent.z
return (DX*DX + DY*DY + DZ*DZ) <= (dist * dist)
end
As I said you can get all this sort of stuff from my scripts, you will also find functions to rotate vectors, generate quaternions from Euler angles, generate Euler angles from quaternions, multiply quaternions etc etc
Wherever possible I've optimised all the code to give the best performance.
Been there, done that, got all the T-Shirts!