it's a modified select adventure bodyswap to align a unit to the Comfort.lua script
This file contains 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
function getxyz() -- this will return pointers x,y and z coordinates. | |
local x=df.global.cursor.x | |
local y=df.global.cursor.y | |
local z=df.global.cursor.z | |
return x,y,z -- return the coords | |
end | |
function getCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord | |
--local x,y,z=getxyz() --get 'X' coords | |
local vector=df.global.world.units.all -- load all creatures | |
for i = 0, #vector-1 do -- look into all creatures offsets | |
local curpos=vector[i].pos --get its coordinates | |
local cx=curpos.x | |
local cy=curpos.y | |
local cz=curpos.z | |
if cx==x and cy==y and cz==z then --compare them | |
return vector[i] --return index | |
end | |
end | |
--print("Creature not found!") | |
return nil | |
end | |
function change_adv(unit,nemesis) | |
if nemesis==nil then | |
nemesis=true --default value is nemesis switch too. | |
end | |
if unit==nil then | |
unit=getCreatureAtPos(getxyz()) --getCreatureAtPointer()--getSelectedUnit() | |
end | |
if unit==nil then | |
error("Invalid unit!") | |
end | |
local other=df.global.world.units.active | |
local unit_indx | |
for k,v in pairs(other) do | |
if v==unit then | |
unit_indx=k | |
break | |
end | |
end | |
if unit_indx==nil then | |
error("Unit not found in array?!") --should not happen | |
end | |
other[unit_indx]=other[2] | |
other[2]=unit | |
if nemesis then --basicly copied from advtools plugin... | |
local nem=dfhack.units.getNemesis(unit) | |
local other_nem=dfhack.units.getNemesis(other[unit_indx]) | |
if other_nem then | |
other_nem.flags[0]=false | |
other_nem.flags[1]=true | |
end | |
if nem then | |
nem.flags[0]=true | |
nem.flags[2]=true | |
for k,v in pairs(df.global.world.nemesis.all) do | |
if v.id==nem.id then | |
df.global.ui_advmode.player_id=k | |
end | |
end | |
else | |
qerror("Current unit does not have nemesis record, further working not guaranteed") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment