local hit = {} local targetx = {} local targetz = {} local startx = {} local startz = {} local hp_set = {} --time until enemy swaps from attack to alert (while player can't be seen) local back_to_alert = 6000 --time until enemy swaps from alert to patrol/idle (while player can't be seen) local back_to_patrol = 3000 function soldier_init(e) ai_soldier_state[e] = "patrol" hit[e] = 0 end function soldier_main(e) if hp_set[e] == nil then hp_set[e] = 1 SetEntityHealth(e,g_Entity[e]['health']+5000) else if targetx[e] == nil or targetz[e] == nil then targetx[e] = g_Entity[e]['x'] targetz[e] = g_Entity[e]['z'] startx[e] = g_Entity[e]['x'] startz[e] = g_Entity[e]['z'] end if frozen == 0 then if g_Entity[e]['health'] < 5000 then SetEntityHealth(e,0) end if ai_soldier_state[e] == "patrol" then CharacterControlUnarmed(e) StartTimer(e) if g_Entity[e]['plrvisible'] == 1 or AIGetEntityHeardSound(g_Entity[e]['obj']) == 1 then targetx[e] = g_PlayerPosX targetz[e] = g_PlayerPosZ ai_soldier_state[e] = "alert" else targetx[e] = startx[e] targetz[e] = startz[e] end AIEntityGoToPosition(g_Entity[e]['obj'],targetx[e],targetz[e]) elseif ai_soldier_state[e] == "alert" then CharacterControlArmed(e) AIEntityGoToPosition(g_Entity[e]['obj'],targetx[e],targetz[e]) if g_Entity[e]['plrvisible'] == 1 or AIGetEntityHeardSound(g_Entity[e]['obj']) == 1 then StartTimer(e) targetx[e] = g_PlayerPosX targetz[e] = g_PlayerPosZ if GetPlayerDistance(e) < 800 then ai_soldier_state[e] = "attack" end else if GetTimer(e) > back_to_patrol then ai_soldier_state[e] = "patrol" end end elseif ai_soldier_state[e] == "attack" then RotateToPlayer(e) if g_Entity[e]['plrvisible'] == 1 then targetx[e] = g_PlayerPosX targetz[e] = g_PlayerPosZ StartTimer(e) if GetPlayerDistance(e) < 800 then CharacterControlArmed(e) FireWeapon(e) else ai_soldier_state[e] = "alert" end else CharacterControlArmed(e) AIEntityGoToPosition(g_Entity[e]['obj'],targetx[e],targetz[e]) if GetTimer(e) > back_to_alert then StartTimer(e) ai_soldier_state[e] = "alert" end end end --state else targetx[e] = g_Entity[e]['x'] targetz[e] = g_Entity[e]['z'] if g_Entity[e]['health'] < 5000 then if GetPlayerDistance(e) > 80 then CollisionOff(e) else CollisionOn(e) end SetEntityHealth(e,4999) end end --frozen end --hp set --Prompt(ai_soldier_state[e].." "..AIGetEntityHeardSound(g_Entity[e]['obj']).." "..g_Entity[e]['plrvisible'].." "..GetAnimationFrame(e)) end function soldier_exit(e) end