Created
October 31, 2013 02:58
-
-
Save Putnam3145/7243759 to your computer and use it in GitHub Desktop.
Lets you teleport units; syntax is: number after unit is unit id, number after x,y,z is related position number, showunitid will show unit under cursor's ID, showpos will show position under cursor. Just a unit or just a position can be supplied; if either is the case, the cursor will be used to determine what the remaining variable is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
@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).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.