Skip to content

Commit 96c5708

Browse files
Expand empty-bin to allow you to empty currently selected stockpile
1 parent ca3ace3 commit 96c5708

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

empty-bin.lua

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,26 @@ Empties the contents of the selected bin onto the floor.
1212
1313
]====]
1414

15-
local bin = dfhack.gui.getSelectedItem(true) or qerror("No item selected")
16-
local items = dfhack.items.getContainedItems(bin)
17-
18-
if #items > 0 then
19-
print('Emptying ' .. dfhack.items.getDescription(bin, 0))
20-
for _, item in pairs(items) do
21-
print(' ' .. dfhack.items.getDescription(item, 0))
22-
dfhack.items.moveToGround(item, xyz2pos(dfhack.items.getPosition(bin)))
15+
local function emptyContainer(container)
16+
local items = dfhack.items.getContainedItems(container)
17+
18+
if #items > 0 then
19+
print('Emptying ' .. dfhack.items.getDescription(container, 0))
20+
for _, item in pairs(items) do
21+
print(' ' .. dfhack.items.getDescription(item, 0))
22+
dfhack.items.moveToGround(item, xyz2pos(dfhack.items.getPosition(container)))
23+
end
24+
end
25+
end
26+
27+
28+
local stockpile = dfhack.gui.getSelectedStockpile(true)
29+
if stockpile then
30+
local contents = dfhack.buildings.getStockpileContents(stockpile)
31+
for _, container in ipairs(contents) do
32+
emptyContainer(container)
2333
end
2434
else
25-
print('No contained items')
35+
local bin = dfhack.gui.getSelectedItem(true) or qerror("No item selected")
36+
emptyContainer(bin)
2637
end

0 commit comments

Comments
 (0)