mIRC Home    About    Download    Register    News    Help

Print Thread
#142233 17/02/06 06:06 AM
Joined: Feb 2006
Posts: 95
B
blk Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Feb 2006
Posts: 95
In..
Code:
on *:text:!example*:*:{
  if ($2- == test) {
    /commands
  }  
  else /commands
}

Is there anyway to search the whole $2- for the word test?
I was thinking add wildcards to make it *test*, but I guess you cant do that...


-blk-
#142234 17/02/06 06:25 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
(1) For a start group blocks of commands inside { } if there on an IF or a ELSEIF or a ELSE
You only showed one "/coimmands" on your else but u did use a s on command so im assuming it might have been more than one.

(2) commands in scripts dont need / (incase u didnt know, as here your only infering commands here I often put one in as well)

on to your problem

if you just want to know if the word TEST is in the $2- then its (TEST isin $2-) this well pick up aas true testing and fatest since test is present in each

if you want to see if TEST is a word on its own in $2- then ($istok($2-,TEST,32)) this well pick up "the test was easy" but wont pick up "the fatest kid came last"

$istok(<string>,<text>,N) is a $true or $false reply. It works by taking <string> and chopping it up into bits, it finds each spot to chop at by using the ASCII value N as the spot to chop at, in this case 32 which is " " (space), so it chops at each word, then it takes each of these chopped bits and sees if one is the same as <text>, if it is it comes back with $true, else it comes back with $false

Just so you understand $istok, ill show you one $istok(the.cat.sat on.the.mat,cat,32) $FALSE, becuase it chopped on the 32 the space so the first one was "the.cat.sat" and 2nd was "on.the.mat", however $istok(the.cat.sat on.the.mat,cat,46) $TRUE , 46 = ASCII for "." so it chopped up as "the" "cat" "sat on" "the" "mat" and it found "cat"

#142235 17/02/06 07:06 AM
Joined: Feb 2006
Posts: 95
B
blk Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Feb 2006
Posts: 95
yea, my bad on 1..
I always forget to do 2..

and I'll use the $istok one..
Now if people use like "!example test" with bold it goes around it....
Is there a way to check for that?
-----------------------------------------------------------
this is right.. right?
[code]on *:text:!example*:*:{
if ($istok($2-,test,32)) {
commands
}
else {
commands
}
}


-blk-
#142236 17/02/06 07:20 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
If you know or suspect that the command will or might have bold, underlining, color, and/or reversed characters, here are two ways to handle it
Code:
 on *:text:!example*:*:{
if ($istok($strip($2-,burc),test,32)) {
commands
}
else {
commands
}
}
 

That will strip the bold, underlining, reverse and colors from $2- before checking if test is a token in the line

The problem I have with doing it that way, is that you have to use the $strip(<text>,burc) each and every time. So if you have, for example 100 entries that need to be checked, then you have to add that each time

This next one is a one time running (each time you start/load the code, of course)
Code:
on *:start: .strip +burc  


Just add that one line to any script or have it by itself. What it does, is it automatically strips the bold, underlining, reverse and colors from any text received.

With the second code, that I posted, what you currently have will work.

P.S: If you don't want all of those things removed, just don't use the appropriate letter for the item(s) you don't want removed.

Last edited by RusselB; 17/02/06 07:21 AM.
#142237 17/02/06 07:32 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Not that russels method is wrong i just dont like having stripping turned on

Code:
on *:text:!example*:*:{
  tokenize 32 $strip($1-)
  if ($istok($2-,test,32)) {
    commands
  }  
  else {
    commands
  }
}


The tokenize N <string> command works much like the method the $istok works on in chopping up <string> on the ascII value of N (in this case space), but with this command it loads it into $1- so essentially tokenize 32 $strip($1-) removes all color bold etc codes from the event text, i didnt use any second field in $strip as it defuialts to them all if u dont use one.

#142238 17/02/06 07:41 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
For my own scripts, I don't usually have the stripping on, but I found it a lot easier to code my bots by putting it in, rather than stripping it from each and every event that can carry a color, etc. code. I have one bot that when I finished coding it, but before I started condensing it, had nearly 1000 on text, on notice & on action events.

And I did give him another alternative that almost matches yours first.

#142239 17/02/06 08:07 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Dont take it to heart, i said there was nothing wrong with what ya did, I just dont like having stripping on.


Link Copied to Clipboard