1
Utilities and 3rd Party Applications / Re: Monotheism script
« on: February 05, 2024, 07:23:59 pm »
Any plans to update this script for the Steam version?
March 6, 2024: Dwarf Fortress 50.12 has been released.
News: February 3, 2024: The February '24 Report is up.
News: February 4, 2021: Dwarf Fortress Talk #28 has been posted.
News: November 21, 2018: A new Threetoe story has been posted.
Forum Guidelines
I would guess that this is because you are on a very outdated version, 0.43.05 rather than 0.44.12.
...0 (43.05) 64x\Dwarf Fortress/hack/scripts/DEITY_GIFT.lua:197: attempt to index a nil value (field 'history_event_artifact_givenst')
stack traceback:
...0 (43.05) 64x\Dwarf Fortress/hack/scripts/DEITY_GIFT.lua:197: in local 'script_code'
...ork V1.30 (43.05) 64x\Dwarf Fortress\hack\lua\dfhack.lua:562: in function 'dfhack.run_script_with_env'
local gift = df.history_event_artifact_givenst:new()
----------------------------------------------------
-- VARIABLES
----------------------------------------------------
-- Material the slab will be made from
local material = "INORGANIC:MITHRIL"
-- Full name of the secret you want the slab to contain
local secret_type = "the secrets of the light"
-- Full name of the slab as recorded in Legends
local slab_artifact_name = "Blessing of Liral's Divine Fire"
-- Description of the slab
local slab_descritpion = 'The secrets of the light'
-- Full name of the deity that creates the artifact
local deity_name = "Liral"
-- Full name of the person receiving the artifact
local worshipper_name = "Istra Twinklingeye"
----------------------------------------------------
-- FUNCTIONS
----------------------------------------------------
-- Looking for deity's historical figure's id
function getDeityHFID(deity_name)
local deity_id = ""
for _,fig in ipairs(df.global.world.history.figures) do
if fig.flags.deity and (tostring (dfhack.TranslateName(fig.name, true))) == deity_name then
--print("Found deity " .. deity_name)
deity_id = fig.id
--print ("Deity's historical figure id: " .. tostring(deity_id))
break
end
end
return deity_id
end
-- Looking for worshippers's historical figure's id
function getWorshipperHFID(worshipper_name)
local worshipper_id = ""
for _,fig in ipairs(df.global.world.history.figures) do
if tostring (dfhack.TranslateName(fig.name, true)) == worshipper_name then
--print("Found worshipper " .. worshipper_name)
worshipper_id = fig.id
--print ("Worshipper's historical figure id: " .. tostring(worshipper_id))
break
end
end
return worshipper_id
end
-- Looking for the secret's ID
function getSecretId(secret_type)
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_type then
return i.id
end
end
end
end
end
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
-- Checks if the spot to place the slab in-game (mouse cursor's location) is valid
local pos = copyall(df.global.cursor)
if pos.x <0 then
print ("Invalid slab placement.")
end
-- Checks if the slab's material is valid
local m = dfhack.matinfo.find(material)
if not m then
print ("Invalid material.")
end
-- Creates the slab as an item in-game
local slab = df.item_slabst:new()
slab.id = df.global.item_next_id
df.global.world.items.all:insert("#",slab)
df.global.item_next_id = df.global.item_next_id+1
slab:setMaterial(m["type"])
slab:setMaterialIndex(m["index"])
slab:categorize(true)
slab.flags.removed = true
slab:setSharpness(0,0)
slab:setQuality(0)
slab.engraving_type = 6
slab.topic = getSecretId(secret_type)
slab.description = tostring(slab_description)
print("Created item")
-- Places the slab on the chosen spot (mouse cursor's location)
dfhack.items.moveToGround(slab,{x=pos.x,y=pos.y,z=pos.z})
print("Placed item")
-- Adds the slab as an artifact in Legends
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 = slab
a.name.first_name = slab_artifact_name
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)
print("Added artifact to Legends")
-- Adds artifact ref
local ref = df.general_ref_is_artifactst:new()
ref.artifact_id = a.id
slab.general_refs:insert("#",ref)
df.global.world.items.other.ANY_ARTIFACT:insert("#",slab)
print("Added artifact ref")
-- Adds an event of the slab's creation in Legends
local creation = df.history_event_artifact_createdst:new()
creation.year = df.global.cur_year
creation.seconds = df.global.cur_year_tick
creation.id = df.global.hist_event_next_id
creation.artifact_id = a.id
creation.hfid = getDeityHFID(deity_name)
df.global.world.history.events:insert("#",creation)
df.global.hist_event_next_id = df.global.hist_event_next_id+1
print("Added creation event to Legends")
----------------------------------------------------
-- STUFF DOESN'T WORK PAST THIS POINT
----------------------------------------------------
-- Adds an event of deity giving the slab to the adventurer
local gift = df.history_event_artifact_givenst:new()
gift.year = df.global.cur_year
gift.seconds = df.global.cur_year_tick
gift.id = df.global.hist_event_next_id
gift.artifact_id = a.id
gift.giver_hf = getDeityHFID(deity_name)
gift.receiver_hf = getWorshipperHFID(worshipper_name)
df.global.world.history.events:insert("#",gift)
df.global.hist_event_next_id = df.global.hist_event_next_id+1
print("Added gift event to Legends")
For the record, if your adventurer is currently loaded in in adventure mode, you can find their hist figure with df.historical_figure.find(df.global.world.units.active[0].hist_figure_id).
it's different from spouses, mostly, it's all stored in hist figure info, you can check a look at that for assistance
-- This script makes a historical figure worship the chosen deity
local deity_name = "Liral"
local worshipper_name = "Istra Twinklingeye"
local deity_id = ""
local worshipper_id = ""
local worshipper = nil
-- Looking for the deity historical figure
for _,fig in ipairs(df.global.world.history.figures) do
if fig.flags.deity and (tostring (dfhack.TranslateName(fig.name, true))) == deity_name then
print("Found deity " .. deity_name)
deity_id = fig.id
print ("Deity's historical figure id: " .. tostring(deity_id))
break
end
end
-- Looking for the worshipper historical figure
for _,fig in ipairs(df.global.world.history.figures) do
if (tostring (dfhack.TranslateName(fig.name, true))) == worshipper_name then
print("Found worshipper " .. worshipper_name)
worshipper_id = fig.id
worshipper = fig
print ("Worshipper's historical figure id: " .. tostring(worshipper_id))
break
end
end
-- Creating deity link
local deity_link = df.histfig_hf_link_deityst:new()
deity_link.target_hf = deity_id
deity_link.link_strength = 100
worshipper.histfig_links:insert('#', deity_link)
print(worshipper_name .. " is now a worshipper of " .. deity_name)