Skip to content

Instantly share code, notes, and snippets.

@stonetoad
Created April 21, 2014 00:33
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 stonetoad/11129025 to your computer and use it in GitHub Desktop.
Save stonetoad/11129025 to your computer and use it in GitHub Desktop.
Some helper scripts for dfhack
-- Empty a bin onto the floor
print('Finding selected item...')
a = dfhack.gui.getSelectedItem()
print('Found ', dfhack.items.getDescription(a,0))
if not a then dfhack.printerr("No item selected!")
end
loc = a.pos
-- dfhack.items.moveToGround(a,loc)
for _,k in pairs(dfhack.items.getContainedItems(a)) do
print (' ', dfhack.items.getDescription(k,0))
r = dfhack.items.moveToGround(k,loc)
end
print('Done.')
-- Split the selected stack into single items
-- Only tested with coins...
print('Finding selected item...')
a = dfhack.gui.getSelectedItem()
print('Found ', dfhack.items.getDescription(a,0))
if not a then dfhack.printerr("No item selected!")
end
loc = a.pos
dfhack.items.moveToGround(a,loc)
split_size = 1 -- split the stack into split_size stacks
while a.stack_size > split_size do
n = a:new()
n.stack_size = split_size
a.stack_size = a.stack_size - n.stack_size
n.id = df.global.item_next_id
df.global.item_next_id = df.global.item_next_id + 1
-- n.categorize(true) -- bugged, need it for stuff to show up in stocks
df.global.world.items.all:insert('#',n)
n.flags.on_ground = false
n.flags.removed = true -- it's not actually anywhere
n.flags.garbage_collect = true -- hack to get categorize called for us...
dfhack.items.moveToGround(n, loc)
end
print('Done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment