local g_posx = {} local g_posy = {} local g_posz = {} local g_angx = {} local g_angy = {} local g_angz = {} 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) --first run check just so we don't miss any AI that hasn't been spawned by the engine yet if start_level == 0 then start_level = 1 return --get all AI positions so we can put them back later elseif start_level == 1 then for a,_ in pairs(ai_bot_state) do if g_posx[a] == nil then 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 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) end end end player_respawning = 0 else if GetTimer(e) > 100 then StartTimer(e) for a,_ in pairs(ai_bot_state) do if g_Entity[a]['health'] > 0 then last_checkpoint[a] = checkpoints end end end end end end function ai_respawn_control_exit(e) end