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
(Initial writeup)
 
m (pre to source lang lua)
Line 3: Line 3:
 
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.
  
<pre>
+
<source lang="lua">
 
--empties wheelbarrows of stuck stones
 
--empties wheelbarrows of stuck stones
  
Line 32: Line 32:
 
end
 
end
 
end
 
end
</pre>
+
</source>

Revision as of 00:53, 4 July 2019

Save aswheelbarrow-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