Thanks to AtomicChicken and janxious (as well as u/qeveren) I'm able to spawn in books with the secrets of life and death via DFHack
(see below). My world has 5 slabs, so I'm assuming 5 strains of necromancy. Is there any way to specify which strain a book will impart? I'm assuming the function getSecretId(secret) section needs to change but I have no idea where to start. Thanks!
--Author: Atomic Chicken
--Version: 0.43.05
--------------------------------------------------------------
--edit the following as desired:
--book material:
local material = 'INORGANIC:SILVER'
--book title:
local title = 'The Necronomicon'
--secret conveyed by the book (must use the IS_NAME of the secret)
local secret = 'the secrets of life and death'
--changing the following to false will make the book be treated as a copy:
local artifact = true
--------------------------------------------------------------
function getSecretId(secret)
for _,i in ipairs(df.global.world.raws.interactions) do
for _,is in ipairs (i.sources) do
if getmetatable(is) == 'interaction_source_secretst' then
if is.name == secret then
return i.id
end
end
end
end
end
function createWriting(title,secret)
local w = df.written_content:new()
w.id = df.global.written_content_next_id
w.title = title
w.page_start = 1
w.page_end = 42--number of pages
w.styles:insert('#',7)--(forceful)
w.style_strength:insert('#',0)--'the writing drives forward relentlessly'
— w.anon_3 = 50--'the prose is masterful'
local ref = df.general_ref_interactionst:new()
ref.interaction_id = getSecretId(secret)
ref.source_id = 0
ref.unk_08 = -1
ref.unk_0c = -1
w.refs:insert('#',ref)
w.ref_aux:insert('#',0)
df.global.written_content_next_id = df.global.written_content_next_id+1
df.global.world.written_contents.all:insert('#',w)
return w.id
end
local pos = copyall(df.global.cursor)
if pos.x <0 then
error('Please place the cursor wherever you want to spawn the book.')
end
local m = dfhack.matinfo.find(material)
if not m then
error('Invalid material.')
end
local book = df.item_bookst:new()
book.id = df.global.item_next_id
df.global.world.items.all:insert('#',book)
df.global.item_next_id = df.global.item_next_id+1
book:setMaterial(m['type'])
book:setMaterialIndex(m['index'])
book:categorize(true)
book.flags.removed = true
book:setSharpness(0,0)
book:setQuality(0)
book.title = title
local imp = df.itemimprovement_pagesst:new()
imp.mat_type = m['type']
imp.mat_index = m['index']
imp.count = 42--number of pages
imp.contents:insert('#',createWriting(title,secret))
book.improvements:insert('#',imp)
book.flags2.unk_book = true
if artifact == true then
local a = df.artifact_record:new()
a.id = df.global.artifact_next_id
df.global.artifact_next_id = df.global.artifact_next_id+1
a.item = book
a.name.first_name = title
a.name.has_name = true
a.flags:assign(df.global.world.artifacts.all[0].flags)
a.anon_1 = -1000000
a.anon_2 = -1000000
a.anon_3 = -1000000
df.global.world.artifacts.all:insert('#',a)
local ref = df.general_ref_is_artifactst:new()
ref.artifact_id = a.id
book.general_refs:insert('#',ref)
df.global.world.items.other.ANY_ARTIFACT:insert('#',book)
local e = df.history_event_artifact_createdst:new()
e.year = df.global.cur_year
e.seconds = df.global.cur_year_tick
e.id = df.global.hist_event_next_id
e.artifact_id = a.id
df.global.world.history.events:insert('#',e)
df.global.hist_event_next_id = df.global.hist_event_next_id+1
end
dfhack.items.moveToGround(book,{x=pos.x,y=pos.y,z=pos.z})