Created
November 22, 2014 23:59
-
-
Save Meneth32/06f9b01db111778b4c42 to your computer and use it in GitHub Desktop.
warn-creatures.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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