Bay 12 Games Forum
Dwarf Fortress => DF Modding => Utilities and 3rd Party Applications => Topic started by: UselessMcMiner on May 30, 2020, 04:09:38 pm
-
So this code posted by Amazing Chicken IIRC generated a necromancy slab, in this current version of DF it doesn't work (probably because every necromancer has different powers) so how could I update it?
local material = 'INORGANIC:SILVER'
function getSecretId()
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 == 'the secrets of life and death' then
return i.id
end
end
end
end
end
local pos = copyall(df.global.cursor)
if pos.x <0 then
error('Please place the cursor wherever you want to spawn the slab.')
end
local m = dfhack.matinfo.find(material)
if not m then
error('Invalid material.')
end
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()
slab.description = 'The secrets of life and death'
-
Ok so I got curious, and the Secret Interactions are in the World.dat file (I dont remember if they were in there before) each secret has an individual interaction, is it at all possible to make a slab using dfhack from a secret in the world.dat folder?
-
So I tried to edit the script, but it doesn't seem to work (the slab doesn't spawn) Any idea of what I'm doing wrong? This is the first time I've experimented with Lua so I'm a bit confused
local material = 'INORGANIC:SILVER'
function getSecretId()
for i,c in ipairs(df.global.world.raws.interactions) do
if c.name == "SECRET_1" then
return i.id
end
end
local pos = copyall(df.global.cursor)
if pos.x <0 then
error('Please place the cursor wherever you want to spawn the slab.')
end
local m = dfhack.matinfo.find(material)
if not m then
error('Invalid material.')
end
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()
slab.description = 'The secrets of life and death'
-
You may have better luck asking in the modding section of forums :)
-
Is there any way to move this topic?
-
Go to the first post on the thread,
click modify, when the modify page loads scroll all the way to the bottom.
Edit: Oops, you don't have to do the modify part. Just scroll to the bottom of the page.
-
I guess my problem is that I'm not sure how to actually access the name of the secret in the raws, if someone could tell me how to do that, that would be grand thank you!
function getSecretId()
for i,c in ipairs(df.global.world.raws.interactions) do
if c.interaction.name == "SECRET_1" then
return i.id
end
end
-
I guess my problem is that I'm not sure how to actually access the name of the secret in the raws, if someone could tell me how to do that, that would be grand thank you!
function getSecretId()
for i,c in ipairs(df.global.world.raws.interactions) do
if c.interaction.name == "SECRET_1" then
return i.id
end
end
c.interaction.name should be just c.name.
c.name gives the raw name, which is "SECRET_1".
-
Ah thats how I was doing it originally, but it still doesn't work. Is it possible theres an issue with the code to generate the slab item itself?
-
Does "df.item_slabst:new()" create the item positioned at the cursor, or does it need to be set manually? E.g.:
slab.pos = pos
-
It creates an item at the position of the cursor, at least thats how its supposed to work.
-
It creates an item at the position of the cursor, at least thats how its supposed to work.
It most certainly does not - if you're directly instantiating a DF class, you need to initialize all of its fields yourself.
In the case of creating an item, not only do you need to set its position, but you also need to insert it into the map_block corresponding to the coordinates you provided. Fortunately, DFHack contains a helper function for doing this: dfhack.items.moveToGround(item, pos)