D&D rolling script

By totalybored on Sep 24, 2006

this is my first script. use !roll X Y Z where X is how many times you roll, Y is how many sides there is. and Z is bonus/penalty. example: !roll 2 20 +2 will roll 2D20 +2.
also the script wont say uneeded lines. if you just say !roll 1 20 it will say 1 line, or 2 with !roll 2 20 or !roll 1 20 +2, and 3 with !roll 2 20 -2 for example.
also !dc X Y will roll against X 20 sided die with Y bonus and tell you if you succeed or fail.
!dx X Y will roll against a random roll with X bonus while you have Y bonus.

on *:TEXT:!roll*:#: {
  if ($2- == $null) {  
    msg # $nick rolled a 1d6: $rand(1,6)
  }
  else {
    /set -l %dice $2
    set -l %bonus $4
    set -l %sides $3
    set -l %i 0
    set -l %total 0
    set -l %average 0
    set -l %line rolled %dice $+ d $+ %sides $+ : 
    set -l %line1 after bonuses: 
    if ($2 !isnum) || ($3 !isnum) { 
      msg # INVALID PARAMETERS!      
      halt

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

    }
    while (%i < %dice) {
      inc %i 1
      %s = $calc(%s + 1)
      %roll = $rand(1,%sides)
      %rollb = $calc(%roll + %bonus)
      %line = %line %roll 
      %line1 = %line1 %rollb 
      %total = $calc(%total + %rollb)
      %totaln = $calc(%totaln + %roll)

    }
    %avarage = $calc(%totaln / %dice)
    msg $chan $nick %line
    if ($4 != $null) msg $chan %line1
    if ($2 >= 2 ) msg # $nick $+ , Total: %total $+ , before bonus: %totaln $+ , avarage: %avarage 
    unset %total
    unset %totaln  
  }
}
on *:text:!dc*:#: {
  set -l %against $2
  set -l %bonus $3
  %roll = $rand(1,20)
  %rollb = $calc(%roll + %bonus)
  %margin = $calc(%rollb - %against)
  {
    if (%margin >= 1 ) msg $chan $nick $+ , against DC $+ %against and succeded by %margin (rolled: %rollb $+ )
    elseif (-1 >= %margin ) { %margin = $calc(%margin * -1) | msg $chan $nick $+ , against DC $+ %against you faild by %margin (rolled: %rollb $+ )
      elseif (%margin == 0 ) msg $chan $nick $+ , you tied with DC $+ %against
    }
  }
}
on *:text:!dx*:#: {
  set -l %bonus $3
  set -l %bonush $2
  %roll = $rand(1,20)
  %rollb = $calc(%roll + %bonus)
  %rollh = $rand(1,20)
  %rollhb = $calc(%rollh + %bonush)
  %margin = $calc(%rollb - %rollhb)
  {
    if (%margin >= 1 ) msg $chan against DC $+ %rollhb and succeded by %margin (rolled: %rollb $+ )
    elseif (-1 >= %margin ) { %margin = $calc(%margin * -1) | msg $chan against DC $+ %rollhb you faild by %margin (rolled: %rollb $+ )
      elseif (%margin == 0 ) msg $chan you tied with DC $+ %rollhb
    }
  }

Comments

Sign in to comment.
totalybored   -  Sep 25, 2006

thanks :)

 Respond  
LIQUID_NiTrO   -  Sep 24, 2006

Try using more local variables...
There\'s no need for any globals in there.
Basically, replace any /set %var commands in there with var %var or /set -l

 Respond  
totalybored   -  Sep 24, 2006

what to do think? how should i improve it?

 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.