Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: Script to fill bucket/barrel with water/magma near a workshop  (Read 6383 times)

Roses

  • Bay Watcher
    • View Profile
Re: Need help with water/magma script
« Reply #15 on: July 30, 2014, 02:10:43 pm »

Yes I believe milo is right, I didn't notice that when I was looking over it, but I think IndigoFenix got them backwards. Change true to false and false to true and it should work.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Need help with water/magma script
« Reply #16 on: July 30, 2014, 02:24:30 pm »

Thank you two so much. It works!

Humans are still pretty dumb. But I got it to work as intended. I can add liquid_misc to buckets, which is used to bring water to prisoners and injured humans, while I can make drink:none:water:none and add it to a barrel, which will be used by normal humans, they drink it straight from the barrel. NICE!

Now people can barrel and stockpile water. :)

PS: Thirsty people will ignore water in buckets. lol. Barrels are fine though, and buckets are fine for the hospital.
« Last Edit: July 30, 2014, 02:27:04 pm 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 :::

Roses

  • Bay Watcher
    • View Profile
Re: Need help with water/magma script
« Reply #17 on: July 30, 2014, 02:33:05 pm »

Who drinks water out of a bucket? I am a barrel man all the way. Nothing like picking up an entire barrel full of water to start the day out. And you can't do a barrel stand off a bucket!
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Need help with water/magma script
« Reply #18 on: July 30, 2014, 02:57:01 pm »

Its actually pretty useful, because I can finally use water as reagents in custom reactions... like alchemy or tea or water magic reactions. Previously that wasnt possible, because dwarves are too stupid to realize that they potentially could fill a bucket with water. But now I can do it manually. :)

This is one of those things that fits every mod well.
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 :::

Roses

  • Bay Watcher
    • View Profile
Re: Need help with water/magma script
« Reply #19 on: July 30, 2014, 03:12:45 pm »

Indeed, I will have to add it into mine as well. I always found it odd that you couldn't fill up a barrel with water.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Need help with water/magma script
« Reply #20 on: July 30, 2014, 03:23:11 pm »

Here the reactions:

Code: [Select]

[REACTION:LUA_HOOK_USEWATER_WATERWELL]
[NAME:Fill a bucket with water]
[BUILDING:STILL:CUSTOM_ALT_W]
[REAGENT:A:1:BUCKET:NONE:NONE:NONE][PRESERVE_REAGENT] [EMPTY]
[PRODUCT:100:7:LIQUID_MISC:NONE:WATER:NONE][PRODUCT_TO_CONTAINER:A]
[PRODUCT_DIMENSION:150]
[SKILL:BREWING]

[REACTION:LUA_HOOK_USEWATER_WATERWELL2]
[NAME:Fill a barrel with water]
[BUILDING:STILL:CUSTOM_ALT_B]
[REAGENT:A:1:BARREL:NONE:NONE:NONE][PRESERVE_REAGENT] [EMPTY]
[PRODUCT:100:10:DRINK:NONE:WATER:NONE][PRODUCT_TO_CONTAINER:A]
[PRODUCT_DIMENSION:150]
[SKILL:BREWING]

Note that a bucket cant have more than 7 units of liquids. It must be LIQUID_MISC to be used. For the barrel it has to be DRINK, otherwise they wont drink from it. Btw, any liquid can be made a drink that way, even magma. DRINK:NONE:INORGANIC:NONE will make a magma barrel. Even a wooden one is fine, and people drinking from it are unharmed. This would mean you can make a magma-brewery for very hot drinks. :D

I chose 10 for the barrel. I think its fair. 15 can be done as well, anything larger will spill.

Edit: Here the working script, in case other people want to use it.
Spoiler (click to show/hide)
« Last Edit: July 30, 2014, 04:03:06 pm 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 :::

Roses

  • Bay Watcher
    • View Profile
Re: Script to fill bucket/barrel with water/magma near a workshop
« Reply #21 on: July 30, 2014, 03:47:32 pm »

You may want to change the usemagma function to match the usewater function (you can copy and paste everything from the usewater function, just make sure to change the false to a true), otherwise it will only check under the very center of the workshop.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Script to fill bucket/barrel with water/magma near a workshop
« Reply #22 on: July 30, 2014, 04:01:55 pm »

Done. Thanks for the reminder.
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 :::

stuntcock42

  • Escaped Lunatic
    • View Profile
Re: Script to fill bucket/barrel with water/magma near a workshop
« Reply #23 on: August 21, 2014, 03:38:46 am »

Hi Meph.  I used your script in a small mod but made a few tweaks that might be useful for general-purpose stuff.
  • removed "job" from the method signature list because DFHack doesn't provide it when invoking the callback
    • this is based on the Lua API documentation and testing with DFHack 0.40.08-r2.  If you're using a customized version of the Eventful plugin in Masterwork then you can ignore this tweak.
  • switched the abort logic from "preserve all reagents and reduce the output probability to 0%" to "call_native = false".
    • This is intended to avoid an unintended consequence with repeated jobs, wherein a single failure would permanently "poison" the reaction and all subsequent attempts were guaranteed to fail.
    • I don't know whether or not the Repeat-job problem would arise during normal gameplay.  I noticed it only after I began using the DFHack Workflow plugin to automate my water-consuming reactions.
    • Minor consequence: the original script would award experience points even though the Job had been canceled; the tweaked script does not.
  • added a brief cooldown.  Rather than repeating the failed job (and hitting the same problem), the worker can now consider alternate tasks.
    • For example, my mod causes Brewing jobs at the Still to consume water.  If I enable Water-hauling on the Brewer then he'll occasionally exhaust his water supply, report a job cancellation, spend a few minutes refilling the Pond adjacent to his Still, and then resume Brewing.  With the original script, he would just stand at his Still all day long and repeatedly complain about the absence of water.
  • The job-cancellation announcement is now Zoomable.
  • Caution: the modified script does consume Reagents in the event of a job failure.  If you're simply moving environmental water/magma into a container then this isn't a problem (because everything marked with PRESERVE_REAGENT will survive).  In my case (water-reliant brewing) it occasionally wastes a few plants.  If anyone out there is planning to use this script in a complex reaction with precious materials, then please be aware of this failure scenario.
Code: [Select]
function usewater(reaction,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 == false then
liquidBlock.designation[x%16][y%16].flow_size = liquidBlock.designation[x%16][y%16].flow_size - 1
call_native.value=true    -- Allow the job to succeed.  Consume any applicable Reagents, create the appropriate Products, and train the related Skill.
return
end
end
end
dfhack.gui.showZoomAnnouncement(df.announcement_type.CANCEL_JOB, unit.pos, dfhack.TranslateName(unit.name).." cancels "..reaction.name..": Needs water." , COLOR_RED, true)
call_native.value=false    -- Force the job to fail.  Create no Products; do not provide any experience points in the associated Skill.  Note: the failed job WILL consume the normal set of Reagents.
dfhack.job.setJobCooldown(building, unit, 5)    -- Prevent the worker from immediately re-attempting the failed Job.
return
end
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Script to fill bucket/barrel with water/magma near a workshop
« Reply #24 on: August 21, 2014, 03:42:57 am »

Thats a good set of improvements :)

How did you make vanilla brewing require water? Also dfhack that hooks into the 'brew drink' reaction?
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 :::

palu

  • Bay Watcher
    • View Profile
Re: Script to fill bucket/barrel with water/magma near a workshop
« Reply #25 on: August 21, 2014, 04:39:07 pm »

In 40.0x, brewing is a custom reaction.
Logged
Hmph, palu showing off that reading-the-instructions superpower.
The internet encourages thoughtful, intelligent discussion and if you disagree I hate you.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Script to fill bucket/barrel with water/magma near a workshop
« Reply #26 on: August 25, 2014, 05:08:39 am »

In 40.0x, brewing is a custom reaction.
:o

I need to have a better look at the new version it seems. :)
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 :::

Nate McCloud

  • Bay Watcher
    • View Profile
Re: Script to fill bucket/barrel with water/magma near a workshop
« Reply #27 on: March 01, 2018, 04:24:02 am »

Really sorry for necroposting, but I want to use this script so I can have a working obsidian forge building for crafting obsidian without risking burning my dwarves. The only problem is, I don't see any way to require that the workshop have both water AND magma underneath it. How would I do that with this script?
Logged
Pages: 1 [2]