Here is the script
https://forum.game-guru.com/thread/207801?page=10#msg2533489
dead = {}
function ai_respawn_init(e)
package.path = "scriptbank/?.lua;"
require('ai_soldier') --name of AI script to use (no .lua needed)
ai_soldier_init(e) --init(e) call from the AI script used
dead[e] = 0
end
--script to be used in conjunction with ai_respawner.lua
function ai_respawn_main(e)
if dead[e] == 0 then
Show(e)
ai_soldier_main(e) --main(e) call from the AI script used
elseif dead[e] > 2 then
ai_soldier_init(e) --init(e) call from the AI script used
Hide(e)
CollisionOff(e)
end
end
function ai_respawn_exit(e)
dead[e] = 1
ai_soldier_exit(e) --exit(e) call from the AI script used
--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 = 2
--time to wait before respawning the enemies (in seconds)
local respawn_delay = 6
--amount of variation in x,y and z placements when enemies are respawned (in percent)
--note this is taken from where they die
--note2 y position doesnt currently work due to a GG bug
local xmod = 0.02
local zmod = 0.02
local ymod = 0
--time to wait between checks (for performance reasons)
local delay = 1000
---------
local x = {}
local y = {}
local z = {}
local timer = {}
--script to work in conjunction with ai_respawn.lua
--set always active
function ai_respawner_init(e)
Hide(e)
CollisionOff(e)
end
function ai_respawner_main(e)
Hide(e)
CollisionOff(e)
if GetTimer(e) > delay then
StartTimer(e)
for a = 1,9999 do
if g_Entity[a] ~= nil and a ~= e then
if dead[a] ~= nil then
if dead[a] == 1 then
if xmod <= 0 or xmod > 99 then
x[a] = g_Entity[a]['x']
else
x[a] = g_Entity[a]['x'] * math.random(1-(xmod/10),1+(xmod/10))
end
if ymod <= 0 or ymod > 99 then
y[a] = g_Entity[a]['y']
else
y[a] = g_Entity[a]['y'] * math.random(1-(ymod/10),1+(ymod/10))
end
if zmod <= 0 or zmod > 99 then
z[a] = g_Entity[a]['z']
else
z[a] = g_Entity[a]['z'] * math.random(1-(zmod/10),1+(zmod/10))
end
dead[a] = 2
timer[a] = g_Time + (body_removal_delay*1000)
--check body for removal
elseif dead[a] == 2 then
if g_Time >= timer[a] then
--PromptDuration("removed body",500)
timer[a] = g_Time + (respawn_delay*1000)
Spawn(a)
Hide(a)
CollisionOff(a)
SetPosition(a,x[a],y[a],z[a])
ResetPosition(a,x[a],y[a],z[a])
AIEntityGoToPosition(g_Entity[a]['obj'],x[a],z[a])
dead[a] = 3
end
--check for respawn
elseif dead[a] == 3 then
if g_Time >= timer[a] then
--PromptDuration("respawned enemy",500)
Show(a)
CollisionOn(a)
dead[a] = 0
end
end
end
end
end
end
end
function ai_respawner_exit(e)
end