yep that's my mistake because i edited my original PlayerLooking() function which used GetPlayerDistance(e) so i obviously just substituted my GetDistance() function and forgot that wouldnt work if it's not included in the global, i shall fix it now so the function works on it's own as intended, thanks
i believe this is close to what you want to achieve
local damage = 30 --amount of damage each attack does to the gate
EntObjNogate = 4 -- gate entity's ID to move AI to
--if inside gate direction is to the left of map set x to negative / or positive number for right
--if gate direction is north/top of map set z to positive / or negative if south/bottom
local move_amountx = 0
local move_amountz = 1000
function ai_attack_init(e)
ai_soldier_state[e]="idle"
v=0
end
function ai_attack_main(e)
-- skipping first scan waiting for all entity's to be initialised.
EntObjNo = g_Entity[e]['obj']; -- AI soldier entity number
if v==0 then
v=1
return
end
if ai_soldier_state[e]=="idle" then
SetCharacterToRun(e) --makes the character run to target
ai_start_x[e] = g_Entity[EntObjNogate]['x'] -- gate object's X
ai_start_z[e] = g_Entity[EntObjNogate]['z'] -- gate object's Z
AISetEntityControl(EntObjNo,AI_MANUAL)
CharacterControlArmed(e)
RotateToPoint(e,ai_start_x[e],ai_start_z[e]) --needed to counter the core rotatetoplayer bug
AIEntityGoToPosition(EntObjNo,ai_start_x[e],ai_start_z[e])
if EntityLooking(e,EntObjNogate,180,25) == 1 then -- increase the 150 distance to suit your needs
AIEntityGoToPosition(EntObjNo,g_Entity[e]['x'],g_Entity[e]['z']) --makes character stop running
ai_soldier_state[e]="attack gate"
end
-- entity is at the gate and is in "attack gate" state.
elseif ai_soldier_state[e]=="attack gate" then
CharacterControlLimbo(e) --allows us to control the character animation again
if g_Entity[e]['animating'] == 0 then
SetAnimationFrames(160,189)
PlayAnimation(e)
g_Entity[e]['animating'] = 1
elseif GetAnimationFrame(e) >= 188 and GetAnimationFrame(e) < 190 then
SetEntityHealth(EntObjNogate,g_Entity[EntObjNogate]['health'] - damage)
end
if g_Entity[EntObjNogate]['health'] < 100 then
CollisionOff(EntObjNogate)
if g_Entity[EntObjNogate]['animating'] == 0 then
SetAnimation(0)
PlayAnimation(EntObjNogate)
g_Entity[EntObjNogate]['animating'] = 1
end
ai_start_x[e] = g_Entity[e]['x']+move_amountx
ai_start_z[e] = g_Entity[e]['z']+move_amountz
ai_soldier_state[e] = "run inside"
end
elseif ai_soldier_state[e] == "run inside" then
CharacterControlArmed(e)
RotateToPoint(e,ai_start_x[e],ai_start_z[e]) --needed to counter the core rotatetoplayer bug
AIEntityGoToPosition(EntObjNo,ai_start_x[e],ai_start_z[e])
end
end
function EntityLooking(e,t,dis,v)
if g_Entity[e] ~= nil and g_Entity[t] ~= nil then
if dis == nil then
dis = 3000
end
if v == nil then
v = 0.5
end
local destx = g_Entity[t]['x'] - g_Entity[e]['x']
local destz = g_Entity[t]['z'] - 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
function RotateToPoint(e,x,z)
if g_Entity[e] ~= nil and x > 0 and z > 0 then
local destx = x - g_Entity[e]['x']
local destz = z - g_Entity[e]['z']
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
SetRotation(e,0,angle,0)
return angle
end
end
life\'s one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11