local U = require "scriptbank\\utillib" g_ai_botList = g_ai_botList or {} local random = math.random --time to wait before removing the dead bodies (in seconds) --note, dont set too long or it may get removed by the system and then there will be no possibility of respawn local body_removal_delay = 30 --time to wait before respawning the enemies (in seconds) local respawn_delay = 30 --amount of variation in x,y and z placements when enemies are respawned (in percent) --note this is taken from where they originate local xmod = 0 local zmod = 0 local ymod = 0 local reposition = false local AItimer = {} local AIpos = {} function ai_respawner_init( e ) Include("utillib.lua") Hide( e ) CollisionOff( e ) end local botList = g_ai_botList local controlTimer = 0 ai_bot_state = ai_bot_state or {} local state = 'none' function ai_respawner_main( e ) local timeNow = g_Time if timeNow < controlTimer then return end controlTimer = timeNow + 1000 for k, v in pairs( botList ) do state = v.state if v.state == 'alive' and AIpos[ k ] == nil then local Ent = g_Entity[ k ] AIpos[ k ] = { x = Ent.x, y = Ent.y, z = Ent.z } elseif v.state == 'dead' then botList[ k ].state = 'droploot' if slaur3n_addBlood ~= nil then local Ent = g_Entity[ k ] slaur3n_addBlood( Ent.x, Ent.y, Ent.z, body_removal_delay * 1000 ) end elseif v.state == 'droploot' then botList[ k ].state = 'corpse' AItimer[ k ] = timeNow + ( body_removal_delay - 1 ) * 1000 ai_bot_state[ k ] = 1 elseif v.state == 'corpse' then --check body for removal if timeNow > AItimer[ k ] then AItimer[ k ] = timeNow + ( respawn_delay - 1 ) * 1000 Spawn( k ) CollisionOff( k ) botList[ k ].state = 'limbo' Hide( k ) ai_respawn_init_name( k, v.name ) end elseif v.state == 'limbo' then Hide( k ) CollisionOff( k ) if timeNow > AItimer[ k ] then botList[ k ].state = 'wait' end elseif v.state == 'wait' and not U.PlayerCloserThanPos( AIpos[ k ].x, AIpos[ k ].y, AIpos[ k ].z, 2000 ) then local x, y, z = AIpos[ k ].x, AIpos[ k ].y, AIpos[ k ].z if reposition then if xmod > 0 or xmod <= 99 then x = x * random( 1 - xmod / 10, 1 + xmod / 10 ) end if ymod > 0 or ymod <= 99 then y = y * random( 1 - ymod / 10, 1 + ymod / 10 ) end if zmod > 0 or zmod <= 99 then z = z * random( 1 - zmod / 10, 1 + zmod / 10 ) end end local Ent = g_Entity[ k ] SetPosition ( k, x, y, z ) ResetPosition( k, x, y, z ) AIEntityGoToPosition( Ent.obj, x, z ) AISetEntityPosition( Ent.obj, x, y, z ) botList[ k ].state = 'respawn' end end --PromptLocal( e, state ) end