Project Zomboid

Project Zomboid

B42 Native ModOptions Example
30 Comments
TeeJaaY 2 Jul @ 1:43pm 
this isnt a mod for anyone wondering. its nothing if you got here trying to get bandits to work
Michels 1 Jun @ 10:17am 
great work soldier
nakhrin 6 Apr @ 2:48pm 
Thanks cdshmirtz
cdshmirtz 4 Apr @ 4:12pm 
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 Apr @ 1:58pm 
Does this mod has any dependency on another mod? I don't recall downloading it.
Viruana 7 Mar @ 3:32pm 
Appreciate it so much!!!
Lightja 1 Feb @ 6:35pm 
legend!
Kyu 14 Jan @ 8:40am 
@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 Jan @ 7:25am 
no matter what i do i can not get this mod to show up in game. i have tried everything.
No' 11 Jan @ 5:09am 
Thanks for your work !
Arsenal[26] 11 Jan @ 1:02am 
Thanks dhert, good stuff
dhert  [author] 30 Dec, 2024 @ 5:50pm 
@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 Dec, 2024 @ 3:10pm 
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 Dec, 2024 @ 12:15pm 
@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://steamhost.cn/steamcommunity_com/workshop/filedetails/discussion/3386860561/595136643598386903/
NICETRY 23 Dec, 2024 @ 1:33am 
Thanks for the work done, very useful information.
N0wh3re 22 Dec, 2024 @ 5:09am 
This guy is the best.
PePePePePeil 21 Dec, 2024 @ 6:43am 
@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  [author] 21 Dec, 2024 @ 6:13am 
@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 Dec, 2024 @ 4:18am 
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 Dec, 2024 @ 7:08am 
Thanks, this is a helpful way to show the options.
Kyu 20 Dec, 2024 @ 2:51am 
@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 Dec, 2024 @ 11:46pm 
Just wanted to say that this was very helpful. Thank you!
dhert  [author] 19 Dec, 2024 @ 11:06pm 
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 Dec, 2024 @ 9:49pm 
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  [author] 19 Dec, 2024 @ 2:09pm 
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 Dec, 2024 @ 1:40pm 
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 Dec, 2024 @ 1:37pm 
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 18 Dec, 2024 @ 4:45pm 
You deserve a lot of good things and happy holidays <3
poopie pants 18 Dec, 2024 @ 12:58pm 
Awesome!
Tchernobill 18 Dec, 2024 @ 12:51pm 
you're precious