Added mostly complete zombie solution for respawning

This commit is contained in:
Jeremy Smitherman 2018-12-25 00:07:58 -06:00
parent af4fa9d854
commit fa8a7e0c04

View File

@ -59,7 +59,10 @@ HOGGIT.Spawner = function(grpName)
mist.scheduleFunction(CallBack.func, {added_grp, unpack(CallBack.args)}, timer.getTime() + 1) mist.scheduleFunction(CallBack.func, {added_grp, unpack(CallBack.args)}, timer.getTime() + 1)
end end
SpawnedGroups[added_grp] = true SpawnedGroups[added_grp] = true
if zombie then HOGGIT.setZombie(HOGGIT.zombies, added_grp, self, true) end if zombie then
HOGGIT.setZombie(added_grp, self, true)
trigger.action.outText("Spawned new zombie " .. added_grp:getName(), 3)
end
return added_grp return added_grp
end, end,
@ -83,7 +86,7 @@ HOGGIT.Spawner = function(grpName)
end end
local added_grp = Group.getByName(name) local added_grp = Group.getByName(name)
SpawnedGroups[added_grp] = true SpawnedGroups[added_grp] = true
if zombie then HOGGIT.setZombie(HOGGIT.zombies, added_grp, self, true) end if zombie then HOGGIT.setZombie(added_grp, self, true) end
return added_grp return added_grp
else else
trigger.action.outText("Error spawning " .. grpName, 15) trigger.action.outText("Error spawning " .. grpName, 15)
@ -102,7 +105,7 @@ HOGGIT.Spawner = function(grpName)
mist.scheduleFunction(CallBack.func, {added_grp, unpack(CallBack.args)}, timer.getTime() + 1) mist.scheduleFunction(CallBack.func, {added_grp, unpack(CallBack.args)}, timer.getTime() + 1)
end end
SpawnedGroups[added_grp] = true SpawnedGroups[added_grp] = true
if zombie then HOGGIT.setZombie(HOGGIT.zombies, added_grp, self, true) end if zombie then HOGGIT.setZombie(added_grp, self, true) end
return added_grp return added_grp
end, end,
@ -137,7 +140,7 @@ HOGGIT.Spawner = function(grpName)
self:SetZombieOptions({ self:SetZombieOptions({
['zombie'] = true, ['zombie'] = true,
['respawn_delay'] = respawn_delay, ['respawn_delay'] = respawn_delay,
['partial_death_threshold_percent'] = respawn_delay, ['partial_death_threshold_percent'] = partial_death_threshold_percent,
['partial_death_respawn_delay'] = partial_death_respawn_delay ['partial_death_respawn_delay'] = partial_death_respawn_delay
}) })
end end
@ -157,6 +160,18 @@ HOGGIT.Spawner = function(grpName)
trigger.action.outText(GroupName .. " is now a zombie! Arggghhh!", 10) trigger.action.outText(GroupName .. " is now a zombie! Arggghhh!", 10)
end end
end, end,
GetRespawnDelay = function(self, partial)
if partial then
return partial_death_respawn_delay
else
return respawn_delay
end
end,
GetPartialDeathThresholdPercent = function(self)
return partial_death_threshold_percent
end
} }
end end
@ -169,47 +184,58 @@ HOGGIT.SetupDefaultSpawners = function()
end end
end end
HOGGIT.setZombie = function(zombie_tracker, group, spawner, state) HOGGIT.setZombie = function(group, spawner, state)
if state then if state then
zombie_tracker[group] = spawner HOGGIT.zombies[group:getName()] = spawner
else else
zombie_tracker[group] = nil HOGGIT.zombies[group:getName()] = nil
end end
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_DEAD then return end
trigger.action.outText("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() local grp = event.initiator:getGroup():getName()
if grp then if grp then
trigger.action.outText("FOUND GROUP", 10)
if HOGGIT.zombies[grp] then if HOGGIT.zombies[grp] then
trigger.action.outText("CONFIRMED ZOMBIE", 10)
local spawner = HOGGIT.zombies[grp] local spawner = HOGGIT.zombies[grp]
trigger.action.outText("FOUND SPAWNER", 10)
if HOGGIT.zombie_checks[spawner] then if HOGGIT.zombie_checks[spawner] then
trigger.action.outText("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)
trigger.action.outText("Removing dead check id ".. s_func_id .." for group: " + grp:getName()) trigger.action.outText("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()
trigger.action.outText("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 needs_respawn = true
elseif spawner.partial_death_threshold_percent then trigger.action.outText("THEY DEAD, RESPAWNIN", 10)
local group_size = grp:getSize() elseif spawner:GetPartialDeathThresholdPercent() then
local initial_size = grp:getInitialSize() trigger.action.outText("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 local percent_alive = group_size / initial_size * 100
trigger.action.outText(percent_alive .. " percent alive. Threshold is " .. spawner:GetPartialDeathThresholdPercent(), 10)
if (percent_alive - 100) >= partial_death_threshold_percent then if (100 - percent_alive) >= spawner:GetPartialDeathThresholdPercent() then
trigger.action.outText("TRIGGERING PARTIAL RESPAWNING", 10)
needs_respawn = true needs_respawn = true
partial_respawn = true partial_respawn = true
end end
end end
if needs_respawn then if needs_respawn then
local delay = spawner.respawn_delay trigger.action.outText("GROUP NEEDS RESPAWNING", 10)
if partial_respawn then delay = spawner.partial_death_respawn_delay end local delay = spawner:GetRespawnDelay(partial_respawn)
trigger.action.outText("DELAY OF " .. delay, 10)
HOGGIT.zombies[grp] = nil HOGGIT.zombies[grp] = nil
mist.scheduleFunction(function() mist.scheduleFunction(function()
@ -220,10 +246,19 @@ HOGGIT._deathHandler = function(event)
end, {}, timer.getTime() + 10) end, {}, timer.getTime() + 10)
trigger.action.outText("Scheduled NEW dead check id ".. new_func_id .." for group: " .. grp:getName()) trigger.action.outText("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
end end
end end
end end
mist.scheduleFunction(function()
trigger.action.outText("Showing current zombies", 10)
for i,data in pairs(HOGGIT.zombies) do
if HOGGIT.zombies[i] then trigger.action.outText("TOOOO", 10) end
if HOGGIT.zombies['IRAN gnd 1'] then trigger.action.outText("DOOOOOO", 10) end
end
end, {}, timer.getTime() + 40)
mist.addEventHandler(HOGGIT._deathHandler) mist.addEventHandler(HOGGIT._deathHandler)