-
-
Save Putnam3145/7243759 to your computer and use it in GitHub Desktop.
local function teleport(unit,pos) | |
local unitoccupancy = dfhack.maps.getTileBlock(unit.pos).occupancy[unit.pos.x%16][unit.pos.y%16] | |
unit.pos.x = pos.x | |
unit.pos.y = pos.y | |
unit.pos.z = pos.z | |
if not unit.flags1.on_ground then unitoccupancy.unit = false else unitoccupancy.unit_grounded = false end | |
end | |
local function getArgsTogether(args) | |
local settings={ | |
pos={}} | |
for k,v in ipairs(args) do | |
v=string.lower(v) | |
if v=="unit" then settings.unitID=tonumber(args[k+1]) end | |
if v=="x" then settings.pos['x']==tonumber(args[k+1]) end | |
if v=="y" then settings.pos['y']==tonumber(args[k+1]) end | |
if v=="z" then settings.pos['z']==tonumber(args[k+1]) end | |
if v=="showunitid" then print(dfhack.gui.getSelectedUnit(true).id) end | |
if v=="showpos" then printall(df.global.cursor) end | |
end | |
if not settings.pos.x or not settings.pos.y or not settings.pos.z then settings.pos=nil end | |
if not settings.unitID and not settings.pos.x then qerror("Needs a position, a unit ID or both, but not neither!") end | |
return settings | |
end | |
local args = {...} | |
local teleportSettings=getArgsTogether(args) | |
local unit = teleportSettings.unitID and df.unit.find(teleportSettings.unitID) or dfhack.gui.getSelectedUnit(true) | |
local pos = teleportSettings.pos and teleportSettings.pos or df.global.cursor | |
teleport(unit,pos) |
I'd like to point out, playing in the most up to date version of the Lazy Noob Pack, I had to run
teleport -showunitid
and then
teleport -unit [result from -showunitid]
The documentation is not very useful and needs to be improved.
@draeath
You can't possibly be using this exact script, because this has several syntax errors that would make it unusable with any DFHack version (you wouldn't even get to the error you were seeing).
@Djent- there is somewhat-improved documentation at http://dfhack.readthedocs.io/en/latest/docs/_auto/base.html#teleport now.
If there continue to be issues with the teleport.lua script that's included in the most recent DFHack release (currently 0.43.03-r1), please open an issue at https://github.com/DFHack/dfhack. Thanks!
Also, you can find the current teleport script in the DFHack/scripts repo: https://github.com/DFHack/scripts/blob/master/teleport.lua (and you can suggest changes the documentation there).
The way to use it is as follows. On DFHack window type, with the cursor on the unit in Dwarf Forttress
teleport -showunitid
It will display the unit id number say it is 9955.
Now in Dwarf fortress move the cursor to a safe new position and now type in DFHack
teleport 9955
this should save your Drowning Dwarf :-)