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/wheelbarrow-stuckinside"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
m (pre to source lang lua)
m (Spacing, spaces for tabs)
 
Line 1: Line 1:
Save aswheelbarrow-stuckinside.lua into /hack/scripts/fix folder.
+
Save as wheelbarrow-stuckinside.lua into /hack/scripts/fix folder.
  
 
If called with verbose parameter, prints out the wheelbarrows it looks at as well as the positions for each item it dumps out.
 
If called with verbose parameter, prints out the wheelbarrows it looks at as well as the positions for each item it dumps out.
Line 11: Line 11:
  
 
function printv(...)
 
function printv(...)
if verbose then print(...) end
+
    if verbose then print(...) end
 
end
 
end
  
 
for _, wb in ipairs(df.global.world.items.other.TOOL) do
 
for _, wb in ipairs(df.global.world.items.other.TOOL) do
if    wb.subtype.id == "ITEM_TOOL_WHEELBARROW" and wb.stockpile.id ~= -1  then
+
    if    wb.subtype.id == "ITEM_TOOL_WHEELBARROW" and wb.stockpile.id ~= -1  then
printv(wb.id)
+
    printv(wb.id)
local stuckpile = df.building.find(wb.stockpile.id)
+
    local stuckpile = df.building.find(wb.stockpile.id)
if ((wb.pos.x>=stuckpile.x1 and stuckpile.x2>=wb.pos.x) and  
+
    if   ((wb.pos.x>=stuckpile.x1 and stuckpile.x2>=wb.pos.x) and  
(wb.pos.y>=stuckpile.y1 and stuckpile.y2>=wb.pos.y) and  
+
        (wb.pos.y>=stuckpile.y1 and stuckpile.y2>=wb.pos.y) and  
wb.pos.z == stuckpile.z)
+
        wb.pos.z == stuckpile.z)
and not (wb.flags.in_inventory)  then
+
        and not (wb.flags.in_inventory)  then
for i = (#wb.general_refs-1), 0, -1 do
+
        for i = (#wb.general_refs-1), 0, -1 do
--for i,v in ipairs(wb.general_refs) do
+
        --for i,v in ipairs(wb.general_refs) do
if wb.general_refs[i]._type == df.general_ref_contains_itemst then
+
            if wb.general_refs[i]._type == df.general_ref_contains_itemst then
local stuckitem = df.item.find(wb.general_refs[i].item_id)
+
                local stuckitem = df.item.find(wb.general_refs[i].item_id)
if not stuckitem.flags.in_job then dfhack.items.moveToGround(stuckitem,wb.pos) printv("dumped item out", pos2xyz(wb.pos)) end
+
                if not stuckitem.flags.in_job then dfhack.items.moveToGround(stuckitem,wb.pos) printv("dumped item out", pos2xyz(wb.pos)) end
 
                         end
 
                         end
end
+
        end
end
+
    end
end
+
    end
 
end
 
end
 
</source>
 
</source>

Latest revision as of 05:12, 14 October 2019

Save as wheelbarrow-stuckinside.lua into /hack/scripts/fix folder.

If called with verbose parameter, prints out the wheelbarrows it looks at as well as the positions for each item it dumps out.

--empties wheelbarrows of stuck stones

local args = ...
local verbose = false
if args == "verbose" then verbose = true end

function printv(...)
    if verbose then print(...) end
end

for _, wb in ipairs(df.global.world.items.other.TOOL) do
    if     wb.subtype.id == "ITEM_TOOL_WHEELBARROW" and wb.stockpile.id ~= -1   then
    printv(wb.id)
    local stuckpile = df.building.find(wb.stockpile.id)
    if    ((wb.pos.x>=stuckpile.x1 and stuckpile.x2>=wb.pos.x) and 
        (wb.pos.y>=stuckpile.y1 and stuckpile.y2>=wb.pos.y) and 
        wb.pos.z == stuckpile.z)
        and not (wb.flags.in_inventory)  then
        for i = (#wb.general_refs-1), 0, -1 do
        --for i,v in ipairs(wb.general_refs) do
            if wb.general_refs[i]._type == df.general_ref_contains_itemst then
                local stuckitem = df.item.find(wb.general_refs[i].item_id)
                if not stuckitem.flags.in_job then dfhack.items.moveToGround(stuckitem,wb.pos) printv("dumped item out", pos2xyz(wb.pos)) end
                        end
        end
    end
    end
end