mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2008
Posts: 8
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Oct 2008
Posts: 8
Still a bit new to mirc scripting, but wanted to make a small script that would count server connections, and that would trigger if %x = 20 connects in y time.

Any suggestions?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
You can count the number of open status windows (whether connected or not), using $scon(0)
Note that is a 0 (zero) not an O (oh)

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
To count some action in a set amount of time, you can use something like this:

Code:

alias test {
  inc -u30 %counter 1
  if (%counter >= 20) {
    return 1
  }
  else {
    return 0
  }
}



This code will increment once each time it is called. If the counter is higher than 19, it will return a 1, otherwise it will return a 0. Obviously, you would modify this code to fit into an event or raw.

-genius_at_work

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
oh boy if i had a penny for every time someone has fallen into this trap ;>

i've written at length about this before but i'll just summarize for now:

Code:
//inc -uY %var | if (%var >= X) {


this, similar to what was mentioned above, doesn't really trigger for a given number of reps per time interval, but rather for Y times in up to (X-1)*Y seconds (as long as each gap in time is no more than Y seconds of course). depending on the actual delays, this has the potential to be a lot more sensitive than a true X times in Y secs

Code:
//inc -z %var Y | if (%var > (X-1)*Y) {


this is a more accurate "X times in Y seconds" detector

so for 20 times in 30 seconds:

Code:
//inc -z %var 30 | if (%var > 570) {


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
You may alternatively use a hash table, adding an item to the table for every *whatever* action that unsets after N seconds.
Advantages of this method:
- hash tables are ~ as fast as variables
- all data will be destroyed (unless saved) on exit - no need to care for unsetting variables on start (e.g. in case of a crash)
- each item unsets separately: you can check precisely for the current No. of items
- you may perform wildcard checks (if item and / or data was named properly)

Example 1
Code:
alias test {
; add to table "test" for 20 seconds a random-named item with dummy data "x" 
  hadd -mu20 test $rand(1,99999) x

  if ($hget(test,0).item < 5) { ECHO -a triggered "test" less than 5times in the last 20 seconds }
  else { ECHO -a triggered "test" $hget(test,0).item times in the last 20 seconds }
}

Example2 to illustrate some wildcard checks
Code:
; on join of a user: add to table "joins" for 180 seconds a random-named item with data "<connectionID>chr1<channel>chr1<nick>" . 
on *:join:#: {
  hadd -mu180 joins $rand(1,99999) $+($cid,$chr(1),$chan,$chr(1),$nick)

  ECHO -a total No. of joins (all connections, all channels) (last 30s): $hget(joins,0).item
  ECHO -a No. of joins on this connection $cid (last 30s): $hfind(joins, $+($cid,$chr(1),*) ,0,w).data
  ECHO -a No. of joins on this connection $cid and this channel $chan (last 30s): $hfind(joins, $+($cid,$chr(1),$chan,$chr(1),*) ,0,w).data
  ECHO -a No. of joins of the nick $nick on all connections (last 30s): $hfind(joins, $+(*,$chr(1),$nick) ,0,w).data
}

Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Originally Posted By: jaytea
oh boy if i had a penny for every time someone has fallen into this trap ;>


Code:
//inc -z %var 30 | if (%var > 570) {


Unfortunately you kind of fell into the same trap. (I expected more out of you, jaytea!) If someone triggers that 19 times in a split second, the var will be at 570, which means if you waited 4 minutes, and then did that command 9 more times, the %var would be around 600. (If the %var == 570, it'd take 9.5 mins to fully unset.)


Edit: Personally, I'd go with the hash table way. Though as a little example of other fun ways to handle things just like this, you could use something like:

Code:
alias altway {
  var %d = $calc($ctime - 30)
  while ($gettok(%altway,1,32) < %d) { set -k %altway $deltok(%altway,1,32) }

  set -u30 %altway $addtok(%altway,$ctime,32)

  if ($numtok(%altway,32) > 19) { echo -a ITS OVER 9000! Er, I mean over $v2 :( }
}

Last edited by Rand; 18/03/09 01:45 AM.

Link Copied to Clipboard