mIRC Homepage

Script Help

Posted By: Longspeak

Script Help - 01/05/05 05:17 PM

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
Posted By: BarGarth

Re: Script Help - 01/05/05 06:10 PM

You can try something like this

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

Re: Script Help - 01/05/05 07:00 PM

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
Posted By: BarGarth

Re: Script Help - 01/05/05 07:45 PM

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.
Posted By: DaveC

Re: Script Help - 01/05/05 08:11 PM

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 ?
Posted By: Longspeak

Re: Script Help - 01/05/05 08:17 PM

Okay. I get it now, and it works great. Thanks very much for the help.

Longspeak
Posted By: BarGarth

Re: Script Help - 01/05/05 08:18 PM

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
Posted By: DaveC

Re: Script Help - 01/05/05 08:26 PM

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.
© 2019 mIRC Discussion Forums