And as usual I still don't have an answer to how to I make an item like sword into an artifact with it's own name? Please I need help here. I asked this a few pages ago.
Since then I now also need answers to how do I turn my character into a necromancer with DFhack? As I don't have any necromancer towers whatsoever and I'm missing out a part of the game here because of it.
I actually have a partial explanation for this. I recently needed to write a script to turn things into artifacts, and it looks like this:
function findImage(id, subid)
local result = nil
for _,i in ipairs(df.global.world.art_image_chunks) do
if i.id == id then
result = i.images[subid]
end
end
return result
end
local item = dfhack.gui.getSelectedItem()
if not item then
print("No item selected")
else
local already_artifact = false
for i,v in ipairs(item.general_refs) do if df.general_ref_is_artifactst:is_instance(v) then already_artifact = true end end
if already_artifact then
print("Already an artifact")
else
local artifact_record = df.artifact_record:new()
local artifact_ref = df.general_ref_is_artifactst:new()
local history_event = df.history_event_artifact_createdst:new()
artifact_record.id = df.global.artifact_next_id
artifact_record.item = item
artifact_record.anon_1 = -1000000
artifact_record.anon_2 = -1000000
artifact_record.anon_3 = -1000000
artifact_ref.artifact_id = artifact_record.id
item.flags.artifact = true
item.flags.artifact_mood = true
item:setQuality(5)
for _,v in ipairs(item.improvements) do
v.quality = 5
end
if item.masterpiece_event == -1 then
history_event.year = df.global.cur_year
history_event.seconds = df.global.cur_year_tick_advmode
else
local masterpiece_event = df.global.world.history.events[item.masterpiece_event]
history_event.year = masterpiece_event.year
history_event.seconds = masterpiece_event.seconds
end
history_event.id = df.global.hist_event_next_id
history_event.artifact_id = artifact_record.id
history_event.hfid = item.maker
history_event.unit_id = df.historical_figure.find(item.maker).unit_id
history_event.site = df.global.world.world_data.active_site[0].id
item.general_refs:insert('#', artifact_ref)
df.global.world.artifacts.all:insert('#', artifact_record)
df.global.artifact_next_id = artifact_record.id + 1
df.global.world.history.events:insert('#', history_event)
df.global.hist_event_next_id = df.global.hist_event_next_id + 1
-- Look for a name
local named_image = nil
if df.item_figurinest:is_instance(item) then
print("is figurine")
local image = findImage(item.image.id, item.image.subid)
print("found image") print(image)
if image and image.name.has_name then
print("set name")
named_image = image
end
end
if not named_image then
for _,i in ipairs(item.improvements) do
if df.itemimprovement_art_imagest:is_instance(i)
or df.itemimprovement_illustrationst:is_instance(i)
or df.itemimprovement_sewn_imagest:is_instance(i) then
local image = findImage(i.image.id, i.image.subid)
if image and image.name.has_name then
named_image = image
end
end
end
end
if named_image then
for i=0,6 do
artifact_record.name.words[i] = named_image.name.words[i]
artifact_record.name.parts_of_speech[i] = named_image.name.parts_of_speech[i]
end
artifact_record.name.language = named_image.name.language
artifact_record.name.has_name = true
end
end
end
Note: this is
very sketchy, but should be enough to work off of. The script currently looks for a name on a decoration on the item and, if it finds one, just copies that name into the artifact record. But, you could manually edit the artifact_record::name through the interactive Lua interface. You can find the word IDs (for name::words) at df.global.world.raws.language.words. They're actually just indexed in the order they appear in language_words.txt. The parts_of_speech is the specific variant of the word to use. 0 and 1 are singular and plural noun, for example.
You could also just skip all this, set all the words to -1, and then set the first_name to whatever you want, but that's less fun.
For an artifact weapon, you'll want to manually set the sharpness and such to the correct values for an artifact weapon. Search on Google for a script called "artifake," which I based mine off of. It sets the sharpness, so you can see how to do that from there.
EDIT: BTW, here's a useful thing for getting the word IDs:
for i,v in ipairs(df.global.world.raws.language.words) do dfhack.printerr(v.word .. ': ' .. i) end
That'll print the words and their IDs out to DFHack's error log. Copy/paste them into a text file, and you'll have a reference for any time you need to look up word IDs.
I considered writing a script to parse language_names from plain text, which would actually not be too hard, since everything's there in raws.language.words. The only tricky bit is the first, compound word. You'd have to first search for single words matching it, then try every split position until you find one that gives you two valid words. It ended up being overengineered for what I needed, though, so I've just been doing it manually when I need to.