Page 1 of 1

Math help: dynamic throttle based on #players

Posted: Fri Oct 28, 2016 2:38 am
by aubergine18
I'd like to try and throttle a frivolous mod based on number of players in game. So when there are very few players, I don't want the mod throttled, but as more players join I want to throttle the mod so it doesn't cause message spam.

I can easily determine the number of players: #game.players

But I'm too useless at math to think of a decent, non-desyncable way to calculate the throttle.

The throttle calculation would only be performed when a player dies, and even then if that death is not ignored due to throttling.

The resulting value will be added to game.tick to determine when the event can next be processed, sort of like this:

Code: Select all

local delay = 60 -- ticks
local threshold = 0

function handle_event( event )
  if event.tick < threshold then return end

 -- something to calculate new `delay` value based on `#game.players`

  threshold = event.tick + delay

  -- handle event
end
I'd ideally want lower and upper bounds for the delay, eg. min 1 minute, max 10 minutes.

Re: Math help: dynamic throttle based on #players

Posted: Fri Oct 28, 2016 3:24 am
by DaveMcW
aubergine18 wrote:non-desyncable
Store everything in global. Initialize it in script.on_init.


The math is pretty simple. Multiply the delay by number of players. Pick delay so that it works out to 1 minute for a low number of players and 10 minutes for a high number of players. If you want a hard cap of 1-10 minutes, do some if statements at the end.