Project Zomboid

Project Zomboid

[B42/41] Reactive Sound Events
Can I fix the mod's event probabilities?
I took a look at this mod's code. I don't know lua but I do know javascript, which is somewhat similar. It seems the way it calculates the probability any event will happen is overly complicated and nearly impossible to understand for users (no offense to the author).



Long technical explanation ahead. It uses the default settings as an example:

Basically, the first time the mod starts, a counter starts ticking up. This counter starts at 0 and increases by 1 every in-game minute. Once this counter reaches Minimum Event Cooldown, an event will attempt to fire.

When it tries to fire, it takes the Minimum Event Cooldown, multiplies it by 100, then divides that by Maximum Event Cooldown.
With the default settings, this would result in an 11.1111...% of an event happening every 10 in-game minutes. Once an event happens, the counter will turn back to 0 and attempt to fire again 240 minutes later. This seems to use a vanilla looping function called EveryTenMinutes. I think lots of mods use it so it's not an issue.

Every time it fails the 11.1111...% check, it increases the chance by (I can't even explain this in words so I'll just paste the code): (100-modData.baseEventChance)/((maxCD-minCD)/10), which results in roughly 0.4629...%

This all means that after Minimum Event Cooldown has elapsed, there is a (not really due to cumulative probability but for the sake of simplicity) 66.6666... + 2.7777...% per in-game hour that an event will fire.



I'm asking if I can repost this mod with these parts of the code modified, or if you could modify it in a future update.

I would do away with Minimum and Maximum Event Cooldowns and use a simple to understand percentage setting: "Chance per hour an event may happen." Say the user chooses 5%, I would simply divide that by 6 because I would use the EveryTenMinutes function you're already using.
So in this case it would have a 0.83333...% chance of happening every 10 minutes, which would equal ~5% after 60 minutes (actually 4.9% or something due to the aforementioned cumulative probability. The margin or error increases the farther from 0% it goes).

Thanks.
Last edited by KemonoAmigo; 20 hours ago