mIRC Home    About    Download    Register    News    Help

Topic Options
#119112 - 01/05/05 06:17 PM Script Help
Longspeak Offline
Nutrimatic drinks dispenser

Registered: 01/05/05
Posts: 6
Hello,

I'm a complete dunce for aliases and scripting, and need some help.

Using some information I gleaned from this thread, I have a working dice roller, customized to fit the game I'm playing. I want to use it in a bot to do the following.

Whenever a player uses the word "roll", followed by a number, I want the bot to do the following:

/msg $chan $nick is rolling [number] dice.
then execute the dice-rolling script.

The bot I have will do everything but accept the number after the word "roll." So it always tries to execute without a number.

How do I get the bot to accept the number? Also, how do I make the bot ignore the word "roll" whenever there isn't a number following the word.

EDIT: Okay, It now works if the user types ONLY "Roll [Number]" If I type (for example) "I roll 4 dice." it still won't execute.

Thanks,

Longspeak


Edited by Longspeak (01/05/05 06:32 PM)

Top
#119113 - 01/05/05 07:10 PM Re: Script Help
BarGarth Offline
Pikka bird

Registered: 14/04/05
Posts: 18
You can try something like this

Code:
  
on $*:TEXT:/roll (\d+)/:#:{
  msg $chan $nick is rolling $regml(1) dice
  dice-rollingscript $regml(1)
}


Edited by BarGarth (01/05/05 07:12 PM)

Top
#119114 - 01/05/05 08:00 PM Re: Script Help
Longspeak Offline
Nutrimatic drinks dispenser

Registered: 01/05/05
Posts: 6
I'm not sure I understood that, but perhaps it will help if I show you what I have:

Code:
on 1:TEXT:*roll*:#room: {
  if ($2 !isnum) { halt } {
    var %Roll.NumberOfdice = $2
    var %Success.Count = 0
    var %Trait.1 = 0
    var %Trait.2 = 0
    var %Trait.3 = 0
    var %Trait.4 = 0
    var %i = 1
    while (%i <= %Roll.NumberOfdice) {
      var %Die.Result = $rand(1,6)
      if (%Die.Result = 6) { inc %Success.Count 2 }
      if (%Die.Result = 5) { inc %Success.Count }
      if (%Die.Result = 4) { inc %Trait.4 }
      if (%Die.Result = 3) {
        inc %Trait.4
        inc %Trait.3
      }
      if (%Die.Result = 2) {
        inc %Trait.4
        inc %Trait.3
        inc %Trait.2
      }
      if (%Die.Result = 1) {
        inc %Trait.4
        inc %Trait.3
        inc %Trait.2
        inc %Trait.1
      }
      var %Roll.Result = %Roll.Result %Die.Result
      inc %i
    }
    /msg $chan * $nick rolls $2 dice ( %Roll.Result ) for %Success.Count success(es).
    /msg $chan * $nick may activate an Anima Trait of 4 to reroll %Trait.4 dice.
    /msg $chan * $nick may activate an Anima Trait of 3 to reroll %Trait.3 dice.
    /msg $chan * $nick may activate an Anima Trait of 2 to reroll %Trait.2 dice.
    /msg $chan * $nick may activate an Anima Trait of 1 to reroll %Trait.1 dice.
  }
}


This script will wait for the word "roll". Then, if there is a number in the 2nd position, it rolls x d6. It tallies one success for every '5', and two successes for every '6'. It also counts possible rerolls. If there is no number in the second position, it halts.

For example, I type:

roll 4

It returns:

rolls 4 dice ( 6 6 3 4 ) for 4 success(es).
may activate an Anima Trait of 4 to reroll 2 dice.
may activate an Anima Trait of 3 to reroll 1 dice.
may activate an Anima Trait of 2 to reroll 0 dice.
may activate an Anima Trait of 1 to reroll 0 dice.

Ideally, I want the Bot to look for the word "roll" or "rolls" anywhere in a line of text. If it finds those words followed by a number, it executes using that number as the variable. If it doesn't see the number, nothing happens.

I can easily do "roll" and "rolls" by making two separate on:TEXT: commands. But making it take look for the number after the word is what flummoxed me.

Later I want to add complexity by making it look for the text only from users I have identified as "players", but for now I just want the dice part to run right.

Thanks,

Longspeak

Edit: Removed redundant line of code


Edited by Longspeak (01/05/05 08:01 PM)

Top
#119115 - 01/05/05 08:45 PM Re: Script Help
BarGarth Offline
Pikka bird

Registered: 14/04/05
Posts: 18
Code:
  
on $1:TEXT:/rolls? (\d+)/:#room: {
  var %Roll.NumberOfdice = $regml(1)
  var %Success.Count = 0
  var %Trait.1 = 0
  var %Trait.2 = 0
  var %Trait.3 = 0
  var %Trait.4 = 0
  var %i = 1
  while (%i <= %Roll.NumberOfdice) {
    var %Die.Result = $rand(1,6)
    if (%Die.Result == 6) { inc %Success.Count 2 }
    if (%Die.Result == 5) { inc %Success.Count }
    if (%Die.Result == 4) { inc %Trait.4 }
    if (%Die.Result == 3) {
      inc %Trait.4
      inc %Trait.3
    }
    if (%Die.Result == 2) {
      inc %Trait.4
      inc %Trait.3
      inc %Trait.2
    }
    if (%Die.Result == 1) {
      inc %Trait.4
      inc %Trait.3
      inc %Trait.2
      inc %Trait.1
    }
    var %Roll.Result = %Roll.Result %Die.Result
    inc %i
  }
  msg $chan * $nick rolls %Roll.NumberOfdice dice ( %Roll.Result ) for %Success.Count success(es).
  msg $chan * $nick may activate an Anima Trait of 4 to reroll %Trait.4 dice.
  msg $chan * $nick may activate an Anima Trait of 3 to reroll %Trait.3 dice.
  msg $chan * $nick may activate an Anima Trait of 2 to reroll %Trait.2 dice.
  msg $chan * $nick may activate an Anima Trait of 1 to reroll %Trait.1 dice.
}


event triggers when in a line 'roll <number>' or 'rolls <number>'
occurs.
The $regml(1) identifier replaces your $2 which is the dice-number.

Top
#119116 - 01/05/05 09:11 PM Re: Script Help
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
Quote:
The $regml(1) identifier replaces your $2 which is the dice-number.


Im not good with regex, so im just wondering as i dont know, was there a need to use $regml(1) over $2, would not the number still been in $2 ?

Top
#119117 - 01/05/05 09:17 PM Re: Script Help
Longspeak Offline
Nutrimatic drinks dispenser

Registered: 01/05/05
Posts: 6
Okay. I get it now, and it works great. Thanks very much for the help.

Longspeak

Top
#119118 - 01/05/05 09:18 PM Re: Script Help
BarGarth Offline
Pikka bird

Registered: 14/04/05
Posts: 18
not if you would use:
i roll 5 dice or something else where the second word isn't the number

in this example: $2 would be roll

Top
#119119 - 01/05/05 09:26 PM Re: Script Help
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
oh yes, i get it now, there was no leading ^ (i think thats it) to say start of text, I didnt realiase you were doing any "roll(s) #" in the line, my mistake.

Top