mIRC Home    About    Download    Register    News    Help

Print Thread
dice roller #168630 11/01/07 04:44 PM
Joined: Jan 2007
Posts: 5
I
IrcFear Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jan 2007
Posts: 5
I need a lil help on how $calc on this dice roller I'm making. Now I got the random numbers working and i got it to add and give a total but I can't get it to modify like modifiers like *Fear rolls 2d6 +1 the result would be oh say 2+5 = 7 but the +1 would make it 8, Or Even subtract like *Fear rolls 2d4 3+2 = 5 -2 would = 3, here is what i got

alias dice2 {
tokenize 32 $iif($1 isnum 1-,$1,6) $iif($2 isnum 1-,$2,3)
var %i = 1
while (%i <= $2) { var %o = $instok(%o,$iif($calc($r(1,$1) % 2),$r(1,$1),$r(1,$1)),0,44) | inc %i }
if ($isid) { return $replace(%o,$chr(44),$chr(43),$chr(32)) }
else { describe $active Rolled $+($chr(3),14,$2,$chr(3),12,d,$chr(3),14,$1) And Got4:12 $+ $replace(%o,$chr(44),$chr(43)) Total4:12 $+ $calc($replace(%o,$chr(44),$chr(43))) }
}

Re: dice roller [Re: IrcFear] #168633 11/01/07 07:26 PM
Joined: Jan 2007
Posts: 259
K
Kardafol Offline
Fjord artisan
Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
I'm making a dice roller, fully functional. Just adding the on text event, I will post the code when its done.


Those who can, cannot. Those who cannot, can.
Re: dice roller [Re: Kardafol] #168636 11/01/07 07:46 PM
Joined: Jan 2007
Posts: 5
I
IrcFear Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jan 2007
Posts: 5
cool
can't wait to see

Re: dice roller [Re: Kardafol] #168637 11/01/07 07:51 PM
Joined: Jan 2007
Posts: 259
K
Kardafol Offline
Fjord artisan
Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
Here's the code (updated with enabling/disabling):
Code:
# Dice roller, by Kardafol
#rolldice off
on *:text:!roll*:#: {
  ;flood protection
  if (%flood.roll) return
  set %flood.roll 1
  .timerflood.roll 1 3 unset %flood.roll 


  ; syntax things, and error checking
  if ((!$2) || ($2 == help)) {
    msg # Syntax: <<dice>d<sides: 4/6/8/10/20/100>|<number>>[<+/->...]. <> = required, [] = optional. $&
      ... means you may repeat the expression. <number> is a number to add to the total without rolling a dice for it. The first part must be a roll. $&
      Limit to <dice> is 100.
    msg # Examples: !roll 2d6+5, !roll 1d20, !roll 2d6+1d8-3. Bad examples: !roll 2d2+4, !roll 5+2d6, !roll 101d4+5
    return  
  }

  var %x = $rolldice($2-)
  if (-* iswm %x) {
    msg # $nick $+ , your syntax is invalid. Possible errors: $gettok(%x,2-,32) $+ .
    return
  }
  else {
    describe # rolls dice for $nick $+ , and gets: %x
  }

}

alias rolldice {
  if (!$1) return -
  ; Syntax checking:

  var %s = $1-, %st = 09, %f = 1
  while ($regsub(%s,/^((\d+)d(?:4|6|8|10|20|100)(?:[-+]|$)|\d+(?:[-+]|$))/,$null,%s)) {
    if ((%f == 1) && (*d* !iswm $regml(1))) {
      return - $+(%st,04,$regml(1),%s)
    }
    if ($regml(2) > 100) {
      return - $+(%st,04,$regml(1),%s)
    }
    var %st = %st $+ $regml(1)
    inc %f
  }
  if (%s != $null) {
    return - $+(%st,04,%s)
  }

  ; The actual calculations and rolls

  var %x = $1-, %rolls, %t, %total
  while ($regsub(roll,%x,/^(?:(\d+)(d)(4|6|8|10|20|100)([-+]|$)|(\d+)([-+]|$))/,$null,%x)) {
    if ($regml(roll,2) == d) {
      var %d = $regml(roll,1), %s = $regml(roll,3)
      var %o = $droll(%d,%s), %t = $gettok(%o,1,32), %rx = $gettok(%o,2-,32)
      var %total = $calc(%t %m %total)
      var %rolls = %rolls $iif(%m,%m) $+([,%rx,])
      var %m = $regml(roll,4)
    }
    else {
      if (!%m) %m = +
      var %total = $iif(%total,$calc(%total %m $regml(roll,1)),$regml(roll,1))
      var %rolls = %rolls %m $regml(roll,1)
      var %m = $regml(roll,2)
    }
  }
  if ($len(%rolls) > 150) %rolls = [hidden, too long to display.]
  return %rolls = %total
}
alias droll {
  if (($1 !isnum) || ($2 !isnum)) return 
  var %n = $1, %s = $2, %r, %rolls, %t
  while (%n) {
    %r = $rand(1,%s)
    %t = $calc(%t + %r)
    %rolls = $iif(%rolls,$+(%rolls,+,%r),%r)
    dec %n
  }
  return %t $+(%rolls,=,%t)
}
#rolldice end

alias diceroll {
  if (!$1) {
    echo -ac info * Dice Roll is $iif($group(rolldice) == on,enabled,disabled) $+ . /diceroll <on/off> to enable, disable.
  }
  if ($1 == on) {
    if ($group(#rolldice) == on) echo -ac info * Dice Roll is already enabled.
    else {
      .enable #rolldice
      echo -ac info * Dice Roll has been enabled.
    }
  }
  elseif ($1 == off) {
    if ($group(#rolldice) == off) echo -ac info * Dice Roll is already disabled.
    else {
      .disable #rolldice
      echo -ac info * Dice Roll has been disabled.
    }
  }
}
on *:load: {
  echo -ac info * Dice Roll V1 by kardafol has been sucessfully loaded.
  echo -ac info * Type /diceroll on to enable dice rolling. (Disabled by deafult.)
}


Tell me if you get any bugs, and I'll try to fix it.

Last edited by Kardafol; 11/01/07 08:47 PM.

Those who can, cannot. Those who cannot, can.
Re: dice roller [Re: IrcFear] #168642 11/01/07 08:14 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
There are 2 dice scripts listed here ... one that Sais did and one that I did. Feel free to check them out. Both are AD&D style, where you can use 2d4+1 or whatever as the roll.


Invision Support
#Invision on irc.irchighway.net
Re: dice roller [Re: Kardafol] #168644 11/01/07 08:16 PM
Joined: Jan 2007
Posts: 5
I
IrcFear Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jan 2007
Posts: 5
thanks helped me out alot laugh

Re: dice roller [Re: Riamus2] #168647 11/01/07 08:23 PM
Joined: Jan 2007
Posts: 259
K
Kardafol Offline
Fjord artisan
Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
However, your script doesn't support "2d6+3d8" while mine does. It also highlights possible errors if there's a error in the syntax. =)

Last edited by Kardafol; 11/01/07 08:23 PM.

Those who can, cannot. Those who cannot, can.
Re: dice roller [Re: Kardafol] #168661 11/01/07 11:23 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
No, mine doesn't. Of course, it wasn't necessary to do multiple dice for what I was making. For a standard AD&D dice roll, it will do everything that is necessary. It would be a very minor edit to make it support extra sided dice in the roll.

A good thing with this versus yours is that you prevent any dice that don't match your specific number of sides. Mine works with any number of sides. Although most AD&D would use a specific number of sides, this can be used for unusual campaigns or non-AD&D rolls that use the same kind of format for rolls.

As for the error checking is there. You can always change the message to say something more specific, but a single message showing the proper syntax for any incorrect roll was all that I needed. Obviously, if you want more, you can add more. I gave the link to show 2 working scripts to use as examples.

Anyhow, that's an old dice rolling script (it was old when I pasted it as the post says) and it could be shortened and improved on thanks to having more scripting experience since the time that was written (years ago), but it does work for a standard AD&D roll.


Invision Support
#Invision on irc.irchighway.net
Re: dice roller [Re: Riamus2] #168684 12/01/07 02:55 AM
Joined: Jan 2007
Posts: 5
I
IrcFear Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jan 2007
Posts: 5
well thanks again you both helped me alot

Re: dice roller [Re: Riamus2] #168685 12/01/07 02:55 AM
Joined: Jan 2007
Posts: 5
I
IrcFear Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jan 2007
Posts: 5
well thanks again you both helped me alot