Got it working, you need two pieces, the first is the basic check, you need to enable this like you do with projectileExpansion and itemSyndrome (you can just put teleportbase or whatever you call it in the init file)
events = require "plugins.eventful"
events.enableEvent(events.eventType.BUILDING,100)
events.onBuildingCreatedDestroyed.teleport=function(building_id)
bldg = df.building.find(building_id)
if bldg then
all_bldgs = df.global.world.raws.buildings.all
btype = bldg.custom_type
if ((all_bldgs[btype].code == 'TELEPORT_1') or (all_bldgs[btype].code == 'TELEPORT_2')) then
print('placing portal')
pers,status = dfhack.persistent.get('teleport')
if all_bldgs[btype].code == 'TELEPORT_1' then
print('portal 1 placed')
if not pers then
dfhack.persistent.save({key='teleport',value='teleport',ints={bldg.centerx,bldg.centery,bldg.z,-1,-1,-1,-1}})
else
dfhack.persistent.save({key='teleport',ints={bldg.centerx,bldg.centery,bldg.z,pers.ints[4],pers.ints[5],pers.ints[6],-1}})
end
else
print('portal 2 placed')
if not pers then
dfhack.persistent.save({key='teleport',value='teleport',ints={-1,-1,-1,bldg.centerx,bldg.centery,bldg.z,-1}})
else
dfhack.persistent.save({key='teleport',ints={pers.ints[1],pers.ints[2],pers.ints[3],bldg.centerx,bldg.centery,bldg.z,-1}})
end
end
pers,status = dfhack.persistent.get('teleport')
if ((pers.ints[1] > 0) and (pers.ints[4] > 0 )) then
print('portals connected')
dfhack.persistent.save({key='teleport',ints={pers.ints[1],pers.ints[2],pers.ints[3],pers.ints[4],pers.ints[5],pers.ints[6],1}})
else
print('need another portal')
end
else
print('not a portal building')
end
end
end
then the actual teleportation reaction code
args={...}
local unit = df.unit.find(tonumber(args[1]))
local dir = tonumber(args[2])
pers,status = dfhack.persistent.get('teleport')
if pers.ints[7] == 1 then
if dir == 1 then
local unitoccupancy = dfhack.maps.getTileBlock(unit.pos).occupancy[unit.pos.x%16][unit.pos.y%16]
unit.pos.x = pers.ints[1]
unit.pos.y = pers.ints[2]
unit.pos.z = pers.ints[3]
if not unit.flags1.on_ground then unitoccupancy.unit = false else unitoccupancy.unit_grounded = false end
elseif dir == 2 then
local unitoccupancy = dfhack.maps.getTileBlock(unit.pos).occupancy[unit.pos.x%16][unit.pos.y%16]
unit.pos.x = pers.ints[4]
unit.pos.y = pers.ints[5]
unit.pos.z = pers.ints[6]
if not unit.flags1.on_ground then unitoccupancy.unit = false else unitoccupancy.unit_grounded = false end
else
print('not a valid portal imput')
end
else
print('no valid portals')
end
You will need two buildings, the first named TELEPORT_1 and the second named TELEPORT_2, once both are built you will be able to move between them using reactions. (Note those are the id names, not the displayed in game names)
Then all you need to do is make a reaction with [SYN_CLASS:\COMMAND][SYN_CLASS:teleport][SYN_CLASS:\UNIT_ID][SYN_CLASS:direction] where direction is either 1 or 2, 1 means you want to teleport to TELEPORT_1 and 2 means you want to teleport to TELEPORT_2 (so you should give the TELEPORT_1 building a reaction with direction 2 and the TELEPORT_2 building a reaction with direction 1.
EDIT: This hasn't been massively tested so there are probably some bugs in it, but I was able to move across the map in an instant and down several z levels without any problems (obviously your dwarfs won't use these teleports for pathing)