Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How to update this script to generate a Necromancy Slab?  (Read 2386 times)

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
How to update this script to generate a Necromancy Slab?
« 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'
« Last Edit: May 30, 2020, 04:23:36 pm by UselessMcMiner »
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #1 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?
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #2 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'
« Last Edit: May 30, 2020, 08:03:42 pm by UselessMcMiner »
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

Fatace

  • Bay Watcher
  • Cease hostilities? Never!
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #3 on: May 30, 2020, 09:26:00 pm »

You may have better luck asking in the modding section of forums :)
Logged
I once had a 30 dwarf glacier fortress once.. was going great till the dwarf merchants brought along a WereKoala and killed everyone...

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #4 on: May 30, 2020, 10:01:44 pm »

Is there any way to move this topic?
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

Ziusudra

  • Bay Watcher
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #5 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.
« Last Edit: May 31, 2020, 12:18:28 am by Ziusudra »
Logged
Ironblood didn't use an axe because he needed it. He used it to be kind. And right now he wasn't being kind.

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #6 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
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #7 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".
« Last Edit: May 31, 2020, 12:47:17 pm by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #8 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?
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #9 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
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: How to update this script to generate a Necromancy Slab?
« Reply #10 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.
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: How to update this script to generate a Necromancy Slab?
« Reply #11 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)
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.