Math help: dynamic throttle based on #players
Posted: Fri Oct 28, 2016 2:38 am
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:
I'd ideally want lower and upper bounds for the delay, eg. min 1 minute, max 10 minutes.
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