mIRC Home    About    Download    Register    News    Help

Topic Options
#229633 - 12/02/11 03:34 AM help with random number on text
ohaithar Offline
Ameglian cow

Registered: 18/01/11
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?

Top
#229634 - 12/02/11 04:23 AM Re: help with random number on text [Re: ohaithar]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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.

Top
#229636 - 12/02/11 05:57 AM Re: help with random number on text [Re: RusselB]
ohaithar Offline
Ameglian cow

Registered: 18/01/11
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?

Top
#229658 - 12/02/11 10:30 PM Re: help with random number on text [Re: ohaithar]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
Change $remove($gettok($1-,%a,32),$chr(44)) to $remove($gettok($1-,%a,32),$chr(44),$chr(36))

Top
#229661 - 13/02/11 12:43 AM Re: help with random number on text [Re: RusselB]
ohaithar Offline
Ameglian cow

Registered: 18/01/11
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?

Top
#229662 - 13/02/11 01:06 AM Re: help with random number on text [Re: ohaithar]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
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.

Top
#229663 - 13/02/11 01:11 AM Re: help with random number on text [Re: Tomao]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top
#229664 - 13/02/11 01:15 AM Re: help with random number on text [Re: Riamus2]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
Riamus2, if you don't mind, could you please show me your apporach with this? ^^ Much obliged.

Top
#229665 - 13/02/11 02:01 AM Re: help with random number on text [Re: ohaithar]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
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-)

Top
#229666 - 13/02/11 02:23 AM Re: help with random number on text [Re: Tomao]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top
#229667 - 13/02/11 03:19 AM Re: help with random number on text [Re: Riamus2]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
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.

Top
#229668 - 13/02/11 03:33 AM Re: help with random number on text [Re: Tomao]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top
#229669 - 13/02/11 04:06 AM Re: help with random number on text [Re: RusselB]
ohaithar Offline
Ameglian cow

Registered: 18/01/11
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


Top
#229670 - 13/02/11 04:09 AM Re: help with random number on text [Re: Tomao]
ohaithar Offline
Ameglian cow

Registered: 18/01/11
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.

Top
#229671 - 13/02/11 04:48 AM Re: help with random number on text [Re: ohaithar]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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
  }
}


Top
#229672 - 13/02/11 05:21 AM Re: help with random number on text [Re: ohaithar]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
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.

Top
#229674 - 13/02/11 05:31 AM Re: help with random number on text [Re: Tomao]
ohaithar Offline
Ameglian cow

Registered: 18/01/11
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


Edited by ohaithar (13/02/11 05:33 AM)

Top
#229675 - 13/02/11 05:39 AM Re: help with random number on text [Re: ohaithar]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
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.

Top
#229678 - 13/02/11 10:59 AM Re: help with random number on text [Re: Tomao]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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.
  }
}


Top
#229682 - 13/02/11 09:18 PM Re: help with random number on text [Re: RusselB]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
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.

Top