Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Mephs script questions/requests/things I need help with  (Read 2160 times)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Mephs script questions/requests/things I need help with
« on: May 16, 2016, 07:40:38 pm »

I thought a topic would make more sense than constantly writing PMs.

Things I currently need help with:
1. Spawning webs next to a workshop. I tried createitem, but it doesnt work with webs. I tried create-items, but it doesnt allow a location to be set. :/

2. Removing soil and creating open-space next to/under a workshop. I had a script that worked with dfhack 40.24, but now crashes the game.

3. Getting this script to run: waterwell.lua. It should check if water/magma is next to a workshop, otherwise cancel any reaction with LUA_HOOK_USEWATER/USEMAGMA_. But it only shows an errorlog.

Code: [Select]
--Lets you make reactions that require water or magma under the workshop.  Reactions must start with LUA_HOOK_USEWATER or LUA_HOOK_USEMAGMA.
local eventful = require 'plugins.eventful'
local utils = require 'utils'

local function starts(String, Start)
return string.sub(String, 1, string.len(Start)) == Start
end

function usewater(reaction,unit,job,input_items,input_reagents,output_items,call_native)
local building = dfhack.buildings.findAtTile(unit.pos)
local pos = {}
pos.x1 = building.x1
pos.x2 = building.x2
pos.y1 = building.y1
pos.y2 = building.y2
pos.z = building.z
for x = pos.x1-1, pos.x2+1, 1 do
for y = pos.y1-1, pos.y2+1, 1 do
baseBlock = dfhack.maps.ensureTileBlock(x,y,pos.z)
liquidBlock = dfhack.maps.ensureTileBlock(x,y,pos.z-1)
if liquidBlock.designation[x%16][y%16].flow_size > 0 and liquidBlock.designation[x%16][y%16].liquid_type == false then
liquidBlock.designation[x%16][y%16].flow_size = liquidBlock.designation[x%16][y%16].flow_size - 1
return
end
end
end
dfhack.gui.showAnnouncement( dfhack.TranslateName(unit.name).." cancels "..reaction.name..": Needs water." , COLOR_RED, true)
for i=0,#input_items-1,1 do
input_items[i].flags.PRESERVE_REAGENT = true
end
for i=0,#reaction.products-1,1 do
reaction.products[i].probability = 0
end
end


function usemagma(reaction, reaction_product, unit, input_items, input_reagents, output_items, call_native)
local building = dfhack.buildings.findAtTile(unit.pos)
local pos = {}
pos.x1 = building.x1
pos.x2 = building.x2
pos.y1 = building.y1
pos.y2 = building.y2
pos.z = building.z

for x = pos.x1-1, pos.x2+1, 1 do
for y = pos.y1-1, pos.y2+1, 1 do
baseBlock = dfhack.maps.ensureTileBlock(x,y,pos.z)
liquidBlock = dfhack.maps.ensureTileBlock(x,y,pos.z-1)
if liquidBlock.designation[x%16][y%16].flow_size > 0 and liquidBlock.designation[x%16][y%16].liquid_type == true then
liquidBlock.designation[x%16][y%16].flow_size = liquidBlock.designation[x%16][y%16].flow_size - 1
return
end
end
end

dfhack.gui.showAnnouncement( dfhack.TranslateName(unit.name).." cancels "..reaction.name..": Needs magma." , COLOR_RED, true)
for k,v in ipairs(input_reagents) do
input_reagents[k].flags.PRESERVE_REAGENT = true
end
for i=0,#reaction.products-1,1 do
reaction.products[i].probability = 0
end
end

dfhack.onStateChange.loadUseLiquid = function(code)
local registered_reactions = false
if code==SC_MAP_LOADED then
--registered_reactions = {}
for i,reaction in ipairs(df.global.world.raws.reactions) do
if starts(reaction.code,'LUA_HOOK_USEWATER') then
eventful.registerReaction(reaction.code,usewater)
registered_reactions = true
elseif starts(reaction.code,'LUA_HOOK_USEMAGMA') then
eventful.registerReaction(reaction.code,usemagma)
registered_reactions = true
end
end
if registered_reactions then
print('Use Liquid Reactions: Loaded.')
end
elseif code==SC_MAP_UNLOADED then
end
end

if dfhack.isMapLoaded() then dfhack.onStateChange.loadUseLiquid(SC_MAP_LOADED) end

4. What happened to Itemsyndrome? Aka "unit equips item, item adds a syndrome/interaction to unit". That one was extremely interesting to modders.
« Last Edit: May 17, 2016, 12:31:31 am by Meph »
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: Mephs script questions/requests/things I need help with
« Reply #1 on: May 18, 2016, 12:47:27 am »

I thought a topic would make more sense than constantly writing PMs.

Things I currently need help with:
1. Spawning webs next to a workshop. I tried createitem, but it doesnt work with webs. I tried create-items, but it doesnt allow a location to be set. :/

2. Removing soil and creating open-space next to/under a workshop. I had a script that worked with dfhack 40.24, but now crashes the game.

3. Getting this script to run: waterwell.lua. It should check if water/magma is next to a workshop, otherwise cancel any reaction with LUA_HOOK_USEWATER/USEMAGMA_. But it only shows an errorlog.

Code: [Select]
--Lets you make reactions that require water or magma under the workshop.  Reactions must start with LUA_HOOK_USEWATER or LUA_HOOK_USEMAGMA.
local eventful = require 'plugins.eventful'
local utils = require 'utils'

local function starts(String, Start)
return string.sub(String, 1, string.len(Start)) == Start
end

function usewater(reaction,unit,job,input_items,input_reagents,output_items,call_native)
local building = dfhack.buildings.findAtTile(unit.pos)
local pos = {}
pos.x1 = building.x1
pos.x2 = building.x2
pos.y1 = building.y1
pos.y2 = building.y2
pos.z = building.z
for x = pos.x1-1, pos.x2+1, 1 do
for y = pos.y1-1, pos.y2+1, 1 do
baseBlock = dfhack.maps.ensureTileBlock(x,y,pos.z)
liquidBlock = dfhack.maps.ensureTileBlock(x,y,pos.z-1)
if liquidBlock.designation[x%16][y%16].flow_size > 0 and liquidBlock.designation[x%16][y%16].liquid_type == false then
liquidBlock.designation[x%16][y%16].flow_size = liquidBlock.designation[x%16][y%16].flow_size - 1
return
end
end
end
dfhack.gui.showAnnouncement( dfhack.TranslateName(unit.name).." cancels "..reaction.name..": Needs water." , COLOR_RED, true)
for i=0,#input_items-1,1 do
input_items[i].flags.PRESERVE_REAGENT = true
end
for i=0,#reaction.products-1,1 do
reaction.products[i].probability = 0
end
end


function usemagma(reaction, reaction_product, unit, input_items, input_reagents, output_items, call_native)
local building = dfhack.buildings.findAtTile(unit.pos)
local pos = {}
pos.x1 = building.x1
pos.x2 = building.x2
pos.y1 = building.y1
pos.y2 = building.y2
pos.z = building.z

for x = pos.x1-1, pos.x2+1, 1 do
for y = pos.y1-1, pos.y2+1, 1 do
baseBlock = dfhack.maps.ensureTileBlock(x,y,pos.z)
liquidBlock = dfhack.maps.ensureTileBlock(x,y,pos.z-1)
if liquidBlock.designation[x%16][y%16].flow_size > 0 and liquidBlock.designation[x%16][y%16].liquid_type == true then
liquidBlock.designation[x%16][y%16].flow_size = liquidBlock.designation[x%16][y%16].flow_size - 1
return
end
end
end

dfhack.gui.showAnnouncement( dfhack.TranslateName(unit.name).." cancels "..reaction.name..": Needs magma." , COLOR_RED, true)
for k,v in ipairs(input_reagents) do
input_reagents[k].flags.PRESERVE_REAGENT = true
end
for i=0,#reaction.products-1,1 do
reaction.products[i].probability = 0
end
end

dfhack.onStateChange.loadUseLiquid = function(code)
local registered_reactions = false
if code==SC_MAP_LOADED then
--registered_reactions = {}
for i,reaction in ipairs(df.global.world.raws.reactions) do
if starts(reaction.code,'LUA_HOOK_USEWATER') then
eventful.registerReaction(reaction.code,usewater)
registered_reactions = true
elseif starts(reaction.code,'LUA_HOOK_USEMAGMA') then
eventful.registerReaction(reaction.code,usemagma)
registered_reactions = true
end
end
if registered_reactions then
print('Use Liquid Reactions: Loaded.')
end
elseif code==SC_MAP_UNLOADED then
end
end

if dfhack.isMapLoaded() then dfhack.onStateChange.loadUseLiquid(SC_MAP_LOADED) end

4. What happened to Itemsyndrome? Aka "unit equips item, item adds a syndrome/interaction to unit". That one was extremely interesting to modders.

1.
Spoiler (click to show/hide)

2. Don't like messing with tiletypes: You need to figure out A LOT of corner cases (e.g. if the tile is in some vein, if it has itles below, if it has above etc...)

3. I tidied it up a little. However can't test it yet. Also if it shows errorlog it would be helpful if you pasted it.
Spoiler (click to show/hide)

4. Have no idea :P

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Mephs script questions/requests/things I need help with
« Reply #2 on: May 18, 2016, 01:47:53 am »

I'll test the water/magma script now, thanks :)

How does this help? Is that a script-part for createitem? It seems to plant a web at the cursor, which is the same as what create-items does atm. My problem was triggering it with reaction-trigger and planting it NEXT to the workshop, aka finding and changing the location without a cursor.
Code: [Select]
local material=dfhack.matinfo.find("CREATURE_MAT:SPIDER_CAVE:SILK")
local item1 = dfhack.items.createItem(dfhack.items.findType("THREAD"), dfhack.items.findSubtype("THREAD"), material.type, material.index, df.unit.find(df.global.unit_next_id-1))
local item = df.item.find(item1)
dfhack.items.moveToGround(item,copyall(df.global.cursor))
item.flags.spider_web=true

EDIT: The new waterwell script shows this message when I load a world:
Code: [Select]
...waterwell.lua:41: attempt to index global 'eventful' (a nil value)
stack traceback:        ...waterwell.lua:41: in function<...waterwell.lua:36>
« Last Edit: May 18, 2016, 01:51:51 am by Meph »
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: Mephs script questions/requests/things I need help with
« Reply #3 on: May 18, 2016, 02:09:51 am »

Can't help you with reaction-trigger. Those "\\" give me a headache.

Waterwell is missing "local eventful = require 'plugins.eventful' " at the begging. Sorry.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Mephs script questions/requests/things I need help with
« Reply #4 on: May 18, 2016, 02:16:27 am »

Can't help you with reaction-trigger. Those "\\" give me a headache.
Me too ^^

Added local eventful = require 'plugins.eventful'

Errorlog now:
Code: [Select]
.../waterwell.lua:14: Cannot read field reaction_product_itemst.pos: not found.stack traceback:
        [C]: in function '__index'
        .../waterwell.lua:14: in function '?'
        ....03 (42.06)\Dwarf Fortress\hack\lua\plugins\eventful.lua:49: in function <....03 (42.06)\Dwarf Fortress\hack\lua\plugins\eventful.lua:47>
.../waterwell.lua:14: Cannot read field reaction_product_itemst.pos: not found.
stack traceback:
        [C]: in function '__index'
        .../waterwell.lua:14: in function '?'
        ....03 (42.06)\Dwarf Fortress\hack\lua\plugins\eventful.lua:49: in function <....03 (42.06)\Dwarf Fortress\hack\lua\plugins\eventful.lua:47>
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: Mephs script questions/requests/things I need help with
« Reply #5 on: May 18, 2016, 06:55:01 am »

change
Code: [Select]
return function (reaction,unit,job,input_items,input_reagents,output_items,call_native)
to
Code: [Select]
return function (reaction,reaction_product,unit,input_items,input_reagents,output_items,call_native)

Roses

  • Bay Watcher
    • View Profile
Re: Mephs script questions/requests/things I need help with
« Reply #6 on: May 18, 2016, 09:53:27 am »

itemsyndrome has been replaced with modtools/item-trigger, same functionality as far as I know, with perhaps more stuff added on.

As for \\LOCATION, I think it would be interesting if we could change all of the modtools scripts that currently support it to also support offsets. But for now I will write a small plugin script that will allow you to set location and offset.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Mephs script questions/requests/things I need help with
« Reply #7 on: May 18, 2016, 11:03:49 am »

change
Code: [Select]
return function (reaction,unit,job,input_items,input_reagents,output_items,call_native)
to
Code: [Select]
return function (reaction,reaction_product,unit,input_items,input_reagents,output_items,call_native)
Done, less errors, but cant find the location.

Quote
...ss/data/save/region26/raw/scripts/succubus/waterwell.lua:14: Cannot read field reaction_product_itemst.pos: not found.
stack traceback:
        [C]: in function '__index'
        ...ss/data/save/region26/raw/scripts/succubus/waterwell.lua:14: in function '?'
        ....03 (42.06)\Dwarf Fortress\hack\lua\plugins\eventful.lua:49: in function <....03 (42.06)\Dwarf Fortress\hack\lua\plugins\eventful.lua:47>

Thanks Roses, I'll have a look at item-trigger.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: Mephs script questions/requests/things I need help with
« Reply #8 on: May 18, 2016, 01:50:24 pm »

Rubble comes with Item Syndrome Reborn, a reworking of the old item syndrome.

modtools/item-trigger will work too, but last I looked it was a lot harder to use...
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS