as belidos already linked the example script can be found in the post, basically the function works in the same way as the normal functions from global.lua, you can copy the function into your global.lua file (note it will get removed each time the file is updated or verified) or you can simply paste it to the bottom of any script that needs it (only need to do it once per map)
function facing_init_name(e,name)
weapon_name[e] = name
end
function facing_main(e)
if PlayerLooking(e,600,5) == 1 then
PromptLocal(e,"player looking at "..weapon_name[e])
end
end
function facing_exit(e)
end
function PlayerLooking(e,dis,v)
if g_Entity[e] ~= nil then
if dis == nil then
dis = 3000
end
if v == nil then
v = 0.5
end
if GetPlayerDistance(e) <= dis then
local destx = g_Entity[e]['x'] - g_PlayerPosX
local destz = g_Entity[e]['z'] - g_PlayerPosZ
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_PlayerAngY < 0 or g_PlayerAngY > 360 do
if g_PlayerAngY <= 0 then
g_PlayerAngY = 360 + g_PlayerAngY
elseif g_PlayerAngY > 360 then
g_PlayerAngY = g_PlayerAngY - 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_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then
return 1
elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then
return 1
else
return 0
end
else
return 0
end
end
end
now your request requires more than my basic function can give but if you added x and z angles it should work ok.
*note, this is without*
local y1 = 15
local y2 = 85
local x1 = 40
local x2 = 60
local min_dist = 100
local max_dist = 1500
local angle = 10
local distd = max_dist - min_dist
local yd = y2-y1
local xd = x2-x1
local x1t = 0
local x2t = 0
local y1t = 0
local y2t = 0
local nearest = max_dist
local target = nil
local ymod = distd / yd
local xmod = distd / xd
local anglemod = distd / angle
function player_target_init(e)
end
function player_target_main(e)
x1t = x1
x2t = x2
y1t = y1
y2t = y2
for a = 2, 3999 do
if g_Entity[a] ~= nil and a ~= g_PlayerObjNo then
if ai_soldier_state[a] ~= nil then
if PlayerLooking(a,nearest,angle) == 1 then
if GetPlayerDistance(a) < nearest then
nearest = GetPlayerDistance(a)
target = a
end
for x = min_dist, GetPlayerDistance(a), xmod do
if x1t < 48 then
x1t = x1t + 1
end
if x2t > 51 then
x2t = x2t - 1
end
end
for y = min_dist,GetPlayerDistance(a), ymod do
if y1t < 45 then
y1t = y1t + 1
end
if y2t > 55 then
y2t = y2t - 1
end
end
Panel(x1t,y1t,x2t,y2t)
TextCenterOnX(50,47,3,g_Entity[a]['health'])
end
end
end
end
if target ~= nil then
if PlayerLooking(target,nearest,angle) == 0 then
nearest = max_dist
end
end
end --main
function player_target_exit(e)
end
function PlayerLooking(e,dis,v)
if g_Entity[e] ~= nil then
if dis == nil then
dis = 3000
end
if v == nil then
v = 0.5
end
if GetPlayerDistance(e) <= dis then
local destx = g_Entity[e]['x'] - g_PlayerPosX
local destz = g_Entity[e]['z'] - g_PlayerPosZ
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_PlayerAngY < 0 or g_PlayerAngY > 360 do
if g_PlayerAngY <= 0 then
g_PlayerAngY = 360 + g_PlayerAngY
elseif g_PlayerAngY > 360 then
g_PlayerAngY = g_PlayerAngY - 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_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then
return 1
elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then
return 1
else
return 0
end
else
return 0
end
end
end
life\'s one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11