Ok, this should work.
--rejuvenate the spouse of the current monarch
--[[=begin
rejuvenate-monarch-spouse
============
Make the monarch-spouse 20 years old and have at least 100 years of life.
=end]]
-- set debug_flag to 1 to get more details and/or if things don't work
local debug_flag = 0
local unit=dfhack.gui.getSelectedUnit()
if not unit then qerror("No unit selected") end
local my_civ_id=df.historical_entity.find(df.global.ui.civ_id)
local monarch_pos_id
for k,v in pairs(my_civ_id.positions.own) do
if v.code=="MONARCH" then
monarch_pos_id=v.id
break
end
end
if not monarch_pos_id then qerror("No monarch position found!") end
local monarch_id
local monarch_spouse
for pos_id,v in pairs(my_civ_id.positions.assignments) do
if v.position_id==monarch_pos_id then
monarch_id=v.histfig
local current_monarch=df.historical_figure.find(monarch_id)
monarch_spouse = df.historical_figure.find(current_monarch.histfig_links[1].target_hf)
-- now we have a monarch, and a monarch spouse, ideally.
-- print out a bunch of information if this doesn't work and the flag is set.
if debug_flag == 1 then
print("..monarch data")
print(current_monarch)
print("..monarch data fields")
printall(current_monarch)
print("..monarch entity_links")
printall_ipairs(current_monarch.entity_links)
print("..monarch histfig_links")
printall_ipairs(current_monarch.histfig_links)
print("..monarch links")
printall(current_monarch.histfig_links[1])
print("..monarch spouse")
print(current_monarch.histfig_links[1].target_hf)
end
if debug_flag == 1 then
print("..monarch_spouse data")
print(monarch_spouse)
print("..monarch_spouse data fields")
printall(monarch_spouse)
print("..monarch_spouse entity_links")
printall_ipairs(monarch_spouse.entity_links)
print("..monarch_spouse histfig_links")
printall_ipairs(monarch_spouse.histfig_links)
print("..monarch_spouse links")
printall(monarch_spouse.histfig_links[1])
print("..monarch_spouse spouse")
print(monarch_spouse.histfig_links[1].target_hf)
end
-- now print out the monarch and spouse names
print("Monarch name is: "..dfhack.TranslateName(current_monarch.name))
if debug_flag == 1 then
print("Monarch id is: "..current_monarch.id)
end
print("Monarch spouse name is: "..dfhack.TranslateName(monarch_spouse.name))
if debug_flag == 1 then
print("Monarch spouse id is: "..monarch_spouse.id)
end
-- the monarch_spouse is all we need to rejuvenate them, so let's try to do that now
local current_year,newbirthyear
current_year=df.global.cur_year
if debug_flag == 1 then
print("Current in-game year is: "..current_year)
end
if monarch_spouse.died_year ~= -1 then
print("The monarch spouse is dead. (died in "..monarch_spouse.died_year..") Nothing more to do now but weep.")
break
end
newbirthyear=current_year - 20
if monarch_spouse.born_year < newbirthyear then
monarch_spouse.born_year=newbirthyear
end
if monarch_spouse.old_year < current_year+100 then
monarch_spouse.old_year=current_year+100
end
print (dfhack.TranslateName(monarch_spouse.name).." is now 20 years old and will live at least 100 years")
break
end
end
If not, set the Debug flag to 1 and paste the output from dfhack into a reply here.
Usage is: just target a dwarf in the civ of the monarch in question, and then run the script in dfhack. put the script into /hack/scripts/
I'm not certain this is going to work, I'm just setting the correct historical figure values and hoping it will work when that figure appears at the fortress. Try it out, Corthalas, and let me know. (Obviously, use a backup!)
You are the hero we need, vjek!
Thank you so much! That seems to have worked.
€dit: He was killed in a goblin siege, the mountainhome was lost
The monarch spouse is the immortal one, it's just the king that dies, thus preventing any chance of the monarch spouse migrating to my fortress. So I only used the current_monarch you found out, here is the result:
--rejuvenate the current monarch
--[[=begin
rejuvenate-monarch-spouse
============
Make the monarch 20 years old and have at least 100 years of life.
=end]]
-- set debug_flag to 1 to get more details and/or if things don't work
local debug_flag = 1
local unit=dfhack.gui.getSelectedUnit()
if not unit then qerror("No unit selected") end
local my_civ_id=df.historical_entity.find(df.global.ui.civ_id)
local monarch_pos_id
for k,v in pairs(my_civ_id.positions.own) do
if v.code=="MONARCH" then
monarch_pos_id=v.id
break
end
end
if not monarch_pos_id then qerror("No monarch position found!") end
local monarch_id
local monarch_spouse
for pos_id,v in pairs(my_civ_id.positions.assignments) do
if v.position_id==monarch_pos_id then
monarch_id=v.histfig
local current_monarch=df.historical_figure.find(monarch_id)
monarch_spouse = df.historical_figure.find(current_monarch.histfig_links[1].target_hf)
-- now we have a monarch, and a monarch spouse, ideally.
-- print out a bunch of information if this doesn't work and the flag is set.
if debug_flag == 1 then
print("..monarch data")
print(current_monarch)
print("..monarch data fields")
printall(current_monarch)
print("..monarch entity_links")
printall_ipairs(current_monarch.entity_links)
print("..monarch histfig_links")
printall_ipairs(current_monarch.histfig_links)
print("..monarch links")
printall(current_monarch.histfig_links[1])
print("..monarch spouse")
print(current_monarch.histfig_links[1].target_hf)
end
if debug_flag == 1 then
print("..monarch_spouse data")
print(monarch_spouse)
print("..monarch_spouse data fields")
printall(monarch_spouse)
print("..monarch_spouse entity_links")
printall_ipairs(monarch_spouse.entity_links)
print("..monarch_spouse histfig_links")
printall_ipairs(monarch_spouse.histfig_links)
print("..monarch_spouse links")
printall(monarch_spouse.histfig_links[1])
print("..monarch_spouse spouse")
print(monarch_spouse.histfig_links[1].target_hf)
end
-- now print out the monarch and spouse names
print("Monarch name is: "..dfhack.TranslateName(current_monarch.name))
if debug_flag == 1 then
print("Monarch id is: "..current_monarch.id)
end
print("Monarch spouse name is: "..dfhack.TranslateName(monarch_spouse.name))
if debug_flag == 1 then
print("Monarch spouse id is: "..monarch_spouse.id)
end
-- the current_monarch is all we need to rejuvenate them, so let's try to do that now
local current_year,newbirthyear
current_year=df.global.cur_year
if debug_flag == 1 then
print("Current in-game year is: "..current_year)
end
if current_monarch.died_year ~= -1 then
print("The monarch is dead. (died in "..current_monarch.died_year..") Nothing more to do now but weep.")
break
end
newbirthyear=current_year - 20
if current_monarch.born_year < newbirthyear then
current_monarch.born_year=newbirthyear
end
if current_monarch.old_year < current_year+100 then
current_monarch.old_year=current_year+100
end
print (dfhack.TranslateName(current_monarch.name).." is now 20 years old and will live at least 100 years")
break
end
end
Warning: Plugin automaterial compiled for DFHack 0.42.06-alpha2-0-g6fd904f, running DFHack 0.42.06-alpha1-10-g6fd904f
Warning: Plugin mousequery compiled for DFHack 0.42.06-alpha2-0-g6fd904f, running DFHack 0.42.06-alpha1-10-g6fd904f
Warning: Plugin resume compiled for DFHack 0.42.06-alpha2-0-g6fd904f, running DFHack 0.42.06-alpha1-10-g6fd904f
Warning: Plugin twbt compiled for DFHack 0.42.06-alpha2-0-g6fd904f, running DFHack 0.42.06-alpha1-10-g6fd904f
TWBT: version 5.58
reshape_graphics
reshape_graphics
reshape_graphics
DFHack is ready. Have a nice day!
DFHack version 0.42.06-alpha2 (development build 0.42.06-alpha1-10-g6fd904f)
Type in '?' or 'help' for general help, 'ls' to see all commands.
This is a prerelease build of DFHack. Some structures are likely
to be incorrect, resulting in crashes or save corruption
Make backups of your saves often!
Autonestbox stopped.
unstuck 0 doors
reshape_graphics
[DFHack]# rejuvenate-monarch
..monarch data
<historical_figure: 0x37bddc58>
..monarch data fields
profession = 126
race = 572
caste = 1
sex = 1
orientation_flags = <orientation_flags: 0x37bddc60>
appeared_year = 1
born_year = -70
born_seconds = -1
curse_year = -1
curse_seconds = -1
birth_year_bias = 0
birth_time_bias = 0
old_year = 90
old_seconds = 379591
died_year = -1
died_seconds = -1
name = <language_name: 0x37bddc90>
civ_id = 237
population_id = 227
breed_id = -1
cultural_identity = 35
flags = <BitArray<>: 0x37bddd0c>
unit_id = 581
unit_id2 = 581
id = 458
unk4 = 0
entity_links = <vector<histfig_entity_link*>: 0x37bddd24>
site_links = <vector<histfig_site_link*>: 0x37bddd34>
histfig_links = <vector<histfig_hf_link*>: 0x37bddd44>
info = <historical_figure_info: 0x37b59828>
worldgen = <historical_figure.T_worldgen: 0x37bddd58>
unk_v4019_1 = -1
..monarch entity_links
0 = <histfig_entity_link_memberst: 0x37c18f48>
1 = <histfig_entity_link_memberst: 0x37c18f90>
2 = <histfig_entity_link_positionst: 0x373f5678>
..monarch histfig_links
0 = <histfig_hf_link_deityst: 0x37c18d38>
1 = <histfig_hf_link_spousest: 0x37c18cf0>
2 = <histfig_hf_link_childst: 0x37c18db0>
3 = <histfig_hf_link_childst: 0x37c18f00>
4 = <histfig_hf_link_childst: 0x37c18dc8>
5 = <histfig_hf_link_childst: 0x37c18d20>
6 = <histfig_hf_link_childst: 0x37c18f18>
7 = <histfig_hf_link_childst: 0x37c18ea0>
8 = <histfig_hf_link_childst: 0x37c18de0>
9 = <histfig_hf_link_childst: 0x37c18df8>
10 = <histfig_hf_link_childst: 0x37c18eb8>
..monarch links
target_hf = 462
link_strength = 100
..monarch spouse
462
..monarch_spouse data
<historical_figure: 0x37bdc788>
..monarch_spouse data fields
profession = 102
race = 572
caste = 0
sex = 0
orientation_flags = <orientation_flags: 0x37bdc790>
appeared_year = 1
born_year = -63
born_seconds = -1
curse_year = 83
curse_seconds = -1
birth_year_bias = 0
birth_time_bias = 0
old_year = 99
old_seconds = 252318
died_year = -1
died_seconds = -1
name = <language_name: 0x37bdc7c0>
civ_id = 237
population_id = 227
breed_id = -1
cultural_identity = 35
flags = <BitArray<>: 0x37bdc83c>
unit_id = 579
unit_id2 = 579
id = 462
unk4 = 0
entity_links = <vector<histfig_entity_link*>: 0x37bdc854>
site_links = <vector<histfig_site_link*>: 0x37bdc864>
histfig_links = <vector<histfig_hf_link*>: 0x37bdc874>
info = <historical_figure_info: 0x37b592a8>
worldgen = <historical_figure.T_worldgen: 0x37bdc888>
unk_v4019_1 = -1
..monarch_spouse entity_links
0 = <histfig_entity_link_memberst: 0x37c19350>
1 = <histfig_entity_link_memberst: 0x37c19860>
..monarch_spouse histfig_links
0 = <histfig_hf_link_deityst: 0x37c19698>
1 = <histfig_hf_link_spousest: 0x37c196b0>
2 = <histfig_hf_link_childst: 0x37c19878>
3 = <histfig_hf_link_childst: 0x37c195d8>
4 = <histfig_hf_link_childst: 0x37c196c8>
5 = <histfig_hf_link_childst: 0x37c19650>
6 = <histfig_hf_link_childst: 0x37c19758>
7 = <histfig_hf_link_childst: 0x37c19710>
8 = <histfig_hf_link_childst: 0x37c195f0>
9 = <histfig_hf_link_childst: 0x37c19740>
10 = <histfig_hf_link_childst: 0x37c198a8>
11 = <histfig_hf_link_apprenticest: 0x37c198c0>
..monarch_spouse links
target_hf = 458
link_strength = 100
..monarch_spouse spouse
458
Monarch name is: Nomal Ostukkol
Monarch id is: 458
Monarch spouse name is: Rimtar Lertethrig̣th
Monarch spouse id is: 462
Current in-game year is: 90
Nomal Ostukkol is now 20 years old and will live at least 100 years
[DFHack]#
Now it remains to be seen if the friendly necromancer arrives with the king and what she does.