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
m (.pause_state instead of run_command('fpause'))
m (pre to source lang lua)
 
Line 1: Line 1:
 
Save as cposchange.lua into /hack/scripts folder:
 
Save as cposchange.lua into /hack/scripts folder:
  
<pre>
+
<source lang="lua">
 
--[==[Waits for a cart to move (or return with flip) and pauses --]==]
 
--[==[Waits for a cart to move (or return with flip) and pauses --]==]
 
local args = {...}
 
local args = {...}
Line 43: Line 43:
 
mwait(df.global.cur_year_tick,cart, (cart.pos.x +1 -1), (cart.pos.y +1 -1), (cart.pos.z +1 -1))
 
mwait(df.global.cur_year_tick,cart, (cart.pos.x +1 -1), (cart.pos.y +1 -1), (cart.pos.z +1 -1))
 
end
 
end
</pre>
+
</source>

Latest revision as of 00:54, 4 July 2019

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 
			df.global.pause_state = true 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 
			df.global.pause_state = true 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