mIRC Home    About    Download    Register    News    Help

Print Thread
#128329 23/08/05 02:44 PM
P
pUff
pUff
P
Okay, here's one that goes past me, I have done things like this in the past and they all work. I cant understand why this bot keeps rolling 2 on a random bot script. Why is the bot rolling 2?

-------

on *:TEXT:!roll *:#:/describe $chan rolls dices and they land on $read(Dice.txt)

And the .txt file looks like

-------

1
2
3
4
5
6
7
8
9
10
11
12

#128330 23/08/05 03:13 PM
B
buster2007
buster2007
B
try $read("Dice.txt",t)

#128331 23/08/05 03:24 PM
P
pUff
pUff
P
It worked, is it okay if you told me how it made it work?
If not, thank you for yout help just the same

#128332 23/08/05 03:27 PM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
Why not do this?

Code:
on *:text:!roll:#: describe $chan rolls the dice and gets $rand(1,12)


If you want it to roll multiple dice and get a total, you can do this:

Code:
on *:text:!roll *:#: {
  if ($2 isnum) {
    describe $chan rolls $2 dice and gets $rand($2,$calc($2 * 6))
  }
  else notice $nick Invalid format.
}


Example of use:

!roll 5

Output is:

/me rolls 5 dice and gets 5-30 (depending on the random number)

Minimum would be 5 (1 on 5 dice = 5), maximum is 30 (6 on 5 dice = 30).

Last edited by Riamus2; 23/08/05 03:31 PM.
#128333 23/08/05 03:29 PM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
Quote:
It worked, is it okay if you told me how it made it work?
If not, thank you for yout help just the same


Just so you know, the "t" tells mIRC that line #1 isn't the total lines in the file.

Since your first line is "1", it assumes there is only one line in your file. So, no matter what random number you had, you would only be reading the "first" line, which is "2". The "1" line isn't treated as a line in this matter.

Using "t" makes it not assume the first line is the number of lines and makes it work. Anytime you have a file being read that has a number in line one, you should use "t".

#128334 23/08/05 05:10 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Just a reminder: if you throw 10 6 sided dice (or 1 die 10 times) the sum will indeed be a number between 10 and 60, but it will not be the same as just picking a random number between 10 and 60.

Let's check probabilities for 2 dice:
throwing a 2=1+1: 1/6 * 1/6 = 1/36 chance
throwing a 3=2+1 or 1+2: 2/36 chance
throwing a 4=1+3 or 2+2 or 3+1: 3/36 chance
throwing a 7= 1+6 or 2+5 or 3+3 or 4+2 or 5+2 or 6+1: 6/36 chance
etc

Just choosing a random number between 2 and 12: 1/11 chance for all outcomes...

Here's one that works ok, without needing a text file.
Code:
alias dice {
  ; roll dice, argument is <num_dice> [d <num_faces> [+-*/^ modifier]]
  ; 2d6 or 2d or just 2 -> roll 2 normal (6 sided) dice
  ; 5d100-2 -> roll five 100 sided dice and subtract 2
  ; 1d6^2 -> roll one 6 sided die and square the result
  ; usage: $dice(3d6*5)
  if ($regex($1,/^(\d+)\s*(?:d\s*(?:(\d+)\s*(?:([-+*/^])\s*(\d+))?)?)?$/)) {
    var %i = 0, %sum = 0, %sides = $iif($regml(2),$v1,6)
    while (%i < $regml(1)) {
      inc %sum $rand(1,%sides)
      inc %i
    }
    if ($regml(4)) var %sum = $calc(%sum $regml(3) $regml(4))
    return %sum
  }
  return $false
}

on *:TEXT:!roll:#:describe $chan rolls dice and they land on $dice([color:blue]2d6[/color])
on *:TEXT:!roll *:#:{
  if ($dice($2) != $false) describe $chan rolls $2- dice and they land on $v1
  else notice $nick Sorry, $2- is not a valid request
}


Change the default to whatever you like, your text file suggests 1d12 since you cannot throw a 1 with 2 normal dice

Last edited by Kelder; 23/08/05 05:20 PM.
#128335 23/08/05 05:56 PM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
Good point. I usually do a AD&D style dice like you did above and when I do, I end up taking that into account. Since I didn't think he was doing that sort of thing, I didn't think about the multiple dice issue. :|

I also don't use regex for it, but that's okay too. laugh


Link Copied to Clipboard