Skip to content

Instantly share code, notes, and snippets.

@Meneth32
Created November 22, 2014 23:59
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 Meneth32/06f9b01db111778b4c42 to your computer and use it in GitHub Desktop.
Save Meneth32/06f9b01db111778b4c42 to your computer and use it in GitHub Desktop.
warn-creatures.lua
-- Pauses the game with a warning when a new creature enters the map.
oldUnits = oldUnits or {}
local units = df.global.world.units.active
local repeatUtil = require 'repeat-util'
local function findRaceCaste(unit)
local rraw = df.creature_raw.find(unit.race)
return rraw, safe_index(rraw, 'caste', unit.caste)
end
-- todo: check wildanimals in ShowUnitSyndromes.rb.
local function isWild(u)
if u.civ_id ~= -1 then return false end
if u.animal.population.region_x == -1 then return false end
--if u.flags2.visitor ~= 0 then return false end
return true
end
local function doCheck()
for i=#units-1,0,-1 do
local unit = units[i]
local rraw = findRaceCaste(unit)
if rraw and isWild(unit) and not unit.flags1.dead and not oldUnits[unit.id] then
local msg = "wild "..rraw.name[0].." appeared! ("..unit.id..")"
print(msg)
dfhack.gui.showPopupAnnouncement(msg, 7, true)
oldUnits[unit.id] = true
df.global.pause_state = true
end
end
end
doCheck()
repeatUtil.scheduleEvery('warn-creatures',100,'ticks',doCheck)
print("warn-creatures timer enabled.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment