Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DFHack lua script - egg-saver  (Read 1603 times)

khm

  • Escaped Lunatic
    • View Profile
DFHack lua script - egg-saver
« on: September 14, 2021, 08:02:45 pm »

hello,

with how long this game has been out i strongly suspect that this already exists somewhere, but i couldn't find it. i was kind of annoyed with all the micromanagement i was having to do to stop my dwarfs from stealing fertilized eggs, so i wrote this short script. it listens for dwarfs getting assigned jobs moving objects to storage. if that object is a fertilized egg it will remove the worker from the job and mark the eggs as forbidden.

file name:
Code: [Select]
egg-saver.luacode:
Code: [Select]
local utils = require('utils')
local eventful = require 'plugins.eventful'

if eventful.onJobInitiated.saveEggs == nil then
eventful.onJobInitiated.saveEggs = function(job)
if job.flags.store_item then
for _,item in ipairs(job.items) do
if item.item._type == df.item_eggst and item.item.egg_flags.fertile then
item.item.flags.forbid = true
dfhack.job.removeWorker(job, 1000)
print("Eggs Saved!")
end
end
end
end
print("Starting Egg Saver")
else
eventful.onJobInitiated.saveEggs = nil
print("Stopping Egg Saver")
end
eventful.enableEvent(eventful.eventType.JOB_INITIATED, 0)

it's toggle-able, so to start/stop it, just type this into the DFHack prompt
Code: [Select]
egg-saver
the upside is now i don't have to micromanage my dwarfs, the downside is now i have over 200 chickens
Logged

myk

  • Bay Watcher
    • View Profile
Re: DFHack lua script - egg-saver
« Reply #1 on: September 14, 2021, 09:12:04 pm »

Nice script, but I think the plugin you're looking for is nestboxes: https://docs.dfhack.org/en/stable/docs/Plugins.html#nestboxes
Logged

khm

  • Escaped Lunatic
    • View Profile
Re: DFHack lua script - egg-saver
« Reply #2 on: September 14, 2021, 10:04:40 pm »

you would be correct sir, that plugin does indeed do what i was aiming to do. but the problem with it is i didn't know about it before and now i'm tumbling down the rabbit hole of DFHack scripting.
Logged

myk

  • Bay Watcher
    • View Profile
Re: DFHack lua script - egg-saver
« Reply #3 on: September 14, 2021, 11:15:12 pm »

You're in good company! Ask on the discord server if you need any help with anything!
Logged