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

Title: How to update this script to generate a Necromancy Slab?
Post 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?

Code: [Select]
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'
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: UselessMcMiner on May 30, 2020, 04:34:51 pm
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?
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: UselessMcMiner on May 30, 2020, 07:48:12 pm
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

Code: [Select]
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'
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: Fatace on May 30, 2020, 09:26:00 pm
You may have better luck asking in the modding section of forums :)
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: UselessMcMiner on May 30, 2020, 10:01:44 pm
Is there any way to move this topic?
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: Ziusudra on May 31, 2020, 12:14:55 am
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.
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: UselessMcMiner on May 31, 2020, 09:58:36 am
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!

Code: [Select]
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
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: Bumber on May 31, 2020, 12:43:12 pm
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!

Code: [Select]
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".
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: UselessMcMiner on May 31, 2020, 01:11:46 pm
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?
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: Bumber on May 31, 2020, 02:21:56 pm
Does "df.item_slabst:new()" create the item positioned at the cursor, or does it need to be set manually? E.g.:
Code: [Select]
slab.pos = pos
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: UselessMcMiner on May 31, 2020, 02:49:00 pm
It creates an item at the position of the cursor, at least thats how its supposed to work.
Title: Re: How to update this script to generate a Necromancy Slab?
Post by: Quietust on June 03, 2020, 01:47:48 pm
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)