Added CRASH event to dead check to catch planes getting killed as well

This commit is contained in:
Jeremy Smitherman 2019-01-08 23:34:08 -06:00
parent 2b54280fd2
commit f09435fc72

View File

@ -193,63 +193,64 @@ HOGGIT.setZombie = function(group, spawner, state)
end end
HOGGIT._deathHandler = function(event) HOGGIT._deathHandler = function(event)
if event.id ~= world.event.S_EVENT_DEAD then return end if event.id == world.event.S_EVENT_CRASH or event.id == world.event.S_EVENT_DEAD then
HOGGIT.debug_text("SOMETHING DEAD YO", 10) HOGGIT.debug_text("SOMETHING DEAD YO", 10)
if not event.initiator then return end if not event.initiator then return end
if not event.initiator.getGroup then return end if not event.initiator.getGroup then return end
local grp = event.initiator:getGroup():getName() local grp = event.initiator:getGroup():getName()
if grp then if grp then
HOGGIT.debug_text("FOUND GROUP", 10) HOGGIT.debug_text("FOUND GROUP", 10)
if HOGGIT.zombies[grp] then if HOGGIT.zombies[grp] then
HOGGIT.debug_text("CONFIRMED ZOMBIE", 10) HOGGIT.debug_text("CONFIRMED ZOMBIE", 10)
local spawner = HOGGIT.zombies[grp] local spawner = HOGGIT.zombies[grp]
HOGGIT.debug_text("FOUND SPAWNER", 10) HOGGIT.debug_text("FOUND SPAWNER", 10)
if HOGGIT.zombie_checks[spawner] then if HOGGIT.zombie_checks[spawner] then
HOGGIT.debug_text("FOUND SPAWNER CHECK", 10) HOGGIT.debug_text("FOUND SPAWNER CHECK", 10)
local s_func_id = HOGGIT.zombie_checks[spawner] local s_func_id = HOGGIT.zombie_checks[spawner]
mist.removeFunction(s_func_id) mist.removeFunction(s_func_id)
HOGGIT.debug_text("Removing dead check id ".. s_func_id .." for group: " .. grp, 10) HOGGIT.debug_text("Removing dead check id ".. s_func_id .." for group: " .. grp, 10)
end end
local new_func_id = mist.scheduleFunction(function() local new_func_id = mist.scheduleFunction(function()
HOGGIT.debug_text("STARTING DEAD CHECK", 10) HOGGIT.debug_text("STARTING DEAD CHECK", 10)
local needs_respawn = false local needs_respawn = false
local partial_respawn = false local partial_respawn = false
if not HOGGIT.GroupIsAlive(grp) then if not HOGGIT.GroupIsAlive(grp) then
needs_respawn = true
HOGGIT.debug_text("THEY DEAD, RESPAWNIN", 10)
elseif spawner:GetPartialDeathThresholdPercent() then
HOGGIT.debug_text("CHECKING PERCENT", 10)
local group_obj = Group.getByName(grp)
local group_size = group_obj:getSize()
local initial_size = group_obj:getInitialSize()
local percent_alive = group_size / initial_size * 100
HOGGIT.debug_text(percent_alive .. " percent alive. Threshold is " .. spawner:GetPartialDeathThresholdPercent(), 10)
if (100 - percent_alive) >= spawner:GetPartialDeathThresholdPercent() then
HOGGIT.debug_text("TRIGGERING PARTIAL RESPAWNING", 10)
needs_respawn = true needs_respawn = true
partial_respawn = true HOGGIT.debug_text("THEY DEAD, RESPAWNIN", 10)
elseif spawner:GetPartialDeathThresholdPercent() then
HOGGIT.debug_text("CHECKING PERCENT", 10)
local group_obj = Group.getByName(grp)
local group_size = group_obj:getSize()
local initial_size = group_obj:getInitialSize()
local percent_alive = group_size / initial_size * 100
HOGGIT.debug_text(percent_alive .. " percent alive. Threshold is " .. spawner:GetPartialDeathThresholdPercent(), 10)
if (100 - percent_alive) >= spawner:GetPartialDeathThresholdPercent() then
HOGGIT.debug_text("TRIGGERING PARTIAL RESPAWNING", 10)
needs_respawn = true
partial_respawn = true
end
end end
end
if needs_respawn then if needs_respawn then
HOGGIT.debug_text("GROUP NEEDS RESPAWNING", 10) HOGGIT.debug_text("GROUP NEEDS RESPAWNING", 10)
local delay = spawner:GetRespawnDelay(partial_respawn) local delay = spawner:GetRespawnDelay(partial_respawn)
HOGGIT.debug_text("DELAY OF " .. delay, 10) HOGGIT.debug_text("DELAY OF " .. delay, 10)
HOGGIT.zombies[grp] = nil HOGGIT.zombies[grp] = nil
mist.scheduleFunction(function() mist.scheduleFunction(function()
spawner.Spawn() spawner.Spawn()
end, {}, timer.getTime() + delay) end, {}, timer.getTime() + delay)
end end
HOGGIT.zombie_checks[spawner] = nil HOGGIT.zombie_checks[spawner] = nil
end, {}, timer.getTime() + 10) end, {}, timer.getTime() + 10)
HOGGIT.debug_text("Scheduled NEW dead check id ".. new_func_id .." for group: " .. grp, 10) HOGGIT.debug_text("Scheduled NEW dead check id ".. new_func_id .." for group: " .. grp, 10)
HOGGIT.zombie_checks[spawner] = new_func_id HOGGIT.zombie_checks[spawner] = new_func_id
else else
end
end end
end end
end end