16
Utilities and 3rd Party Applications / Re: Connecting lua scripts to reactions + related worldgen questions
« on: January 09, 2021, 12:23:04 am »
1) You don't have to write anything special in the reaction itself (see later points). I think there was/still is functionality to do it by naming reactions in certain ways, but I don't know if anyone still does that.
2) IIRC yes, the reaction needs a product, or else the code doesn't actually trigger (even though the documentation says otherwise). There's supposed to be a way to prevent the product from actually being made, but I believe that functionality is broken/removed (though I could be misremembering, it's been ages), so most people set the product to be a boulder of a dummy material that turns into gas instantly.
3) By using modtools/reaction-trigger. You should include each command inside an onLoad init file, so they get automatically run every time a world is loaded (otherwise you'd have to manually type in each command into the console every time you load up the world).
Here's an example from an old mod I abandoned. When the reaction with the ID "THE_HIVE_SPAWN_QUEEN" is completed, a QUEEN caste of the creature THE_HIVE is spawned that's part of the fort, and uses THE_HIVE entity's naming conventions:Code: [Select]modtools/reaction-trigger -reactionName THE_HIVE_SPAWN_QUEEN -command [ modtools/create-unit -race THE_HIVE -caste QUEEN -setUnitToFort -name THE_HIVE -location [ \\LOCATION ] -age 0 ]
4) If I remember correctly, there will be problems in worldgen for creatures that reproduce solely from reactions. create-unit combined with reaction-trigger only spawns the creatures from their reactions when the reaction is used during fortress mode. This means that for all of worldgen, no new creatures are actually spawned, and so that civilisation is left with just their default level of population that the game initially spawns them with (assuming they can't reproduce on their own).
It might be possible to rig something up to have them create more of themselves during worldgen, like say giving them a dummy item that they can create as a craft, and then periodically replacing any of those items stored in a site with people instead. It'd obviously need a custom made script for it (I don't think one such script exists currently), and I'm not sure how possible it is, since I've never touched anything worldgen related before. 🤔Given your content, whether it still works needs to be seen but "construct-creature.lua by IndigoPhoenix" might fit your purposes because of the way it transfers the reagent material directly into it.That does look pretty old, and I'm not sure how well it'll work, but I'm glad I stumbled upon it. I never realised/considered you could just straight-up edit the materials a creature is made up from. I was considering potentially picking up one of my old mod concepts that involves creating golems, and I was going to just cheat making them out of a particular material by colouring their body material based on the colour of the material used, but actually making them out of their material sounds better.
Though actually looking into it, it doesn't look like those changes to a unit's materials are actually saved, so you'd have to reapply them whenever they're loaded, which seems like potentially more effort than it's worth.
2) Would having the reaction emit smoke count as a product? The smoke wouldn't do anything, just serve as a product for purposes of needing a product. (And maybe for dramatic effect.)
4) Ahhh, I have zero coding experience so I'm not quite sure how to write such a script. I'm like a toddler who knows basic math but can't do anything past that to give a decent metaphor about coding.
Given your content, whether it still works needs to be seen but "construct-creature.lua by IndigoPhoenix" might fit your purposes because of the way it transfers the reagent material directly into it. Im new to writing in DFhack too, but the workshop reactions are fufilled by inputting them (somewhere, anywhere) onto the dfhack.init file in a particular code string to execute when the game is loaded, usually referencing a seperate .lua with the code in it.
I like to use grown.lua (which i picked up as part of a older modification's dfhack spec) which applies a simple grown flag to the output which is useful for elf modifications. etc like a so. My particular example is to process cut logs, then restore them to be grown via elven means of... tree necromancy? Its nonspecific but it ought to work in a way that i can simply launder my logs through the shrine and then not alienate any traders later so long as im careful.
Location, then reaction-product-trigger (pretty typical if you've got DFhack of the latest version out the box, its simply referencing the scope from the DFfilefolder's position, and would change if you added another dfhack.init somewhere else) input a name from the reaction file, then the command references the actual code to apply in square brackets so it works.
The // is just a comment to keep track of what its meant to be doing and anything past // doesnt count as the code will stop reading.Code: [Select]modtools/reaction-product-trigger -reactionName DENDROMANTIC_REVIVAL -command [ grownwood.lua \\OUTPUT_ITEMS ]
Feel free to correct me anybody if i've actually got it wrong myself. Its all a opportunity to learn. Notepad++ application is probably the easiest way to open them to look inside any .lua file and also make relevant edits.
I do kind of want to make procedural wood ents now though. Thinking of the hideously strong dryads/ents i could make with custom trees, there's more than enough old abandoncode elf mods to finish it.
Oh!!! Thank you very much. This makes a lot of sense--but I only need one thing (A large gem) to make a rock person, and I'm not sure if you can leave out one thing in the code. I did think briefly about making the rock people bleed gold because the mental image of their scars resembling kintsugi would be cool, but it would be difficult in practice to hunt down literal gold just to expand the fort's population without exploits. I could instead just make it so that they need metal bars of any kind to act as "blood."
).