v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

User:Fleeting Frames/setwarning

From Dwarf Fortress Wiki
Jump to navigation Jump to search

Save as setwarning.lua into /hack/scripts folder.

--used to give warning a day and step before migrants or caravans arrive.

local interestingTypes = {}
interestingTypes[0] = "Caravan"
interestingTypes[1] = "Migrants"
interestingTypes[6] = "Gremlin"
interestingTypes[8] = "Werebeast"

local dayWarning = true
local stepWarning = true

local curTime = df.global.cur_year_tick
local eventTime
setTimers = setTimers or {} --Only want 1 announcement, which means need to track which events already have announcements set
local timer

for index, event in ipairs(df.global.timed_events) do
	if interestingTypes[event.type] then
		eventTime = 10*(event.season_ticks+event.season*10080)
		
		if not setTimers[eventTime] then
		if stepWarning and ((eventTime-1) > curTime) then
			local announcementTextStep = "Warning: " .. interestingTypes[event.type] .. " coming on next step!"
			setTimers[eventTime] = dfhack.timeout((eventTime-curTime-1), "ticks", function()
				df.global.pause_state = true --insurance
				dfhack.gui.showPopupAnnouncement(
					announcementTextStep,
					COLOR_RED,
					true)
					setTimers[eventTime] = nil --cleanup
			end)
		end
		
		if dayWarning and ((eventTime-1200) > curTime) then
			local announcementTextDay = "Warning: " .. interestingTypes[event.type] .. " coming in a day!"
			setTimers[eventTime] = dfhack.timeout((eventTime-curTime-1200), "ticks", function()
				df.global.pause_state = true --insurance
				dfhack.gui.showPopupAnnouncement(
					announcementTextDay,
					COLOR_RED,
					true)
			end)
		end
		end
	end
end