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.
Difference between revisions of "User:Fleeting Frames/UnsuspendSelectedBuilding"
Jump to navigation
Jump to search
m (pre to source lang lua) |
m (Fixed segfault on constructions) |
||
Line 32: | Line 32: | ||
end | end | ||
− | function AnnounceEnd( | + | function AnnounceEnd(bldName) |
dfhack.gui.makeAnnouncement( | dfhack.gui.makeAnnouncement( | ||
df.announcement_type.QUOTA_FILLED, | df.announcement_type.QUOTA_FILLED, | ||
{D_DISPLAY = true}, | {D_DISPLAY = true}, | ||
xyz2pos(bld.centerx,bld.centery, bld.z), | xyz2pos(bld.centerx,bld.centery, bld.z), | ||
− | " | + | "Ended building " .. bldName .. ".", |
COLOR_GREEN, | COLOR_GREEN, | ||
true) | true) | ||
Line 57: | Line 57: | ||
if bldjob then | if bldjob then | ||
local myBldStr=tostring(bld) | local myBldStr=tostring(bld) | ||
+ | local myBldName = utils.getBuildingName(bld) --bld is lost on constructions, which means ending the loop would segfault due nil | ||
if(watchedbuildings[myBldStr] ~= false) then --don't set repeatfunc when there's already one | if(watchedbuildings[myBldStr] ~= false) then --don't set repeatfunc when there's already one | ||
repeatfunction( | repeatfunction( | ||
function() | function() | ||
− | if(watchedbuildings[myBldStr]) then | + | if(watchedbuildings[myBldStr]) then |
local bld = df.building.find(watchedbuildings[myBldStr]) | local bld = df.building.find(watchedbuildings[myBldStr]) | ||
local bldjob = bld and getConstructionJob(bld) | local bldjob = bld and getConstructionJob(bld) | ||
− | if bld and bldjob then | + | if bld and bldjob and bld.flags.exists == false then |
bldjob.flags.suspend=false | bldjob.flags.suspend=false | ||
− | + | return true | |
− | |||
− | |||
end | end | ||
end | end | ||
− | watchedbuildings[ | + | print("ending..") |
− | AnnounceEnd( | + | watchedbuildings[myBldStr] = nil --if didn't return, end is at hand |
+ | AnnounceEnd(myBldName) | ||
end | end | ||
) | ) |
Revision as of 12:07, 5 July 2019
Save as UnsuspendSelectedBuilding.lua into /hack/scripts folder.
--auto-unsuspend selected building.
local bld = dfhack.gui.getSelectedBuilding(true)
utils = require 'utils';
if not bld.construction_stage then qerror("Building " .. utils.getBuildingName(bld) .. " isn't constructed in stages.") end
local function repeatfunction(rfunc)
--repeats a function every 10 frames, until the function returns false or nil
local myrfunc
myrfunc = function ()
timeoutid = dfhack.timeout(10, "ticks", function(options)
if rfunc() then myrfunc() end
end)
end
myrfunc()
end
function AnnounceStart(bld)
dfhack.gui.makeAnnouncement(
df.announcement_type.JOB_OVERWRITTEN,
{D_DISPLAY = true},
xyz2pos(bld.centerx,bld.centery, bld.z),
"Started unsuspending " .. utils.getBuildingName(bld) .. ".",
COLOR_GREEN,
true)
end
function AnnounceEnd(bldName)
dfhack.gui.makeAnnouncement(
df.announcement_type.QUOTA_FILLED,
{D_DISPLAY = true},
xyz2pos(bld.centerx,bld.centery, bld.z),
"Ended building " .. bldName .. ".",
COLOR_GREEN,
true)
end
function getConstructionJob(building)
for _, attachedjob in ipairs(building.jobs) do
if attachedjob.job_type == 68 then
return attachedjob
end
end
end
watchedbuildings = watchedbuildings or {}
if (bld and not watchedbuildings[tostring(bld)]) then
if bld.flags.exists == false then
local bldjob=getConstructionJob(bld)
if bldjob then
local myBldStr=tostring(bld)
local myBldName = utils.getBuildingName(bld) --bld is lost on constructions, which means ending the loop would segfault due nil
if(watchedbuildings[myBldStr] ~= false) then --don't set repeatfunc when there's already one
repeatfunction(
function()
if(watchedbuildings[myBldStr]) then
local bld = df.building.find(watchedbuildings[myBldStr])
local bldjob = bld and getConstructionJob(bld)
if bld and bldjob and bld.flags.exists == false then
bldjob.flags.suspend=false
return true
end
end
print("ending..")
watchedbuildings[myBldStr] = nil --if didn't return, end is at hand
AnnounceEnd(myBldName)
end
)
end
watchedbuildings[tostring(bld)]=bld.id
AnnounceStart(bld)
end
end
elseif (bld and watchedbuildings[tostring(bld)]) then
watchedbuildings[tostring(bld)] = false
dfhack.gui.makeAnnouncement(
df.announcement_type.JOB_OVERWRITTEN,
{D_DISPLAY = true},
xyz2pos(bld.centerx,bld.centery, bld.z),
"Stopped unsuspending " .. utils.getBuildingName(bld) .. ".",
COLOR_GREEN,
true)
end