Random Dice Roller

I want to have the following:


Common Event


SetXforXdY - X (number of dice)


SetYforXdY - Y (number of sides)


SetAPD - Adjustment Per Dice ... so (+APD)


SetAPR - Adjustment Per Roll  ... so(+APR)


SetXDY - the dice to be used eg SetXforXdY D SetYforXdY


I managed to find this on the forums:


ROLL_FORMAT = /(\d+)[d](\d+)/i


def roll(n, sides)
    result = 0
    n.times {|x| result += rand(sides)+1 }
    return result
end


def dice_roll(expr)
  fn_call = expr.gsub ROLL_FORMAT do |match|
    'roll(' + $1 + ',' + $2 + ')'
  end
  return eval(fn_call)
end


The call to that would be dice_roll(XDY)


I would probably have to adjust  the formula also because it doesn't take into account the adjustment variables. ie APD and APR


What I need is a way so that an event like a treasure chest or some action can define and roll dynamically. Also it would need to take into account other variables.


Anyway I am hacking my way towards making something but can any of you give me a or provide a link to a royalty free dice rolling script?
Usually dice rollings aren't done by script, but by events - the control variable command contains a random generator, and that is usually used for determing random results, including random treasure chests.


If you cannot use that, we need to know why that is impossible and what you want from this script that can't be done by a series of control variable commands, because that will affect how the script needs to be written.

Original thread: https://forums.rpgmakerweb.com/threads/random-dice-roller.57320/