-
Notifications
You must be signed in to change notification settings - Fork 0
/
GizmoCommands.py
35 lines (31 loc) · 995 Bytes
/
GizmoCommands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import random
# Ex. takes in 2d20 and outputs the string Rolling 2 d20
def roll_str(rolls):
numDice = rolls.split('d')[0]
diceVal = rolls.split('d')[1]
if numDice == '':
numDice = int(1)
return "Rolling %s d%s" % (numDice, diceVal)
# Ex. takes in 2d20 and outputs resultString = 11, 19 results = 30 numDice = 2
def roll(rolls):
results = 0
resultString = ''
try:
numDice = rolls.split('d')[0]
except Exception as e:
print(e)
return "Use proper format!"
rolls, limit = map(str, rolls.split('d'))
if rolls == '':
rolls = int(1)
rolls = int(rolls)
limit = int(limit)
for r in range(rolls):
number = random.randint(1, limit)
results = results + number
if resultString == '':
resultString += str(number)
else:
resultString += ', ' + str(number)
# Returns 3 variables, make sure to store in 3 variables
return resultString, results, numDice