ai_soldier_state = {} ai_old_hp = {} local atk_anim_s = {} local atk_anim_e = {} local last_atk_frame = {} local hit = {} local hit_in_leg = {} local run_speed = {} local temproty = {} local attack_range = 90 local damage_min = 15 local damage_max = 25 local idle_anim_s = {} local idle_anim_e = {} local run_anim_s = {} local run_anim_e = {} local walk_anim_s = {} local walk_anim_e = {} local walk_speed = {} local hurt_anim_s = 740 local hurt_anim_e = 751 atk_anim_s[1] = 304 atk_anim_e[1] = 340 atk_anim_s[2] = 407 atk_anim_e[2] = 459 atk_anim_s[3] = 473 atk_anim_e[3] = 536 ai_soldier_pathindex = {} ai_path_point_direction = {} ai_patrol_x = {} ai_patrol_z = {} ai_path_point_index = {} ai_path_point_max = {} function ai_zombie_custom_init(e) AISetEntityTurnSpeed(AIObjNo,2500) ai_soldier_state[e] = "idle" CharacterControlManual(e) StopAnimation(e) SetCharacterSoundSet(e) hit_in_leg[e] = 0 idle_anim_s[e] = 38 idle_anim_e[e] = 98 run_speed[e] = 120 run_anim_s[e] = 1334 run_anim_e[e] = 1355 walk_anim_s[e] = 1208 walk_anim_e[e] = 1238 walk_speed[e] = 80 ai_soldier_pathindex[e] = -1 end function ai_zombie_custom_main(e) if ai_old_hp[e] == nil then ai_old_hp[e] = g_Entity[e]['health'] end AIObjNo = g_Entity[e]['obj'] PlayerDist = GetPlayerDistance(e) if ai_soldier_state[e] == "idle" then if ai_soldier_pathindex[e] == -1 then ai_soldier_pathindex[e] = -2 PathIndex = -1 PathPointIndex = -1 pClosest = 99999 for pa = 1, AIGetTotalPaths(), 1 do for po = 1 , AIGetPathCountPoints(pa), 1 do pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po) pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po) pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ)) if pDist < pClosest and pDist < 200 then pClosest = pDist PathIndex = pa PathPointIndex = po end end -- po end -- pa if PathIndex > -1 then ai_soldier_pathindex[e] = PathIndex ai_path_point_index[e] = PathPointIndex ai_path_point_direction[e] = 1 ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e]) end elseif ai_soldier_pathindex[e] > -1 then ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e]) ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e]) AIEntityGoToPosition(AIObjNo,ai_patrol_x[e],ai_patrol_z[e]) if g_Entity[e]['animating'] ~= 6 then StopAnimation(e) SetAnimationFrames(walk_anim_s[e],walk_anim_e[e]) PlayAnimation(e) g_Entity[e]['animating'] = 6 else MoveForward(e,walk_speed[e]) end tDistX = g_Entity[e]['x'] - ai_patrol_x[e] tDistZ = g_Entity[e]['z'] - ai_patrol_z[e] DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ)) if DistFromPath < 50 then if ai_path_point_direction[e] == 1 then ai_path_point_index[e] = ai_path_point_index[e] + 1 if ( ai_path_point_index[e] > ai_path_point_max[e] ) then ai_path_point_index[e] = ai_path_point_max[e] - 1 ai_path_point_direction[e] = 0 end else ai_path_point_index[e] = ai_path_point_index[e] - 1 if ( ai_path_point_index[e] < 1 ) then ai_path_point_index[e] = 2 ai_path_point_direction[e] = 1 end end end else if g_Entity[e]['animating'] == 0 or g_Entity[e]['animating'] > 1 then StopAnimation(e) SetAnimationFrames(idle_anim_s[e],idle_anim_e[e]) PlayAnimation(e) g_Entity[e]['animating'] = 1 end end if g_Entity[e]['plrvisible'] == 1 or PlayerDist < AIGetEntityViewRange(AIObjNo)/3 or AIGetEntityHeardSound(AIObjNo) == 1 then ai_soldier_state[e] = "alert" PlaySoundIfSilent(e,1) end elseif ai_soldier_state[e] == "alert" then if PlayerDist > attack_range then if g_Entity[e]['animating'] ~= 2 then StopAnimation(e) SetAnimationFrames(run_anim_s[e],run_anim_e[e]) PlayAnimation(e) g_Entity[e]['animating'] = 2 elseif g_Entity[e]['animating'] == 2 then temproty[e] = 15-(PlayerDist/100) if temproty[e] < 3 then temproty[e] = 3 end AISetEntityTurnSpeed(AIObjNo,temproty[e]*10) AIEntityGoToPosition(AIObjNo,g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ) MoveForward(e,run_speed[e]) end else ai_soldier_state[e] = "attack" end elseif ai_soldier_state[e] == "attack" then if g_Entity[e]['animating'] ~= 3 then StopAnimation(e) if hit_in_leg[e] == 0 then temp = math.random(1,3) SetAnimationFrames(atk_anim_s[temp],atk_anim_e[temp]) last_atk_frame[e] = atk_anim_e[temp] else SetAnimationFrames(3865,3912) last_atk_frame[e] = 3912 end PlayAnimation(e) g_Entity[e]['animating'] = 3 hit[e] = 0 StartTimer(e) elseif g_Entity[e]['animating'] == 3 and GetTimer(e) > 15 then if GetAnimationFrame(e) > last_atk_frame[e]-15 and PlayerDist <= attack_range and hit[e] == 0 then hit[e] = 1 HurtPlayer(e,math.random(damage_min,damage_max)) end if GetAnimationFrame(e) >= last_atk_frame[e]-1 and GetAnimationFrame(e) <= last_atk_frame[e] then if hit_in_leg[e] == 0 then SetAnimationFrame(e,idle_anim_s[e]) else SetAnimationFrame(e,3865) end g_Entity[e]['animating'] = 0 ai_soldier_state[e] = "alert" end end elseif ai_soldier_state[e] == "hurt" then if g_Entity[e]['animating'] ~= 4 then StopAnimation(e) SetAnimationFrames(hurt_anim_s,hurt_anim_e) PlayAnimation(e) g_Entity[e]['animating'] = 4 elseif g_Entity[e]['animating'] == 4 then if GetAnimationFrame(e) >= hurt_anim_e-1 and GetAnimationFrame(e) <= hurt_anim_e then ai_soldier_state[e] = "alert" end end elseif ai_soldier_state[e] == "go prone" then if g_Entity[e]['animating'] == 0 then ai_soldier_state[e] = "alert" end end if hit_in_leg[e] == 0 then if string.find(string.lower(g_Entity[e]['limbhit']), "l_thigh") ~= nil or string.find(string.lower(g_Entity[e]['limbhit']), "l_foot") ~= nil then SetAnimationFrames(3578,3647) PlayAnimation(e) g_Entity[e]['animating'] = 5 walk_anim_s[e] = 3994 walk_anim_e[e] = 4013 run_anim_s[e] = 3994 run_anim_e[e] = 4013 idle_anim_s[e] = 3818 idle_anim_e[e] = 3818 run_speed[e] = run_speed[e]*0.6 walk_speed[e] = walk_speed[e]*0.6 hit_in_leg[e] = 1 ResetLimbHit(e) ai_soldier_state[e] = "go prone" elseif string.find(string.lower(g_Entity[e]['limbhit']), "r_thigh") ~= nil or string.find(string.lower(g_Entity[e]['limbhit']), "r_foot") ~= nil then SetAnimationFrames(3709,3779) PlayAnimation(e) g_Entity[e]['animating'] = 5 walk_anim_s[e] = 3994 walk_anim_e[e] = 4013 run_anim_s[e] = 3994 run_anim_e[e] = 4013 idle_anim_s[e] = 3818 idle_anim_e[e] = 3818 run_speed[e] = run_speed[e]*0.6 walk_speed[e] = walk_speed[e]*0.6 hit_in_leg[e] = 2 ResetLimbHit(e) ai_soldier_state[e] = "go prone" end end if string.find(string.lower(g_Entity[e]['limbhit']), "head") ~= nil then SetEntityHealth(e,0) ResetLimbHit(e) end if g_PlayerHealth < 1 then ai_soldier_state[e] = "idle" end if g_Entity[e]['health'] < ai_old_hp[e] and hit_in_leg[e] == 0 then ai_soldier_state[e] = "hurt" ai_old_hp[e] = g_Entity[e]['health']*0.6 PlayCharacterSound(e,"onHurt") end SetRotation(e,0,AIGetEntityAngleY(AIObjNo),0) AISetEntityPosition(AIObjNo,GetEntityPositionX(e),GetEntityPositionY(e),GetEntityPositionZ(e)) end function ai_zombie_custom_exit(e) PlayCharacterSound(e,"onDeath") if hit_in_leg[e] > 0 then CharacterControlLimbo(e) SetAnimationFrames(3913,3967) PlayAnimation(e) end end