Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Assumes $1 uses the standard #d# format (I..e, 1d6 = Roll 1 six sided die; 2d4 = roll 2 four sided die. $2 can be ##, +##, or -## (## is converted to +##))
- ; $1 can also be 'percentile' or 'p' to simulate the rolling of percentile dice (2d10, where one d10 is ones (0-9), the other is tens (00-90). 0+00 = 100)
- alias diceroll {
- var %parDice = $1
- var %parMod = $2
- var %rollTotal = 0
- var %rollList = $null
- ; Percentile (Only checks if first letter is p)
- if ($left(%parDice, 1) == p) {
- ; Roll tens
- var %tmpRoll = $calc($rand(0, 9) * 10)
- inc %rollTotal %tmpRoll
- var %rollList = %rollList ( $+ %tmpRoll $+ )
- ; Roll ones
- var %tmpRoll = $rand(0, 9)
- inc %rollTotal %tmpRoll
- var %rollList = %rollList ( $+ %tmpRoll $+ )
- ; If total is 0, roll is 100
- if (%rollTotal = 0) {
- var %rollTotal = 100
- }
- }
- ; Standard dice notation (#d#)
- else {
- var %diceCount = $gettok(%parDice, 1, 100)
- var %diceSides = $gettok(%parDice, 2, 100)
- ; Roll each dice
- var %count = 1
- while (%count <= %diceCount) {
- var %tmpRoll = $rand(1, %diceSides)
- inc %rollTotal %tmpRoll
- var %rollList = %rollList ( $+ %tmpRoll $+ )
- inc %count
- }
- }
- ; Add modifier
- if (%parMod) {
- inc %rollTotal %parMod
- var %rollList = %rollList %parMod
- }
- return %rollTotal %rollList
- }
- alias doTest {
- echo t $diceRoll(Percentile, +3)
- echo t $diceRoll(Percentile)
- echo t $diceRoll(Percentile, -3)
- echo t $diceRoll(Percentile, 1)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement