U = U or require "scriptbank\\utillib" local inspectlist = {} function entitylookingnear_init(e) end function entitylookingnear_main(e) if inspectlist[e] == nil then inspectlist[e] = {} local count = 0 for a = 1, g_EntityElementMax do if GetEntityName(a) == "inspectable" then count = count + 1 inspectlist[e][count] = a end end return end CollisionOff(e) local pxp, pyp, pzp = g_PlayerPosX, g_PlayerPosY, g_PlayerPosZ local pax, pay, paz = g_PlayerAngX, g_PlayerAngY, g_PlayerAngZ SetPosition(e, pxp, pyp + 30, pzp) SetRotation(e, pax, pay, paz) if GetTimer(e) > 15 then StartTimer(e) local islookingnear = 0 for a,b in pairs (inspectlist[e]) do islookingnear = IsEntityLookingNear(e, b, 500) if islookingnear == g_Entity[b]['obj'] then islookingnear = "yes, i have entity : "..b break end end PromptDuration(islookingnear, 500) end end function IsEntityLookingNear( e, t, dist) local function sqrd3( x1, y1, z1, x2, y2, z2 ) local dx, dy, dz = x1 - x2, y1 - y2, z1 - z2 return dx*dx+dy*dy+dz*dz end local rad = math.rad local eObj = g_Entity[e]['obj'] local tObj = g_Entity[t]['obj'] local x1, y1, z1, ax1, ay1, az1 = GetEntityPosAng(e) local x2, y2, z2 = GetEntityPosAng(t) if not U.CloserThan( x1, y1, z1, x2, y2, z2, dist ) then return "to far" end local ox, oy, oz = U.Rotate3D(0, 0, dist*2, rad(ax1), rad(ay1), rad(az1)) local x3, y3, z3 = x1 + ox, y1 + oy, z1 + oz local ray1 = IntersectStatic(x1, y1, z1, x3, y3, z3, eObj) if ray1 == nil then ray1 = 0 end local x4, y4, z4 local dist1 = nil if ray1 > 0 then x4, y4, z4 = GetIntersectCollisionX(), GetIntersectCollisionY(), GetIntersectCollisionZ() dist1 = sqrd3(x1, y1, z1, x4, y4, z4) end local ray2 = IntersectAll(x1, y1, z1, x3, y3, z3, eObj) if ray2 == nil then ray2 = 0 end local dist2 = nil if ray2 > 0 then x4, y4, z4 = GetIntersectCollisionX(), GetIntersectCollisionY(), GetIntersectCollisionZ() dist2 = sqrd3(x1, y1, z1, x4, y4, z4) end local ray3 = RayTerrain(x1, y1, z1, x3, y3, z3) if ray3 == nil then ray3 = 0 end local dist3 = nil if ray3 > 0 then x4, y4, z4 = GetRayCollisionX(), GetRayCollisionY(), GetRayCollisionZ() dist3 = sqrd3(x1, y1, z1, x4, y4, z4) end if dist1 == nil and dist2 == nil and dist3 == nil then return "nothing" end if dist1 == nil then dist1 = math.huge end if dist2 == nil then dist2 = math.huge end if dist3 == nil then dist3 = math.huge end if dist3 < dist1 and dist3 < dist2 then return "terrain" end if dist1 < dist2 then return ray2 else return ray1 end end