Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [DFHack][Script] run once per save  (Read 551 times)

Erendir

  • Bay Watcher
    • View Profile
[DFHack][Script] run once per save
« on: February 24, 2020, 02:41:00 pm »

Short:
Place script in dfhack/scripts/, add
Code: [Select]
once-per-save ban-cooking tallow; ban-cooking honey; ban-cooking oil; ban-cooking seeds; ban-cooking brew; ban-cooking fruit; ban-cooking mill; ban-cooking thread; ban-cooking milk;
to your onMapLoad.init and don't ever forget doing it when returning to DF after a year long pause.

Long:
I'm sporadic DF player with months-long pauses between "sessions". Every time I'm trying to remember what was it one should always do when starting a fresh embark, were there any dfhack-commands to run? Every time I find something new, like `ban-cooking seeds` (so useful!).

There are those dfhack .init files, but sometimes we only want a command run once per fort, but unfortunately, there is no onNewGame.init (AFAIK).

But now we can do just this by placing all run-once-per-save commands in onMapLoad.init and don't have to think about them anymore.

If there is another way I'm unaware of, I'd really like to know.

I also don't yet know how do I hook into fortress abandoned (or created) events (those are when we want to reset the save state). Update: the newest version shouldn't need resetting its state anymore: commands are saved per fortress (`site_id`) with `fortress_age` and world date associated, so new fortress, as well as an unretired one, are properly recognized.

pull request for discussion.
other pull request with simplified version of this.
« Last Edit: March 09, 2020, 03:32:44 am by Erendir »
Logged

sxtxixtxcxh

  • Bay Watcher
    • View Profile
Re: [DFHack][Script] run once per save
« Reply #1 on: March 08, 2020, 05:45:01 pm »

can i nominate
Code: [Select]
3dviens ( https://docs.dfhack.org/en/stable/docs/Plugins.html#dveins ) to be added to this once-per-save script?
Logged

Erendir

  • Bay Watcher
    • View Profile
Re: [DFHack][Script] run once per save
« Reply #2 on: March 09, 2020, 03:31:22 am »

can i nominate
Code: [Select]
3dviens ( https://docs.dfhack.org/en/stable/docs/Plugins.html#dveins ) to be added to this once-per-save script?

the idea is to give the user the tools needed.
In this case, add following to the onMapLoad.init of your choice:
Code: [Select]
once-per-save 3dveins

there is actually a much simpler version of this script that would only execute in a newborn fortress ( pull request) which is preferred way in this case.

Code: [Select]
on-new-fortress 3dveins

I will add `3dveins` to the documentation since it's a very good usage example.
Logged