Dice Roller

By Chewbacca on Mar 29, 2006

This dice roller lets you decide how many dice to roll, and how many sides on each die. If no parameters are specified, it defaults to one 6-sided die. To use it, use the following format: !roll . For example, !roll 10 20 would roll 10 dice, each having twenty sides. It then totals the amounts and gives you the average. Have fun!

on *:TEXT:!roll*:#: {
  if ($2- == $null) {  
    set %dice 1
    set %sides 6
    %roll = $rand(1,%sides)
    msg # Roll 1: %roll
  }
  else {
    set %dice $2
    set %sides $3
    set %i 0
    set %total 0
    set %average 0
    if ($2 !isnum) || ($3 !isnum) { 
      msg # INVALID PARAMETERS!      
      halt

    }
    if (%dice <= 0) || %sides <= 0) { 
      msg # INVALID PARAMETERS!      
      halt

    }
    while (%i < %dice) {
      inc %i 1
      %roll = $rand(1,%sides)
      msg # Roll %i $+ : %roll
      %total = $calc(%total + %roll)
    }
    msg # Total: %total
    %average = $calc(%total / %dice)
    msg # Average: %average
  }
}

Comments

Sign in to comment.
Cage   -  Apr 08, 2006

I used it and it works fine. But I added this:

if (%dice > 10) {
msg # Too many dice to roll!
halt
}

Helps to prevents users from using extremely large numbers to flood the channel with. Just an idea...

 Respond  
Stirk   -  Apr 01, 2006

on :TEXT:!roll:#: {
if ($2- == $null) {
set %dice 1
set %sides 6
%roll = $rand(1,%sides)
msg # Roll 1: %roll
}

Just at a glance, why set a variable if you arent going to use it?
I\'d change the above part to this:

on :TEXT:!roll:#:{
if (!$2-) {
msg # Roll 1: $rand(1,6)
}

 Respond  
Chewbacca   -  Mar 30, 2006

It works... I\'ve tested it all.

 Respond  
KuTsuM   -  Mar 29, 2006

5 global variables never unset. Also,
if (%dice <= 0) || %sides <= 0) {
Looks as if it may not work..

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.