function EntityLookingAtPlayer(e,dis,v)
if g_Entity[e] ~= nil then
if dis == nil then
dis = 3000
end
if v == nil then
v = 0.5
end
local destx = g_PlayerPosX - g_Entity[e]['x']
local destz = g_PlayerPosZ - g_Entity[e]['z']
if math.sqrt((destx*destx)+(destz*destz)) <= dis then
local angle = math.atan2(destx,destz)
angle = angle * (180.0 / math.pi)
if angle <= 0 then
angle = 360 + angle
elseif angle > 360 then
angle = angle - 360
end
while g_Entity[e]['angley'] < 0 or g_Entity[e]['angley'] > 360 do
if g_Entity[e]['angley'] <= 0 then
g_Entity[e]['angley'] = 360 + g_Entity[e]['angley']
elseif g_Entity[e]['angley'] > 360 then
g_Entity[e]['angley'] = g_Entity[e]['angley'] - 360
end
end
local L = angle - v
local R = angle + v
if L <= 0 then
L = 360 + L
elseif L > 360 then
L = L - 360
end
if R <= 0 then
R = 360 + R
elseif R > 360 then
R = R - 360
end
if (L < R and math.abs(g_Entity[e]['angley']) > L and math.abs(g_Entity[e]['angley']) < R) then
return 1
elseif (L > R and (math.abs(g_Entity[e]['angley']) > L or math.abs(g_Entity[e]['angley']) < R)) then
return 1
else
return 0
end
else
return 0
end
end
end
this will return 1 if the entity is looking at the player within the distance and angle set
i.e.
if EntityLookingAtPlayer(e,150,10) == 1 then
Prompt("you are less than 150 away and i can see you")
end
life\'s one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11