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.
1.
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
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.
local function starts(String, Start)
return string.sub(String, 1, #Start) == Start
end
function use_liquid(is_magma)
local liquid_name="water"
if is_magma then
liquid_name="magma"
end
return function (reaction,unit,job,input_items,input_reagents,output_items,call_native)
local building = dfhack.buildings.findAtTile(unit.pos)
local pos = {
x1=building.x1,
x2=building.x2,
y1=building.y1,
y2=building.y2,
z=building.z }
for x = pos.x1-1, pos.x2+1, 1 do
for y = pos.y1-1, pos.y2+1, 1 do
local liquidBlock = dfhack.maps.ensureTileBlock(x,y,pos.z-1)
local designation=liquidBlock.designation[x%16][y%16]
if designation.flow_size > 0 and designation.liquid_type == is_magma then
designation.flow_size = designation.flow_size - 1
return
end
end
end
dfhack.gui.showAnnouncement( string.format("%s cancels %s. Needs %s.",dfhack.TranslateName(unit.name),reaction.name,liquid_name), COLOR_RED, true)
call_native.value=false
end
end
dfhack.onStateChange.loadUseLiquid = function(code)
local registered_reactions = false
if code==SC_MAP_LOADED then
for i,reaction in ipairs(df.global.world.raws.reactions) do
if starts(reaction.code,'LUA_HOOK_USEWATER') then
eventful.registerReaction(reaction.code,use_liquid(false))
registered_reactions = true
elseif starts(reaction.code,'LUA_HOOK_USEMAGMA') then
eventful.registerReaction(reaction.code,use_liquid(true))
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. Have no idea :P