mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Mpot #212129 11/05/09 08:18 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
You had had a loop doing a "isin" check to compare every line of the textfile to the current message.
Instead of a check for isin, you could check for $istok, $findtok, or $matchtok.
With token identifiers you need to specify the char that is seaparating what you're looking for. As you're trying to match whole words, which are separated by spaces, it's "32" (the ascii value of a space is 32). Sorry for my bad explanation - have a look at /help token identifiers smile

The code I was refering to:
Code:
 var %n = 1
  while ($read(expletives.txt,n,%n)) {
    if ($v1 isin $1-) {
      kick $chan $nick Your message contained badword $qt($v1)
      break
    }
    inc %n
  }

The code, modified for "istok":
Code:
 var %n = 1
  while ($read(expletives.txt,n,%n)) {
    if ($istok($1-,$v1,32)) {
      kick $chan $nick Your message contained some badword
      break
    }
    inc %n
  }
Because istok will only return "$true" or "$false", you cannot have a direct reference to the matching word.
But of course you could $read the line again to get the "bad" word that was matched by the message: "Your message contained the badword $read(expletives.txt,n,%n)"

The code, modified for "findtok":
Code:
 var %n = 1
  while ($read(expletives.txt,n,%n)) {
    if ($findtok($1-,$v1,32)) {
      kick $chan $nick Your message contained the badword $gettok($1-,$v1,32)
      break
    }
    inc %n
  }
Findtok isn't returning $true or $false but the position of the matching token. With a gettok on the original message, you return the "bad" word that was matched.

Horstl #212131 11/05/09 08:35 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
So $v1 changes from the current line in the text file, to the number of the token that matched the line?

Also, I modified the original to work like this:

Code:
on *:text:*:: {
  var %n = 1
  while ($read(expletives.txt,n,%n)) {
    if ($v1 isin $1-) { 
      kick $chan $nick You said $read(kicks.txt,w,* $+ $v1 $+ *)
      break
    }
    inc %n
  }
}


I assume the correct modification is:

Code:
on *:text:*:: {
  var %n = 1
  while ($read(expletives.txt,n,%n)) {
    if ($v1 isin $1-) { 
      kick $chan $nick You said $read(kicks.txt,w,* $+ $gettok($1-,$v1,32) $+ *)
      break
    }
    inc %n
  }
}

?

Anyway, I appreciate the help. I'll have to look over this again when I'm not quite as exhausted, because I'm not quite getting the concept.

Thanks, Horstl.

Mpot #212133 11/05/09 09:21 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
$v1 is the first parameter of the last if-condition that was matched/true. $v2 would be the second parameter, given there is one.
Example:
Code:
//if (3 isnum 1-5) echo -a $v1 is a number in the range of $v2 

Another example:
Code:
if (%a <= %b) && (%b > %a) { echo -s %a }
is the same as:
Code:
if (%a <= %b) && ($v2 > $v1) { echo -s $v2 }

In this piece of code:
Code:
while ($read(expletives.txt,n,%n)) {
    if ($v1 isin $1-) {
This loop keeps looping as long as $read(expletives.txt,n,%n) returns something (OK, as pointed out by some previous posts, something that is neither 0 nor $false smile )
The "$v1" in "if ($v1 isin $1-)" is the value returned by $read = the line that was read.
Using $v1 in the kick reason works as well, because the value of the first parameter of "if ($v1 isin $1-)" is the very same:
" kick $chan $nick You said something that contains $v1 "


But in this piece of code:
Code:
while ($read(expletives.txt,n,%n)) {
    if ($findtok($1-,$v1,32)) {
      kick $chan $nick Your message contained the badword $gettok($1-,$v1,32)
The $v1 in "if ($findtok($1-,$v1,32))" is the value of the first (and only) parameter of the while - the text returned by $read.
However in the kick command, $v1 refers to the value of the first (and only) parameter of the condition "if ($findtok($1-,$v1,32))", which is not the line read but the position of the token in the text message $1-.

...wish I could explain this in a more intelligible way smirk


Horstl #212137 11/05/09 11:21 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
This tutorial has been throughly and helpfully useful, professor Horstl. Danke schön! wink

Tomao #212178 13/05/09 04:11 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
/me sets mode +leg_puller Tomao whistle

Page 2 of 2 1 2

Link Copied to Clipboard