Python tools for D&D

Hi guys!!
I'm studying software engineering and since our school projects are kinda boring and without purpose I started working on a little suite of tools for Dungeons and Dragons Dungeon Masters (or also player, if you want).
Right now I have a simple dice roller and I'm programming a random Magic Weapon Generator.
Is there something that you'd find useful being a DM? Or a player?
Here's a link to the GitHub if you want to take a look and/or collaborate!!
Take care and keep rolling those dices :)


Easy making and managing character sheets. I know there are plenty of programs for this you can take a look at, but this can be a real nightmare to deal with especially during long sessions (so it is still useful as a practice).

1 Like

This is a cool idea. I'm gonna look at your code later :D have you put it under a license? (More free software is always good!)

My idea is to open source it, I really should look into creative commons licenses or simialr for code!!
I'll dive into it later :)

1 Like

GPL is great for code and CC is great for assets art and writing, that would be my suggestion

I'll look it up! Thanks for the suggestion :)

1 Like

For the diceroller, I'd chance one thing.

This for loop will run through every integer between 0 and the diceNumber, assigning it to a variable called "dice".
It looks a bit nicer IMO. Don't have to stick "dice = 0" before and "dice += 1" at the end of the while, and the starting line of the loop explains what's actually happening much more clearly. "i", is also a pretty dubious variable name. Don't use dubious variable names. You'll only get yourself confused, and comment on your code lots.

    for dice in range(0, diceNumber):
        diceRoll = randint(1, diceType)
        diceTotal = diceTotal + diceRoll
        print "Dice #%r = %r " % (i + 1, diceRoll)

Remember to document your functions

One thing I think is that weapon generator is going to get massive fast, would it be better to put it into a lookup list rather than having a large amount of if statements. That way you will have cleaner code, and it will be easier to change at a later date.

Something like this (keep in mind my python isn't the best)

I used two different lists as examples but a dictionary is probably best (second example (weapon list)) as its more descriptive.

Id make a pull request but its literally a rewrite of the structure figured its nicer to explain it here.

type = ((1, 10,  "axe"),
        (11, 20, "sword"))

weapon = (
    {'low': 1,   'high': 20,   'magicWeapon': 'Dagger',           'weaponDamage': '1d4, 19-20 x2'},
    {'low': 21,  'high': 40,   'magicWeapon': 'Longsword (1H)',   'weaponDamage': '1d6, 19-20 x2'},
    {'low': 41,  'high': 60,   'magicWeapon': 'Greatsword (2H)',  'weaponDamage': '2d6, 19-20 x2'},
    {'low': 61,  'high': 80,   'magicWeapon': 'Schyte (2H)',      'weaponDamage': '2d4, x4'},
    {'low': 81,  'high': 100,  'magicWeapon': 'Bastard Sword',    'weaponDamage': '1d10, 19-20 x2'}

weaponClassRoll = 11
weaponTypeRoll = 23

for wClassList in type:
    if weaponClassRoll >= wClassList[0] and weaponClassRoll <= wClassList[1]:
        print("Weapon Class: {}".format(wClassList[2]))

for wType in weapon:
    if weaponTypeRoll >= wType['low'] and weaponTypeRoll <= wType['high']:
        print("Weapon type: {}".format(wType['magicWeapon']))
        print("Weapon stats: {}".format(wType['weaponDamage']))

I didn't have time to look into the weapons generator, but my goodness thankyou for showing how to make python code show up that way in posts.

(python code here)

^for anyone wondering

1 Like

It does indeed look better, the diceroller was just a little hack because we otherwise had to wait for our sets to arrive but I'll be sure to update it :)

1 Like

Still not really familiar with these structures, I'll have to dive into them! Thanks for pointing them out tho, I'll finish the idea on the same line I started and if it gets a little too confusing I'll probably rewrite the whole thing from scratch.
Also I'll do the commenting soon enough, I hope, depends on school!

1 Like