local body_removal_time = 2100 local g_spawn_state = {} local g_current_time = {} local g_starting_health = {} local g_posx = {} local g_posy = {} local g_posz = {} local g_angx = {} local g_angy = {} local g_angz = {} local dead = {} local start_level = 0 local player_respawning = 0 checkpoints = 0 local last_checkpoint = {} function ai_respawn_control_init(e) end function ai_respawn_control_main(e) if start_level == 0 then start_level = 1 return elseif start_level == 1 then for a,_ in pairs(ai_bot_state) do if g_posx[a] == nil then g_starting_health[a] = g_Entity[a]['health'] g_posx[a] = GetEntityPositionX(a) g_posy[a] = GetEntityPositionY(a) g_posz[a] = GetEntityPositionZ(a) g_angx[a] = g_Entity[a]['anglex'] g_angy[a] = AIGetEntityAngleY(g_Entity[a]['obj']) g_angz[a] = g_Entity[a]['anglez'] last_checkpoint[a] = checkpoints dead[a] = nil end end start_level = 2 else if g_PlayerHealth < 1 then player_respawning = 1 elseif player_respawning == 1 then for a,_ in pairs(ai_bot_state) do if g_posx[a] ~= nil then if checkpoints <= last_checkpoint[a] then Spawn(a) CollisionOff(a) SetPosition(a,g_posx[a],g_posy[a],g_posz[a]) ResetPosition(a,g_posx[a],g_posy[a],g_posz[a]) SetRotation(a,g_angx[a],g_angy[a],g_angz[a]) CollisionOn(a) StartTimer(a) SetEntityHealth(a,g_starting_health[a]) Show(a) dead[a] = nil ai_soldier_init(a) ai_soldier_main(a) end end end player_respawning = 0 end if GetTimer(e) > 100 then StartTimer(e) for a,_ in pairs(ai_bot_state) do if g_Entity[a]['health'] < 1 then if dead[a] == nil then dead[a] = 1 StartTimer(a) elseif dead[a] == 1 then if GetTimer(a) > body_removal_time then Spawn(a) StartTimer(a) SetEntityHealth(a,g_starting_health[a]) Hide(a) CollisionOff(a) SetPosition(a,0,5000,0) ResetPosition(a,0,5000,0) SetRotation(a,g_angx[a],g_angy[a],g_angz[a]) dead[a] = 2 last_checkpoint[a] = checkpoints end end end end end end end function ai_respawn_control_exit(e) end