mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
ok i'm still learning scripting so i'm sort of making a game where if a number is said anywhere in the text a message will display. I need the script to activate if the number in the text line is 100000 or anything greater. All i need to know is how to get the script to activate once the right number has been said. Everything else i think i can handle on my own, hopefully lol.

Also if the number has a comma in it for example 100,000 will that make a difference and if so how can i make it still work?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
There may be more efficient ways of doing this, but here's an option.
Code:
on *:text:*:#:{
  var %a = 1, %b = $0
  while %a <= %b {
    if $remove($gettok($1-,%a,32),$chr(44)) isnum 100000- {
      .msg $chan The number $gettok($1-,%a,32) was said.
    }
    inc %a
  }
}

Note: This will activate for every number that is said if the number is 100000 or higher.
If one person said 100010 100,020
Then the script will activate twice. Once for the 100010 and once for the 100,020.

Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
ok one last thing, some of the numbers will have a $ sign in front so for example if $100,000 was said how do i get the script to activate on that text aswell?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Change $remove($gettok($1-,%a,32),$chr(44)) to $remove($gettok($1-,%a,32),$chr(44),$chr(36))

Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
Thanks a bunch! Also if i want the script to respond to something in colored text code, how would i do that without turning on color stripping in mirc options? Or is that the only way?

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Code:
on $*:text:/^(\44?\d{3}\54?\d{3,})/S:#:.msg # The number $regml(1) was said.
Use regex without a while loop for this. This also strips out control codes.

Please note this is based upon the example you've shown. There might be a possibility it'll fail if you have numbers like this:
Quote:
$1,264.10
for example. The regex may need to be modified.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
That's definitely better if you only have one large number in a line. Otherwise, you'll only show the first. I'd still use regex even if you want multiple results... I'd just change it to display all of the $regml()'s.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Riamus2, if you don't mind, could you please show me your apporach with this? ^^ Much obliged.

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
If you still want to go with RusselB's code and to have the control codes stripped, just enclose
Code:
$1-
like this:
Code:
$strip($1-)

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
My regex is not very good yet and I'm having trouble making yours work within $regex() for testing (for example, I'm not sure what \54 is doing), but basically I'd just make it greedy so it will fill multiple $regml()'s with all results and then loop through until $regml(0) and create the output that way. If there's a better way, I'm not sure.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Riamus2, \54 is an octal character and is equivalent to \x2C and mIRC's $chr(44)

And \44 is the same as \x24 and $chr(36)

It's force of habit I use the octal chars. You can do it as \$ for it to be escaped with a backward slash \ , since the dollar sign in regex has its special meaning. For the comma, though, it's not necessary to make it literal. I hope this clears up your confusion.

P.S. you should be able to find a list of octal characters by googling one.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok, I see. I thought those should be relating to the $ and comma, but the \44 threw me off since 44 is the $chr for comma and then 54 didn't make sense. I didn't think of octal. laugh


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
I changed $remove($gettok($1-,%a,32),$chr(44),$chr(36)) to $remove($gettok($strip($1-),%a,32),$chr(44),$chr(36)) but it still refuses to work if the text is using color codes. frown


Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
Originally Posted By: Tomao
Code:
on $*:text:/^(\44?\d{3}\54?\d{3,})/S:#:.msg # The number $regml(1) was said.
Use regex without a while loop for this. This also strips out control codes.

Please note this is based upon the example you've shown. There might be a possibility it'll fail if you have numbers like this:
Quote:
$1,264.10
for example. The regex may need to be modified.


I tried this code too and it didn't seem to work, also this type of scripting is kind of over my head.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Here's my code with the various changes that you've requested implemented.
Code:
on *:text:*:#:{
  tokenize 32 $strip($1-)
  var %a = 1, %b = $0
  while %a <= %b {
    if $remove($gettok($1-,%a,32),$chr(44),$chr(36)) isnum 100000- {
      .msg $chan The number $gettok($1-,%a,32) was said.
    }
    inc %a
  }
}


Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I made a foolish mistake. I initially had the caret sign used, which would mean that the regex has to make a match starting with a number or $, or else it will fail. I have corrected the issue and tested it:
Code:
on $*:text:/(\44?\d{3}\54?\d{3,})/S:#:{
  .msg # The number $regml(1) was said.
}
Please be noted that this is not a foolproof regex but will work to match all the number patterns you've shown us. If you encounter a set of numbers like
Quote:
$1,264,543.10
, both RusselB's and mine will fail to match.

Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
That's ok Tomao my script won't be dealing with decimals, at least not anytime soon.

Thank you everyone i think that's all i need. smile

Last edited by ohaithar; 13/02/11 05:33 AM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
You're welcome, ohaithar. RusselB's and mine work pretty much the same in the functionality per se, but without the loop and the process steps using $remove and $gettok...I'd say my regex method is going to be faster. Again, I'm not criticizing RusselB's code. He's done a good job at getting your request fulfilled just as dandy.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Quote:
If you encounter a set of numbers like
Quote:
$1,264,543.10
, both RusselB's and mine will fail to match.


I disagree that my code will not match that number.

While I haven't actually tested it (too tired to do so now), my code should work fine for a number like that using the following method.

Comments added to code to show how I believe that my code will work fine for a number like that.
Code:
on *:text:*:#:{
  ;number entered as $1,264,543.10
  tokenize 32 $strip($1-)
  ;control codes stripped and line re-evaluated with standard spaces being token separators.
  var %a = 1, %b = $0
  while %a <= %b {
    if $remove($gettok($1-,%a,32),$chr(44),$chr(36)) isnum 100000- {
     ;$gettok($1-,%a,32) on the first loop where %a = 1, becomes $1,264,543.10
     ;commas and dollar sign removed using $remove leaving 1264543.10
     ;check if 1264543.10 is equal to or greater than 100000
     ;comparison shows true, thus a message using the original entered number $1,264,543.10 is posted back to the channel.
     .msg $chan The number $gettok($1-,%a,32) was said.
    }
    inc %a
    ;var %a increases by 1, making it 2, which is outside of the loop limit, thus ending the loop.
  }
}


Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Yes, I apologize. It does work for numbers with decimals. I didn't test your code initially but was eyeballing it. I should have done so. For some odd reason, though, mine works now to trigger upon the decimals too, just as yours. I modified it a little to improve it:
Code:
on $*:text:/(.*?\44?\d{3}\54?\d{3,}.*)/S:#:{
  .msg # The number $regml(1) was said.
}
You're welcome to make a comparison between these two methods and see which one is more efficient.


Link Copied to Clipboard