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/cposchange"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(Fix display)
m (forgot to remove comment about code tag)
Line 1: Line 1:
Save as cposchange.lua into /hack/scripts folder (sorry about the code tag eating spacing and linebreaks):
+
Save as cposchange.lua into /hack/scripts folder:
  
 
<pre>
 
<pre>

Revision as of 13:52, 17 August 2018

Save as cposchange.lua into /hack/scripts folder:

--[==[Waits for a cart to move (or return with flip) and pauses --]==]
local args = {...}
local cart = dfhack.gui.getSelectedItem()
local flip = false
if #args>0 and args[1]=="flip" then 
flip = true
else
flip = false
end
function rwait(nr,minecart, cx, cy, cz)
	dfhack.timeout(1, "ticks", 
	function()  
		if((minecart.pos.x == cx) and (minecart.pos.y == cy) and (minecart.pos.z == cz)) then 
			dfhack.run_command('fpause') print("Minecart " .. minecart.vehicle_id .. " moved back into " .. cx .. " " .. cy .. " " .. cz .. " in " .. (df.global.cur_year_tick-nr) .. " steps.") 
		else rwait(nr, minecart, cx, cy, cz) end 
	end )
end 

function fwait(nr,minecart, cx, cy, cz)
	dfhack.timeout(1, "ticks", 
	function()  
		if((minecart.pos.x ~= cx) or (minecart.pos.y ~= cy) or (minecart.pos.z ~= cz)) then 
			rwait(nr, minecart, cx, cy, cz)
		else fwait(nr, minecart, cx, cy, cz) end 
	end )
end

function mwait(nr,minecart, cx, cy, cz)
	dfhack.timeout(1, "ticks", 
	function()  
		if((minecart.pos.x ~= cx) or (minecart.pos.y ~= cy) or (minecart.pos.z ~= cz)) then 
			dfhack.run_command('fpause') print("Minecart " .. minecart.vehicle_id .. " moved in " .. (df.global.cur_year_tick-nr) .. " steps.") 
		else mwait(nr, minecart, cx, cy, cz) end 
	end )
end 

if flip then
fwait(df.global.cur_year_tick,cart, (cart.pos.x +1 -1), (cart.pos.y +1 -1), (cart.pos.z +1 -1))
else 
mwait(df.global.cur_year_tick,cart, (cart.pos.x +1 -1), (cart.pos.y +1 -1), (cart.pos.z +1 -1))
end