Skip to content

Instantly share code, notes, and snippets.

@Hopper262
Created July 25, 2021 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hopper262/5b2d5d3e0fa82be0f17d584dd41b959d to your computer and use it in GitHub Desktop.
Save Hopper262/5b2d5d3e0fa82be0f17d584dd41b959d to your computer and use it in GitHub Desktop.
Show info during Vidmaster films
Triggers = {}
-- end game on level transition? (to dump IL movies)
exit_after_first_level = true
-- globals
MonsterGroups = {}
MonsterGroups.human = {}
MonsterGroups.pfhor = {}
MonsterGroups.spht = {}
MonsterGroups.native = {}
MonsterGroups.human.infinite = false
MonsterGroups.human.not_spawned = 0
MonsterGroups.human.not_killed = 0
MonsterGroups.human.killed_direct = 0
MonsterGroups.human.killed_indirect = 0
MonsterGroups.human.escaped = 0
MonsterGroups.pfhor.infinite = false
MonsterGroups.pfhor.not_spawned = 0
MonsterGroups.pfhor.not_killed = 0
MonsterGroups.pfhor.killed_direct = 0
MonsterGroups.pfhor.killed_indirect = 0
MonsterGroups.pfhor.escaped = 0
MonsterGroups.spht.infinite = false
MonsterGroups.spht.not_spawned = 0
MonsterGroups.spht.not_killed = 0
MonsterGroups.spht.killed_direct = 0
MonsterGroups.spht.killed_indirect = 0
MonsterGroups.spht.escaped = 0
MonsterGroups.native.infinite = false
MonsterGroups.native.not_spawned = 0
MonsterGroups.native.not_killed = 0
MonsterGroups.native.killed_direct = 0
MonsterGroups.native.killed_indirect = 0
MonsterGroups.native.escaped = 0
AmmoLeft = {}
AmmoLeft.infinite = false
AmmoLeft.grabbed = 0
AmmoLeft.total = 0
ShotsFired = {}
ShotsFired.fired_this_tick = false
ShotsFired.total = 0
PlayerDamage = {}
PlayerDamage.total = 0
TrackedMonsters = {}
function Triggers.init(restoring_game)
Game.restore_passed()
if Players[0]._inited then
if exit_after_first_level then
Players[0]._end_game = true
end
else
Players[0]._inited = true
end
-- set up monster groups
MonsterClasses["bob"]._group = MonsterGroups.human
MonsterClasses["madd"]._group = MonsterGroups.human
MonsterClasses["possessed drone"]._group = MonsterGroups.human
MonsterClasses["defender"]._group = MonsterGroups.spht
MonsterClasses["fighter"]._group = MonsterGroups.pfhor
MonsterClasses["trooper"]._group = MonsterGroups.pfhor
MonsterClasses["hunter"]._group = MonsterGroups.pfhor
MonsterClasses["enforcer"]._group = MonsterGroups.pfhor
MonsterClasses["juggernaut"]._group = MonsterGroups.pfhor
MonsterClasses["drone"]._group = MonsterGroups.pfhor
MonsterClasses["compiler"]._group = MonsterGroups.spht
MonsterClasses["cyborg"]._group = MonsterGroups.pfhor
MonsterClasses["explodabob"]._group = MonsterGroups.pfhor
MonsterClasses["tick"]._group = MonsterGroups.native
MonsterClasses["yeti"]._group = MonsterGroups.native
-- set up infinite
for mt in MonsterTypes() do
if mt.class._group then
if (mt.total_available == -1 and mt.random_chance > 0) or (mt.minimum_count > 0) then
mt.class._group.infinite = true
end
end
end
for it in ItemTypes() do
if it.kind == "ammunition" then
if (it.total_available == -1 and it.random_chance > 0) or (it.minimum_count > 0) then
AmmoLeft.infinite = true
end
end
end
end
function Triggers.got_item(type, player)
if type.kind == "ammunition" then
AmmoLeft.grabbed = AmmoLeft.grabbed + 1
end
end
function Triggers.player_damaged(victim, aggressor_player, aggressor_monster, damage_type, damage_amount, projectile)
if not (damage_type == "oxygen drain") then
PlayerDamage.total = PlayerDamage.total + damage_amount
end
end
function Triggers.monster_killed(monster, aggressor, projectile)
-- if not monster._tracked then
-- Players.print(("%i"):format(Game.ticks) .. " Untracked monster " .. ("%i"):format(monster.index) .. " was killed" .. " [" .. monster.type.class.mnemonic .. "]")
-- end
if monster._killed then
return
end
monster._killed = true
mgroup = monster.type.class._group
if mgroup then
TrackedMonsters[monster.index] = nil
if projectile and projectile.owner and projectile.owner.type == "player" then
mgroup.killed_direct = mgroup.killed_direct + 1
else
mgroup.killed_indirect = mgroup.killed_indirect + 1
end
end
end
function Triggers.projectile_created(projectile)
if projectile.owner and (projectile.owner.type == "player") and (not (projectile.type == "fist")) then
-- only count 1 shot per tick, to account for shotgun
if not ShotsFired.fired_this_tick then
ShotsFired.fired_this_tick = true
ShotsFired.total = ShotsFired.total + 1
end
end
end
function Triggers.idle()
if Players[0]._end_game then
Game.over = true
end
ShotsFired.fired_this_tick = false
-- detect monsters removed last tick without being killed
for idx, mgroup in pairs(TrackedMonsters) do
if mgroup then
m = Monsters[idx]
if (m == nil) or (not m.valid) or (not m._tracked) then
-- Players.print(("%i"):format(Game.ticks) .. " Monster " .. ("%i"):format(idx) .. " escaped")
mgroup.escaped = mgroup.escaped + 1
end
end
end
-- calculate monster stats
for g, v in pairs(MonsterGroups) do
MonsterGroups[g].not_spawned = 0
MonsterGroups[g].not_visible = 0
MonsterGroups[g].not_killed = 0
end
for mt in MonsterTypes() do
if mt.total_available > 0 then
mgroup = mt.class._group
if mgroup then
mgroup.not_spawned = mgroup.not_spawned + mt.total_available
end
end
end
TrackedMonsters = {}
for m in Monsters() do
mgroup = m.type.class._group
if mgroup and (not m._killed) then
if not m.visible then
mgroup.not_visible = mgroup.not_visible + 1
else
mgroup.not_killed = mgroup.not_killed + 1
end
m._tracked = true
m._killed = false
TrackedMonsters[m.index] = mgroup
end
end
-- count items
ammo_text = ""
if not AmmoLeft.infinite then
AmmoLeft.total = 0
for it in ItemTypes() do
if it.kind == "ammunition" then
if it.total_available > 0 then
AmmoLeft.total = AmmoLeft.total + it.total_available
end
end
end
for i in Items() do
if i.type and i.type.kind == "ammunition" then
AmmoLeft.total = AmmoLeft.total + 1
end
end
ammo_text = "Ammo: " .. ("%i"):format(AmmoLeft.grabbed) .. "/" .. ("%i"):format(AmmoLeft.total + AmmoLeft.grabbed) .. " "
end
-- display stats
Players[0].overlays[0].text =
kill_counts("human") ..
kill_counts("pfhor") ..
kill_counts("spht") ..
kill_counts("native") ..
"Shots: " .. ("%i"):format(ShotsFired.total) .. " " ..
"Dmg: " .. ("%i"):format(PlayerDamage.total) .. " " ..
ammo_text ..
formatTime(Game.ticks)
end
function kill_counts(group)
text = ""
mgroup = MonsterGroups[group]
total = mgroup.not_spawned + mgroup.not_visible + mgroup.not_killed + mgroup.escaped + mgroup.killed_direct + mgroup.killed_indirect
if mgroup.infinite then
if mgroup.escaped > 0 then
text = ("%i"):format(mgroup.escaped) .. " escaped, "
end
text = text .. ("%i"):format(mgroup.killed_direct + mgroup.killed_indirect) .. " killed"
elseif total > 0 then
text = ("%i"):format(mgroup.not_spawned + mgroup.not_visible + mgroup.not_killed)
if mgroup.escaped > 0 then
text = text .. "(+" .. ("%i"):format(mgroup.escaped) .. ")"
end
text = text .. "/" .. ("%i"):format(total)
end
if string.len(text) > 0 then
return group .. ": " .. text .. " "
end
return ""
end
function formatTime(ticks)
return ("%i"):format(math.floor(ticks / (30*60*60)) % 60) ..
":" .. ("%02i"):format(math.floor(ticks / (30*60)) % 60) ..
":" .. ("%02i"):format(math.floor(ticks / 30) % 60) ..
"." .. ("%02i"):format((ticks % 30) * 100/30)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment