Skip to content

Instantly share code, notes, and snippets.

@Putnam3145
Created July 5, 2018 06:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Putnam3145/9f1958c64ac1df910e74e73e4c296f7e to your computer and use it in GitHub Desktop.
Save Putnam3145/9f1958c64ac1df910e74e73e4c296f7e to your computer and use it in GitHub Desktop.
Sets all beds with no rooms set to have rooms.
-- Autoassigns all beds which do not have assigned rooms to rooms.
-- Will flood fill up to -size size.
--[====[
bedassign
======
Sets all beds with no rooms set to have rooms.
bedassign -size will set all rooms to press the + key -size times. Setting -size to a negative value will press the - key instead.
]====]
local script=require('gui.script')
local gui=require('gui')
if not assert(dfhack.gui.getSelectedBuilding()) then qerror('must be building selection mode') end
local utils=require('utils')
local validArgs = utils.invert({
'size'
})
local args = utils.processArgs({...}, validArgs)
function assignBeds(arg)
for k,v in ipairs(df.global.world.buildings.other.BED) do
if v.construction_stage==1 and not v.is_room then
script.sleep(2,'frames')
df.global.cursor.x=v.centerx
df.global.cursor.y=v.centery
df.global.cursor.z=v.z
gui.simulateInput(dfhack.gui.getCurViewscreen(),'CURSOR_DOWN')
script.sleep(2,'frames')
gui.simulateInput(dfhack.gui.getCurViewscreen(),'CURSOR_UP')
script.sleep(2,'frames')
gui.simulateInput(dfhack.gui.getCurViewscreen(),'BUILDJOB_BED_SIZE')
if arg.size then
if arg.size>=0 then
for i=1,arg.size do
script.sleep(2,'frames')
gui.simulateInput(dfhack.gui.getCurViewscreen(),'SECONDSCROLL_DOWN')
end
else
for i=1,math.abs(arg.size) do
script.sleep(2,'frames')
gui.simulateInput(dfhack.gui.getCurViewscreen(),'SECONDSCROLL_UP')
end
end
end
script.sleep(2,'frames')
gui.simulateInput(dfhack.gui.getCurViewscreen(),'SELECT')
end
end
end
script.start(assignBeds,args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment