; ------------ CREATED BY Horstl @ mirc.com --------------

; you're joining one of your rooms: start a looping timer to check the limit of this chan. 
; modify #yourchan,#anotherchan to whatever chan(s) you want to limit.
on me:*:join:#yourchan,#anotherchan: {
  $+(.timer.channellimit.,$chan) 0 $int($limiter.intermission) limiter.update $chan
}

; how often to check (and maybe adjust) the userlimit?  (edit the number, it's seconds)
alias -l limiter.intermission { return 35 }

; how big may the offset between 'current limit' and 'optimum limit' be? (edit the number, it's seconds)
alias -l limiter.latitude { return 5 }

; this is the actual checking thingie (Don't modify it if you're not sure what you're doing)
alias limiter.update {
  if ($me isop $1) {
    ; a calculation of "optimum" limit (of my personal taste):
    ; it's comparing a soft limit (relative to the number of current users) to a hard limit (15).
    ; the lower of both will be used as 'optimum'
    var %soft = $round($calc($nick($1,0) * 1.05 +5),0), %hard = $calc($nick($1,0) +15), %should = $iif((%soft <= %hard),$v1,$v2)

    ; if the current limit has an offest of ± X to this optimum: set a new limit.
    if ($abs($calc(%should - $chan($1).limit)) >= $int($limiter.latitude)) { mode $1 +l %should }
  }
}