Bay 12 Games Forum

Please login or register.

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

Author Topic: Holidays  (Read 8658 times)

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #15 on: September 22, 2019, 08:40:33 am »

Into the dfhack.init.

Does this mean that mods that use dfhack arn't copatiblebe since they would both overwrite dfhack.init?

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Holidays
« Reply #16 on: September 22, 2019, 08:54:12 am »

Not really. You just tell players to enable it there, or you write your won init. Doesn't have to be the same file. For example Masterwork has an .init for each of the races, that's only activated if that specific race is set to playable.

That would no longer be the dfhack.init, but rather an init file in the raw folder, that's save specific.
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 :::

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #17 on: September 22, 2019, 09:44:11 am »

Thanks. I am looking through your warlock mod now trying to understand this.

So, for example: would a mod that only contains one file in \hack\scripts\classes called learn-skill.lua with the following code work as a mod? (this is the code from your warlock mod)

Code: [Select]
-- classes/learn-skill.lua v0.8 | DFHack 43.05

local utils = require 'utils'

validArgs = utils.invert({
 'help',
 'unit',
 'spell',
 'override',
 'verbose'
})
local args = utils.processArgs({...}, validArgs)

if args.unit and tonumber(args.unit) then
 unit = df.unit.find(tonumber(args.unit))
else
 print('No unit declared')
 return
end

if args.spell then
 spell = args.spell
else
 print('No spell declared')
 return
end

verbose = false
if args.verbose then verbose = true end

if args.override then
 yes = true
else
 yes = dfhack.script_environment('functions/class').checkRequirementsSpell(unit,spell,verbose)
end
if yes then
 success = dfhack.script_environment('functions/class').changeSpell(unit,spell,'add',verbose)
 if success then
 -- Erase items used for reaction
 end
 else
 if verbose then print('Unit does not meet the spell requirements') end
end


There doesn't appear to be anything added to the dfhack.init file that "turns this code on"?

Code: [Select]
multilevel 10
#s#eason-palette start
twbt unit_transparency 1
twbt workshop_transparency 1
twbt redraw_all 1
multilevel shadowcolor 0 0 0 0.6
multilevel fogcolor 0.1 0.1 0.17
multilevel fogdensity 0.30 0.25 0.75
#r#ealcolors

fix-sentient-butcher

startdwarf 7
points 1504

In other words, can a single .lua file be enough on it's own for dfhack to use without any changes to anything else including the dfhack.init file?

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #18 on: September 22, 2019, 10:17:35 am »

Actually, it looks like your cultural exchange mod is just one file with a list of mod tool commands (besides the custom reactions, buildings and art)? OnLoad? Is that a .lua file? So, I assume a single .lua file could make a mod (using vanilla raws)?

Code: [Select]
modtools/reaction-trigger -reactionName MIGRANT_GOBLIN_FEMALE -command [ modtools/create-unit -race GOBLIN -caste FEMALE -setUnitToFort -name EVIL -location [ \\LOCATION ] -age 13 ]

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Holidays
« Reply #19 on: September 22, 2019, 11:32:55 am »

You mixed up a few things.

Lua file = the script you want to use.

Init file (onload.init for example) = the file that tells the game when and how to use the script.

The cultural exchange mod I wrote makes use of already existing dfhack scripts, that's why I didn't have to include anything new. Only tell the game "use reaction trigger, if reaction X is completed, to trigger script Y with arguments Z".

In that case it's spawnunit and force caravan, with the fitting arguments to spawn/summon specific civs. I didn't have to write a new script for that.
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 :::

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #20 on: September 22, 2019, 01:47:55 pm »

You mixed up a few things.

Lua file = the script you want to use.

Init file (onload.init for example) = the file that tells the game when and how to use the script.

The cultural exchange mod I wrote makes use of already existing dfhack scripts, that's why I didn't have to include anything new. Only tell the game "use reaction trigger, if reaction X is completed, to trigger script Y with arguments Z".

In that case it's spawnunit and force caravan, with the fitting arguments to spawn/summon specific civs. I didn't have to write a new script for that.

Ah ok thanks. So a .init file is the only thing required if you are just using existing dfhack scripts? And then if you want to add your own scripts you need a lua file (edit: that the init file then uses)?
« Last Edit: September 22, 2019, 02:05:06 pm by brolol.404 »
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Holidays
« Reply #21 on: September 22, 2019, 02:49:50 pm »

The .lua file (or ruby) is literally the script. Yes, the .init would have a line that tells dfhack when to run the script in the .lua/.rb file. Or if it's a plugin, which .dll.
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 :::

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #22 on: September 22, 2019, 03:25:47 pm »

Alright cool thanks. I think I got it now.

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #23 on: September 22, 2019, 03:54:44 pm »

Can you tell me why this doesn't work? Nothing happens after the reaction.

\raw\bro_dftestspawn.init

Code: [Select]
modtools/reaction-trigger -reactionName brotest_REACTION -command [ modtools/create-unit -race GOBLIN -caste MALE -setUnitToFort -name EVIL -location [ \\LOCATION ] -age 13 ]
\raw\objects\reaction_brotest.txt

Code: [Select]
reaction_brotest

[OBJECT:REACTION]

[REACTION:brotest_REACTION]
[NAME:bro test]
[BUILDING:CARPENTER:CUSTOM_G]
[REAGENT:A:1:WOOD:NO_SUBTYPE:NONE:NONE]
[SKILL:CARPENTRY]

entity_default.txt
Code: [Select]
[PERMITTED_REACTION:brotest_REACTION]
The reaction happens. No product (as expected). No goblin spawned. No errorlog. dfhack installed and running.

Roses

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #24 on: September 22, 2019, 11:14:47 pm »

If using a different init file than the onLoad or onMapLoad you have to put your init file into those files. For example, in Meph's onMapLoad.init there are the lines

Code: [Select]
#################### Script files for each entity: ####################
:lua print(' ')
:lua print('Seeking to Initialize your Civilization')
modtools/if-entity -id "MOUNTAIN" -cmd [ script "raw/dwarf_init.txt" ]
modtools/if-entity -id "KOBOLD" -cmd [ script "raw/kobold_init.txt" ]
modtools/if-entity -id "ORC" -cmd [ script "raw/orc_init.txt" ]
modtools/if-entity -id "PLAINS" -cmd [ script "raw/human_init.txt" ]
modtools/if-entity -id "SUCCUBUS" -cmd [ script "raw/succubus_init.txt" ]
modtools/if-entity -id "HERMIT" -cmd [ script "raw/hermit_init.txt" ]

Now obviously, since you are just testing you can either add your modtools/reaction-trigger to an onLoad.init OR call your bro_dftestspawn.init from the onLoad.init itself

At least I think that is how it works, it's been a long time since I've played around with the init files and custom inits
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Holidays
« Reply #25 on: September 23, 2019, 06:28:11 am »

I think what Brolol wanted to do is use a custom-named init, so that he doesn't have to add lines to the OnLoad or onMapLoad files, in case other mods already have them. Avoiding overwriting files. ;)
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 :::

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #26 on: September 23, 2019, 07:16:33 am »

@Roses thanks :) I will try this out

I think what Brolol wanted to do is use a custom-named init, so that he doesn't have to add lines to the OnLoad or onMapLoad files, in case other mods already have them. Avoiding overwriting files. ;)

Yeah. That was the idea, but it sounds like at least one line is required in OnLoad.init or OnMapLoad.init to call the custom init?

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #27 on: September 23, 2019, 12:12:35 pm »

So, if I can figure out how to write a script in lua, this is what I am thinking that the syntax would look like in the init file to do a command (e.g. summon a creature) based on the date:

Code: [Select]
modtools/date-trigger -date 0315 -command [  ]
-date being MMDD starting with 01 being Opal and each month having 28 days.

I am thinking that the script would keep track of ticks and convert them into a date 0101 to 1228.

I would have to add ticks to the number to start the date at 0315 for a new fortress, but the complication comes, because the game doesn't always start on 0315 (e.g. retired/abandoned fortress).

DF does keep track of the date (YY-MM-DD) though so I wonder if there is just an easier way to use that and not count ticks.

Roses

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #28 on: September 23, 2019, 01:16:18 pm »

Well, if you want sometime to happen on a specific day of the year, you just need to convert that day into the correct tick, with 1200*28*12 ticks in a year. So if you wanted a script to run on 0315 thats 1200*(2*28+15). Then you just set up a timeout callback using dfhack.timeout. It should look something like this;

Code: [Select]
year_ticks = 1200*28*12
current_tick = df.global.cur_year_tick
holiday_tick = 1200*(2*28+15)
ticks = holiday_tick - current_tick
if ticks < 0 then
 ticks = ticks + year_ticks
end
dfhack.timeout(ticks+1,'ticks',holiday_function)

That way every time you start up the game it will calculate how many ticks are between that particular time and when the holiday script should be run and sets up a timeout that will run at that number of ticks. Then you just need to make sure that the holiday function sets up the next timeout so that if someone plays for more than a year of in game time in one sitting they don't miss any of the holiday changes.
Logged

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #29 on: September 23, 2019, 04:25:12 pm »

Well, if you want sometime to happen on a specific day of the year, you just need to convert that day into the correct tick, with 1200*28*12 ticks in a year. So if you wanted a script to run on 0315 thats 1200*(2*28+15). Then you just set up a timeout callback using dfhack.timeout. It should look something like this;

Code: [Select]
year_ticks = 1200*28*12
current_tick = df.global.cur_year_tick
holiday_tick = 1200*(2*28+15)
ticks = holiday_tick - current_tick
if ticks < 0 then
 ticks = ticks + year_ticks
end
dfhack.timeout(ticks+1,'ticks',holiday_function)

That way every time you start up the game it will calculate how many ticks are between that particular time and when the holiday script should be run and sets up a timeout that will run at that number of ticks. Then you just need to make sure that the holiday function sets up the next timeout so that if someone plays for more than a year of in game time in one sitting they don't miss any of the holiday changes.

Awesome thanks.

So I'm trying to digest this.

I assume that the following are all new custom variables that we are creating in the lua file. Do they need to be defined first as int or is that not needed in lua?

Code: [Select]
year_ticks = 1200*28*12
current_tick = df.global.cur_year_tick
holiday_tick = 1200*(2*28+15)
ticks = holiday_tick - current_tick

Is the following a function that dfhack already knows? Does it return the current year tick? Is there a list of these and what they do somewhere?

Code: [Select]
df.global.cur_year_tick
If that's true, couldnt the if statement just be:

Code: [Select]
if current_tick == holiday_tick then
 [do something]
end

Is the following another pre-defined dfhack function? I assume that this stops the script and returns a variable for use elsewhere? Is the holiday_function the variable/value that is being returned from this script?

Code: [Select]
dfhack.timeout(ticks+1,'ticks',holiday_function)
How does this script return back to the init file to run a command off of that date?

I'll watch a youtube video on some basic lua syntax to get a better understanding of how to read the code.
Pages: 1 [2] 3 4 ... 8