Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Necromancer Script help  (Read 3177 times)

GamingMasterAnthony

  • Bay Watcher
    • View Profile
Necromancer Script help
« on: May 17, 2021, 04:22:57 pm »

I'm looking for a script that produces either a necromancer slab (tried atomic chicken's but it doesn't work, and the one burrito25man made with the help of meph years ago. Again, doen't work) so is there an updated version of them or does someone have to make a new one? And while i have experience in coding, i have none in .lua... mostly html and c# (and even then my c# is rusty at best)
Logged

Atomic Chicken

  • Bay Watcher
    • View Profile
Re: Necromancer Script help
« Reply #1 on: May 21, 2021, 03:34:33 pm »

Here's an updated version, now embellished with a gui:

Code: [Select]
-- Create a secret-conveying slab at the cursor position.
-- Author: Atomic Chicken

--@module = true

--[====[

gui/create-secret-slab
======================
A graphical interface for creating slabs that are capable of conveying
an I_SOURCE:SECRET interaction to readers.

Place the cursor wherever you want the slab to appear and run the script.
You will then be asked to select the slab's material and quality,
to input the text that will appear on the slab
(for example, "the secrets of life and death"),
and to select the secret that it will transfer.

]====]

local dialogs = require 'gui.dialogs'
local script = require 'gui.script'
local createItem = reqscript('gui/create-item')

function createSlab(matType, matIndex, quality, slabText, engravingType, topicID)
  local slab = df.item_slabst:new()
  slab.id = df.global.item_next_id
  slab:setMaterial(matType)
  slab:setMaterialIndex(matIndex)
  slab:setQuality(quality)
  slab.engraving_type = engravingType or -1
  slab.topic = topicID or -1
  slab.description = slabText or ""
  df.global.world.items.all:insert('#', slab)
  df.global.item_next_id = df.global.item_next_id+1
  slab:categorize(true)
  slab.flags.removed = true
  return slab
end

function guiSpawnSecretSlab()
  local pos = copyall(df.global.cursor)
  if pos.x < 0 then
    qerror("You must first select a location using the cursor.")
  end

  script.start(function()
    local matInputReceived, matType, matIndex, matFilter
    matInputReceived, matType, matIndex = createItem.showMaterialPrompt('Select Material', 'What material should the slab be made of?', createItem.matFilter)
    if not matInputReceived then
      return
    end

    local qualityInputReceived, quality
    qualityInputReceived, quality = script.showListPrompt('Select Quality', 'How high-quality should the slab be?', COLOR_WHITE, createItem.qualityTable())
    if not qualityInputReceived then
      return
    end

    local textInputReceived, slabText
    textInputReceived, slabText = script.showInputPrompt('Engrave', 'What should be written on the slab?', COLOR_WHITE)
    if not textInputReceived then
      return
    end

    local secrets = {}
    for _, interaction in ipairs(df.global.world.raws.interactions) do
      for _, source in ipairs(interaction.sources) do
        if source._type == df.interaction_source_secretst then
          local secretName = interaction.name
          if source.name ~= "" then
            secretName = secretName .. " - " .. source.name
          end
          table.insert(secrets, {text = secretName, interactionID = interaction.id, search_key = secretName:lower()})
          break
        end
      end
    end
    dialogs.showListPrompt('Engrave', 'What secret should the slab convey?', COLOR_WHITE, secrets, function(id, choice)
      local slab = createSlab(matType, matIndex, quality-1, slabText, df.slab_engraving_type.Secrets, choice.interactionID)
      dfhack.items.moveToGround(slab, pos)
    end, nil, nil, true)
  end)
end

guiSpawnSecretSlab()

To use:
- Install DFHack if you've not done so already.
- Copy-paste the above code into a text editor.
- Save it as a .lua file within the \hack\scripts folder.
- When playing, point the cursor wherever you want the slab to appear and enter [the name you assigned to the file when saving it] as a command in the DFHack console.
« Last Edit: May 23, 2021, 07:45:26 am by Atomic Chicken »
Logged
As mentioned in the previous turn, the most exciting field of battle this year will be in the Arstotzkan capitol, with plenty of close-quarter fighting and siege warfare.  Arstotzka, accordingly, spent their design phase developing a high-altitude tactical bomber. 

GamingMasterAnthony

  • Bay Watcher
    • View Profile
Re: Necromancer Script help
« Reply #2 on: May 24, 2021, 11:19:12 am »

Here's an updated version, now embellished with a gui:

Code: [Select]
-- Create a secret-conveying slab at the cursor position.
-- Author: Atomic Chicken

--@module = true

--[====[

gui/create-secret-slab
======================
A graphical interface for creating slabs that are capable of conveying
an I_SOURCE:SECRET interaction to readers.

Place the cursor wherever you want the slab to appear and run the script.
You will then be asked to select the slab's material and quality,
to input the text that will appear on the slab
(for example, "the secrets of life and death"),
and to select the secret that it will transfer.

]====]

local dialogs = require 'gui.dialogs'
local script = require 'gui.script'
local createItem = reqscript('gui/create-item')

function createSlab(matType, matIndex, quality, slabText, engravingType, topicID)
  local slab = df.item_slabst:new()
  slab.id = df.global.item_next_id
  slab:setMaterial(matType)
  slab:setMaterialIndex(matIndex)
  slab:setQuality(quality)
  slab.engraving_type = engravingType or -1
  slab.topic = topicID or -1
  slab.description = slabText or ""
  df.global.world.items.all:insert('#', slab)
  df.global.item_next_id = df.global.item_next_id+1
  slab:categorize(true)
  slab.flags.removed = true
  return slab
end

function guiSpawnSecretSlab()
  local pos = copyall(df.global.cursor)
  if pos.x < 0 then
    qerror("You must first select a location using the cursor.")
  end

  script.start(function()
    local matInputReceived, matType, matIndex, matFilter
    matInputReceived, matType, matIndex = createItem.showMaterialPrompt('Select Material', 'What material should the slab be made of?', createItem.matFilter)
    if not matInputReceived then
      return
    end

    local qualityInputReceived, quality
    qualityInputReceived, quality = script.showListPrompt('Select Quality', 'How high-quality should the slab be?', COLOR_WHITE, createItem.qualityTable())
    if not qualityInputReceived then
      return
    end

    local textInputReceived, slabText
    textInputReceived, slabText = script.showInputPrompt('Engrave', 'What should be written on the slab?', COLOR_WHITE)
    if not textInputReceived then
      return
    end

    local secrets = {}
    for _, interaction in ipairs(df.global.world.raws.interactions) do
      for _, source in ipairs(interaction.sources) do
        if source._type == df.interaction_source_secretst then
          local secretName = interaction.name
          if source.name ~= "" then
            secretName = secretName .. " - " .. source.name
          end
          table.insert(secrets, {text = secretName, interactionID = interaction.id, search_key = secretName:lower()})
          break
        end
      end
    end
    dialogs.showListPrompt('Engrave', 'What secret should the slab convey?', COLOR_WHITE, secrets, function(id, choice)
      local slab = createSlab(matType, matIndex, quality-1, slabText, df.slab_engraving_type.Secrets, choice.interactionID)
      dfhack.items.moveToGround(slab, pos)
    end, nil, nil, true)
  end)
end

guiSpawnSecretSlab()

To use:
- Install DFHack if you've not done so already.
- Copy-paste the above code into a text editor.
- Save it as a .lua file within the \hack\scripts folder.
- When playing, point the cursor wherever you want the slab to appear and enter [the name you assigned to the file when saving it] as a command in the DFHack console.

Thanks!
Logged

DeathShad0

  • Bay Watcher
    • View Profile
Re: Necromancer Script help
« Reply #3 on: May 30, 2021, 07:34:11 pm »

Here's an updated version, now embellished with a gui:

Code: [Select]
-- Create a secret-conveying slab at the cursor position.
-- Author: Atomic Chicken

--@module = true

--[====[

gui/create-secret-slab
======================
A graphical interface for creating slabs that are capable of conveying
an I_SOURCE:SECRET interaction to readers.

Place the cursor wherever you want the slab to appear and run the script.
You will then be asked to select the slab's material and quality,
to input the text that will appear on the slab
(for example, "the secrets of life and death"),
and to select the secret that it will transfer.

]====]

local dialogs = require 'gui.dialogs'
local script = require 'gui.script'
local createItem = reqscript('gui/create-item')

function createSlab(matType, matIndex, quality, slabText, engravingType, topicID)
  local slab = df.item_slabst:new()
  slab.id = df.global.item_next_id
  slab:setMaterial(matType)
  slab:setMaterialIndex(matIndex)
  slab:setQuality(quality)
  slab.engraving_type = engravingType or -1
  slab.topic = topicID or -1
  slab.description = slabText or ""
  df.global.world.items.all:insert('#', slab)
  df.global.item_next_id = df.global.item_next_id+1
  slab:categorize(true)
  slab.flags.removed = true
  return slab
end

function guiSpawnSecretSlab()
  local pos = copyall(df.global.cursor)
  if pos.x < 0 then
    qerror("You must first select a location using the cursor.")
  end

  script.start(function()
    local matInputReceived, matType, matIndex, matFilter
    matInputReceived, matType, matIndex = createItem.showMaterialPrompt('Select Material', 'What material should the slab be made of?', createItem.matFilter)
    if not matInputReceived then
      return
    end

    local qualityInputReceived, quality
    qualityInputReceived, quality = script.showListPrompt('Select Quality', 'How high-quality should the slab be?', COLOR_WHITE, createItem.qualityTable())
    if not qualityInputReceived then
      return
    end

    local textInputReceived, slabText
    textInputReceived, slabText = script.showInputPrompt('Engrave', 'What should be written on the slab?', COLOR_WHITE)
    if not textInputReceived then
      return
    end

    local secrets = {}
    for _, interaction in ipairs(df.global.world.raws.interactions) do
      for _, source in ipairs(interaction.sources) do
        if source._type == df.interaction_source_secretst then
          local secretName = interaction.name
          if source.name ~= "" then
            secretName = secretName .. " - " .. source.name
          end
          table.insert(secrets, {text = secretName, interactionID = interaction.id, search_key = secretName:lower()})
          break
        end
      end
    end
    dialogs.showListPrompt('Engrave', 'What secret should the slab convey?', COLOR_WHITE, secrets, function(id, choice)
      local slab = createSlab(matType, matIndex, quality-1, slabText, df.slab_engraving_type.Secrets, choice.interactionID)
      dfhack.items.moveToGround(slab, pos)
    end, nil, nil, true)
  end)
end

guiSpawnSecretSlab()

To use:
- Install DFHack if you've not done so already.
- Copy-paste the above code into a text editor.
- Save it as a .lua file within the \hack\scripts folder.
- When playing, point the cursor wherever you want the slab to appear and enter [the name you assigned to the file when saving it] as a command in the DFHack console.
You are a lifesaver. I've been going through threads several years old for a while now trying to figure out either how to update them myself or find someone else who has.

Although I do not understand this part
Quote
and to select the secret that it will transfer.
As nothing I enter is accepted.
« Last Edit: May 30, 2021, 07:43:18 pm by DeathShad0 »
Logged

DeathShad0

  • Bay Watcher
    • View Profile
Re: Necromancer Script help
« Reply #4 on: May 30, 2021, 08:31:52 pm »

Never mind, I'm retarded. Anybody else who attempts to remove all other necromancers from the world while using this, don't. Should've been obvious that removing all 'secrets' during worldgen would not only prevent necromancers from spawning, but prevent you from creating a necromancer's slab as well.
Logged