Project Zomboid

Project Zomboid

B42 Native ModOptions Example
35 kommenttia
Dustin 14.8. klo 1.54 
Please put this on github so we don't need to download a workshop mod to enjoy your work.
Robob27 5.8. klo 3.26 
The mod is not necessary for anything, it won't make anything work, nothing will show up in game. It's simply example code to help other mod developers learn how to expose options for their mods. That's it, that's all.
Apathy 28.7. klo 7.51 
Is it compatible with Britas?
Sweggles11 27.7. klo 12.19 
So is this necessary for Bandits in build 42 or nah?
ReZpawner 23.7. klo 11.07 
So this is getting pretty confusing - is this needed for Bandits in B42 or not? A lot of the information here seem to be conflicting.
TeeJaaY 2.7. klo 13.43 
this isnt a mod for anyone wondering. its nothing if you got here trying to get bandits to work
Michels 1.6. klo 10.17 
great work soldier
nakhrin 6.4. klo 14.48 
Thanks cdshmirtz
cdshmirtz 4.4. klo 16.12 
nakhrin, it is revolved around the Bandits mod, and this is the option for B42 users. At least that's how I got here.
nakhrin 3.4. klo 13.58 
Does this mod has any dependency on another mod? I don't recall downloading it.
Viruana 7.3. klo 15.32 
Appreciate it so much!!!
Lightja 1.2. klo 18.35 
legend!
Kyu 14.1. klo 8.40 
@Ivechy - Are you on build 42? Did you customize your own script for creating the options you want?

If so, create a discussion with your script and maybe I can help!
Invechy 14.1. klo 7.25 
no matter what i do i can not get this mod to show up in game. i have tried everything.
No' 11.1. klo 5.09 
Thanks for your work !
Arsenal[26] 11.1. klo 1.02 
Thanks dhert, good stuff
dhert  [tekijä] 30.12.2024 klo 17.50 
@molecule31 - This is a known issue that has been reported to the developers. The "Save" function for the new ModOptions saves to the file "ModOptions.ini". However, the "Load" function uses file "modOptions.ini". On Windows, this would be the same file. On Linux, this is 2 different files.
molecule31 30.12.2024 klo 15.10 
Hey, apparently, the mod menu on the Linux build works but does not save parameters I've banging my head against the wall for more than a week and all I had to do was put pz through proton to make the mod menu work, I'm so frustrated now
Notloc 28.12.2024 klo 12.15 
@dhert @PePePePePeil
There actually is a callback, but its for the whole object, not specific settings.
Your modOption object has an apply function you can override that is called whenever the user applies settings

Discussion link because comments do not allow adequate formatting:
https://gtm.steamproxy.vip/workshop/filedetails/discussion/3386860561/595136643598386903/
NICETRY 23.12.2024 klo 1.33 
Thanks for the work done, very useful information.
N0wh3re 22.12.2024 klo 5.09 
This guy is the best.
PePePePePeil 21.12.2024 klo 6.43 
@dhert
Thank you for your response and development request. I was hoping to process it only once when it is changed instead of every time to improve processing performance, I look forward to the ModOptions update, thank you! :spiffo:
dhert  [tekijä] 21.12.2024 klo 6.13 
@PePePePePeil - Unfortunately no, there's no function called when you change your options that you can hook in to. You'll just either have to keep querying your options directly when needed.
There's a "Modding Request" thread on the official Zomboid Discord, and I requested that an event be created when changes are applied (even provided a snippet of code for them to accomplish this), so hopefully there will be an event in a future update that you can use to re-read all of your settings.
PePePePePeil 21.12.2024 klo 4.18 
Hello, thank you for providing a new sample of ModOptions. It is very helpful. Previously, with the Mod Options Mod, it was possible to hook into the OnApplyInGame function to perform some processing when settings were changed. Is it possible to achieve the same functionality with the ModOptions in Build 42?
Nepenthe 20.12.2024 klo 7.08 
Thanks, this is a helpful way to show the options.
Kyu 20.12.2024 klo 2.51 
@dhert - Thanks for checking! I decided to go with changing to booting of my mod to when the save loads. This was super helpful and I credited you in my B42 mod. You rock!
Slayer 19.12.2024 klo 23.46 
Just wanted to say that this was very helpful. Thank you!
dhert  [tekijä] 19.12.2024 klo 23.06 
There are no additional parameters, its just PZAPI.ModOptions:load().
The settings are loaded as part of the GameBoot, you're correct (specifically when the MainScreen's object is created).
That said, instead of calling load yourself and reading your options immediately after creating them, I would recommend adding an OnGameBoot function of your own to parse the values and set any local variables you need. Or, you can wait until OnGameStart since most options are typically unused until you start the game anyways.
I think it's probably best that all mods have a chance to load and create their options first, before the mod options load is performed.
Kyu 19.12.2024 klo 21.49 
Hey, Dhert! I was looking into this and found that the mod options are not loaded until sometime after the "OnGameBoot" event. I was poking around and saw PZAPI.ModOptions:load() and figured I could maybe force a load earlier in the process but I'm not sure what parameters that method is expecting. Any ideas?
dhert  [tekijä] 19.12.2024 klo 14.09 
Ha. I thought I mentioned that in some of the comments and tooltips.
But yea, for most of them its just "option:getValue()"
You don't have to store all of the configs like I did either. You can get your "options" table anytime via:
local options = PZAPI.ModOptions:getOptions("UNIQUEID")

Then get your individual options with:
local option = options:getOption("OptionID")
Tchernobill 19.12.2024 klo 13.40 
ok, for most of it, it is config.option:getValue()But
You you let me think Dhert.. it was supposed to be YOUR job, not mine :steammocking:
Tchernobill 19.12.2024 klo 13.37 
Did I missed it or the way to extract the config option value at runtime is not described ?
I think the way to get the option object is, but how do we extract something from it ?
Mxswat The Helldriver 18.12.2024 klo 16.45 
You deserve a lot of good things and happy holidays <3
Sheriff Catnip 18.12.2024 klo 12.58 
Awesome!
Tchernobill 18.12.2024 klo 12.51 
you're precious