Difference between revisions of "Autolimiter"
From Scriptwiki
m (Explained, structured) |
|||
Line 3: | Line 3: | ||
It is a prerequisite to set the limit amount for each channel (a positive integer) using variables in the format of '''%limit.#CHANNEL''', or otherwise changing the format used in the script. | It is a prerequisite to set the limit amount for each channel (a positive integer) using variables in the format of '''%limit.#CHANNEL''', or otherwise changing the format used in the script. | ||
+ | /* | ||
+ | This script simply sets a limit to N users + limit amount | ||
+ | whenever someone enters or leaves the channel. The comments | ||
+ | laid out here should describe what is happening within the | ||
+ | script. Made by Daveoh @ QuakeNet. | ||
+ | */ | ||
+ | |||
+ | |||
+ | /* | ||
+ | The following three events are triggered whenever someone | ||
+ | joins, parts or is kicked from a channel. These events | ||
+ | are all channel associated so we pass the autolimit alias | ||
+ | the channel we want to limit. | ||
+ | */ | ||
on @*:JOIN:#:autolimit # | on @*:JOIN:#:autolimit # | ||
on @*:PART:#:autolimit # | on @*:PART:#:autolimit # | ||
on @*:KICK:#:autolimit # | on @*:KICK:#:autolimit # | ||
+ | |||
+ | |||
+ | /* | ||
+ | The on QUIT event is not channel associated, meaning we | ||
+ | must loop through all the common channels we are on with | ||
+ | whoever quit and pass these to the autolimit alias. | ||
+ | */ | ||
on *:QUIT:{ | on *:QUIT:{ | ||
var %i = 1 | var %i = 1 | ||
while ($comchan($nick,%i)) { | while ($comchan($nick,%i)) { | ||
+ | ;$comchan returns the Nth common channel which you and the specified user is on. | ||
autolimit $v1 | autolimit $v1 | ||
+ | ;$v1 will refer to $comchan($nick,%i) each time the loop is ran. | ||
inc %i | inc %i | ||
} | } | ||
} | } | ||
− | alias -l autolimit if ($me isop $1 && !$timer(autolimit. $+ $1)) && (%limit. [ $+ [ $1 ] ] ) .timerautolimit. $+ $1 1 10 mode $1 +l $!calc( $!nick( $1 ,0) + $v1 ) | + | |
+ | |||
+ | /* | ||
+ | Here we have the alias, this will perform several checks | ||
+ | and then use a timer to determine when the limit is set. | ||
+ | */ | ||
+ | alias -l autolimit { | ||
+ | ;The -l switch means this alias can only be accessed from within this script. | ||
+ | if ($me isop $1) && (!$timer(autolimit. $+ $1)) && (%limit. [ $+ [ $1 ] ] ) { | ||
+ | ;We check that we are op on the specified channel, that a timer isn't already active and that a limit variable is set. | ||
+ | .timerautolimit. $+ $1 1 10 mode $1 +l $!calc( $!nick( $1 ,0) + $v1 ) | ||
+ | ;The identifiers in this timer will only be evaluated when the timer is triggered, meaning the user count can change in between starting the timer and running it. | ||
+ | ;This is achieved with $!, which leaves the identifier unevaluated, evaluating when the timer is ran. | ||
+ | } | ||
+ | } | ||
{{Author|Daveoh}} | {{Author|Daveoh}} | ||
[[Category:Script Archive]] | [[Category:Script Archive]] |
Latest revision as of 12:09, 26 April 2008
This is a very simple yet effective autolimiter. It can be incorporated into a larger script easily, and is recommended to be in a script of its own unless you know how to merge it.
It is a prerequisite to set the limit amount for each channel (a positive integer) using variables in the format of %limit.#CHANNEL, or otherwise changing the format used in the script.
/* This script simply sets a limit to N users + limit amount whenever someone enters or leaves the channel. The comments laid out here should describe what is happening within the script. Made by Daveoh @ QuakeNet. */ /* The following three events are triggered whenever someone joins, parts or is kicked from a channel. These events are all channel associated so we pass the autolimit alias the channel we want to limit. */ on @*:JOIN:#:autolimit # on @*:PART:#:autolimit # on @*:KICK:#:autolimit # /* The on QUIT event is not channel associated, meaning we must loop through all the common channels we are on with whoever quit and pass these to the autolimit alias. */ on *:QUIT:{ var %i = 1 while ($comchan($nick,%i)) { ;$comchan returns the Nth common channel which you and the specified user is on. autolimit $v1 ;$v1 will refer to $comchan($nick,%i) each time the loop is ran. inc %i } } /* Here we have the alias, this will perform several checks and then use a timer to determine when the limit is set. */ alias -l autolimit { ;The -l switch means this alias can only be accessed from within this script. if ($me isop $1) && (!$timer(autolimit. $+ $1)) && (%limit. [ $+ [ $1 ] ] ) { ;We check that we are op on the specified channel, that a timer isn't already active and that a limit variable is set. .timerautolimit. $+ $1 1 10 mode $1 +l $!calc( $!nick( $1 ,0) + $v1 ) ;The identifiers in this timer will only be evaluated when the timer is triggered, meaning the user count can change in between starting the timer and running it. ;This is achieved with $!, which leaves the identifier unevaluated, evaluating when the timer is ran. } }
Contributed by Daveoh |