You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A revived version of the long defunct "adv-bodyswap" with added functionality.
This script allows the player to swap their control over to any unit present on the map in adventure mode only. Targets are specified either via their unit id or through UI selection prior to running the script. Unlike previous iterations, units lacking nemesis or historical figure data (such as wild animals) are valid and safe targets, as the script creates this data when it is missing.
-- Shifts player control over to another unit in adventure mode.
2
+
-- author: Atomic Chicken
3
+
-- based on "assumecontrol.lua" by maxthyme, as well as the defunct advtools plugin "adv-bodyswap"
4
+
-- nemesis and historical figure creation uses slightly modified functions from modtools/create-unit
5
+
6
+
--[====[
7
+
8
+
bodyswap
9
+
========
10
+
11
+
Shifts player control over to another unit (including wild animals) in adventure mode.
12
+
Usage:
13
+
14
+
:bodyswap:
15
+
Swaps into the unit selected in the UI (for example, when viewing the unit's status screen or description).
16
+
17
+
:bodyswap -unit [unitId]:
18
+
Swaps into the unit corresponding to the specified id.
19
+
20
+
]====]
21
+
22
+
localutils=require'utils'
23
+
validArgs=validArgsorutils.invert({
24
+
'unit',
25
+
'help'
26
+
})
27
+
localargs=utils.processArgs({...}, validArgs)
28
+
29
+
localusage=[====[
30
+
31
+
bodyswap
32
+
========
33
+
This script allows the player to gain control over a new unit in adventurer mode
34
+
whilst simultaneously loosing control over their current character.
35
+
36
+
To specify the target unit, simply select it in the user interface,
37
+
such as by opening the unit's status screen or viewing its description
38
+
and enter "bodyswap" in the DFHack console.
39
+
40
+
Alternatively, the target unit can be specified by its unit id as shown below.
41
+
42
+
Arguments::
43
+
44
+
-unit id
45
+
replace "id" with the unit id of your target
46
+
example:
47
+
bodyswap -unit 42
48
+
49
+
]====]
50
+
51
+
ifargs.helpthen
52
+
print(usage)
53
+
return
54
+
end
55
+
56
+
ifnotdfhack.world.isAdventureMode() then
57
+
qerror("This script can only be used in adventure mode!")
58
+
end
59
+
60
+
functionsetNewAdvNemFlags(nem)
61
+
nem.flags.ACTIVE_ADVENTURER=true
62
+
nem.flags.RETIRED_ADVENTURER=false
63
+
nem.flags.ADVENTURER=true
64
+
end
65
+
functionsetOldAdvNemFlags(nem)
66
+
nem.flags.ACTIVE_ADVENTURER=false
67
+
nem.flags.RETIRED_ADVENTURER=true
68
+
nem.unit.idle_area.x=nem.unit.pos.x
69
+
nem.unit.idle_area.y=nem.unit.pos.y
70
+
nem.unit.idle_area.z=nem.unit.pos.z
71
+
end
72
+
73
+
functionclearNemesisFromSite(nem)
74
+
-- this is a workaround for a bug which tends to cause duplication of the unit entry in df.global.world.units.active when the site to which a historical figure is linked is reloaded with the unit present
75
+
-- appears to fix the problem without causing any noticeable issues
76
+
ifnotnem.figurethen
77
+
return
78
+
end
79
+
for_,linkinipairs(nem.figure.site_links) do
80
+
localsite=df.world_site.find(link.site)
81
+
fori=#site.unk_1.nemesis-1,0,-1do
82
+
ifsite.unk_1.nemesis[i] ==nem.idthen
83
+
site.unk_1.nemesis:erase(i)
84
+
end
85
+
end
86
+
end
87
+
end
88
+
89
+
functionswapAdvUnit()
90
+
91
+
localnewUnit
92
+
ifargs.unitthen
93
+
newUnit=df.unit.find(tonumber(args.unit))
94
+
else
95
+
newUnit=dfhack.gui.getSelectedUnit()
96
+
end
97
+
ifnotnewUnitthen
98
+
print("Enter the following if you require assistance: bodyswap -help")
0 commit comments