I'm working on a small project to help some of my players that I GM for. Essentially, I want to create an automated system that will roll dice in the OpenLegend RPG system using its rules.
One element of the system is a "dice explosion." If you roll the maximum value on a dice, you roll it again, adding the previous value and the new one as well, continuing as many times as it "explodes". I'm having some difficulty figuring out how I would do this, however. At present, my code looks like this:
def action_roll_script(attribute, score):
from random import randint as ri
d20 = ri(1, 20)
if score == 0:
roll = d20
if score == 1:
roll = ri(1,4)
if score == 2:
roll = ri(1,6)
if score == 3:
roll = ri(1,8)
if score == 4:
roll = ri(1,10)
if score == 5:
roll = ri(1,6) + ri(1,6)
if score == 6:
roll = ri(1,8) + ri(1,8)
if score == 7:
roll = ri(1,10) + ri(1,10)
if score == 8:
roll = ri(1, 8) + ri(1, 8) + ri(1, 8)
if score == 9:
roll = ri(1, 10) + ri(1, 10) + ri(1, 10)
if score == 10:
roll = ri(1, 8) + ri(1, 10) + ri(1, 10) + ri(1, 10)
print(d20)
print(roll)
outcome = str(roll + d20)
print("You got a " + attribute + " roll of " + outcome + "!")
Now, obviously that's fairly inefficient with entirely too many if statements. I'll work on using a dictionary/list for that later. My question for you all is: how can I tell the script to roll the dice again when it lands on a maximum value? For example, if it rolls a 20 on a d20, I want it to save the previous result and roll again, continuing as many times as it gets a 20.
Thanks in advance for all the help!
Aucun commentaire:
Enregistrer un commentaire