Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Swap adventurer
- local help = [====[
- adv-bodyswap
- ==============
- Swap adventurer with selected (`l`ook) unit
- ]====]
- 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_adv2(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[0]
- other[0]=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
- function change_adv3(unit,nemesis)
- if nemesis==nil then
- nemesis=true --default value is nemesis switch too.
- end
- if unit==nil then
- error("No unit!") --getCreatureAtPointer()--getSelectedUnit()
- end
- if unit==nil then
- error("Invalid unit!")
- end
- local units=df.global.world.units.active
- local unit_indx
- for k,v in pairs(units) 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
- units[unit_indx]=units[0]
- units[0]=unit
- if nemesis then --basicly copied from advtools plugin...
- local old_nem = dfhack.units.getNemesis(units[unit_indx])
- local new_nem=dfhack.units.getNemesis(unit)
- if old_nem==nil or new_nem==nil then
- error("Not have both nemesis")
- end
- if old_nem then
- old_nem.flags[0]=false -- No more adventurer
- old_nem.flags[1]=true -- However, retired adventurer
- end
- if new_nem then
- new_nem.flags[0]=true -- Now current adventurer
- new_nem.flags[1]=false -- Now more considered as retired
- new_nem.flags[2]=true -- Now is adventurer in legends
- -- Now change player
- for k,v in pairs(df.global.world.nemesis.all) do
- if v.id==new_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
- local other_unit = dfhack.gui.getSelectedUnit()
- change_adv3(other_unit, true)
Add Comment
Please, Sign In to add comment