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.
--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.