$roll

By l0wner on Jun 01, 2011

a friend asked for an alias to roll dice for his bot, figured I'd throw it here too.
roll is returned as string separated by periods.

$roll returns 1 roll of 6 sided die (by default, edit var lines for %d and %s respectively)
$roll(N) returns N rolls of 6 sided dice (edit %s line to change)
$roll(N,S) returns N rolls of S sided dice $roll(1,6) is the same as $roll by default
$roll(N1,S1,N2,S2,etc) i think you get the point.

alias roll {
  if ($0 > 2) && (2 \\ $0) { return }
  var %cl = 2, %l = $iif($0 > 2,$0,2)
  while (%cl <= %l) {
    var %d = $iif($1 == $null,1,[ [ $+($,$calc(%cl - 1)) ] ])
    var %s = $iif($2 == $null,6,[ [ $+($,%cl) ] ]), %x = 1
    while (%x <= %d) { 
      hadd -m roll r $instok($hget(roll,r),$rand(1,%s),0,46)
      inc %x 
    }
    inc %cl 2
  }
  .timer 1 0 hfree roll
  return $hget(roll,r)
}

Comments

Sign in to comment.
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.