Dice - rolls dice for roleplaying, in-game gambling or GM:ing

Evennia contribution - Griatch 2012

This module implements a full-fledged dice-roller and a ‘dice’ command to go with it. It uses standard RPG ‘d’-syntax (e.g. 2d6 to roll two six-sided die) and also supports modifiers such as 3d6 + 5.

One can also specify a standard Python operator in order to specify eventual target numbers and get results in a fair and guaranteed unbiased way. For example a GM could (using the dice command) from the start define the roll as 2d6 < 8 to show that a roll below 8 is required to succeed. The command will normally echo this result to all parties (although it also has options for hidden and secret rolls).


To use in your code, just import the roll_dice function from this module.

To use the dice/roll command, just import this module in your custom cmdset module and add the following line to the end of DefaultCmdSet’s at_cmdset_creation():


After a reload the dice (or roll) command will be available in-game.

evennia.contrib.dice.roll_dice(dicenum, dicetype, modifier=None, conditional=None, return_tuple=False)[source]

This is a standard dice roller.

  • dicenum (int) – Number of dice to roll (the result to be added).

  • dicetype (int) – Number of sides of the dice to be rolled.

  • modifier (tuple) – A tuple (operator, value), where operator is one of “+”, “-“, “/” or “*”. The result of the dice roll(s) will be modified by this value.

  • conditional (tuple) – A tuple (conditional, value), where conditional is one of “==”,**”<”,”>”,”>=”,”<=**” or “!=”. This allows the roller to directly return a result depending on if the conditional was passed or not.

  • return_tuple (bool) – Return a tuple with all individual roll results or not.


roll_result (int)

The result of the roll + modifiers. This is the

default return.

condition_result (bool): A True/False value returned if conditional

is set but not return_tuple. This effectively hides the result of the roll.

full_result (tuple): If, return_tuple** is True, instead

return a tuple (result, outcome, diff, rolls). Here, result is the normal result of the roll + modifiers. outcome and diff are the boolean result of the roll and absolute difference to the conditional input; they will be will be None if conditional is not set. rolls is itself a tuple holding all the individual rolls in the case of multiple die-rolls.


TypeError if non-supported modifiers or conditionals are given.


All input numbers are converted to integers.


print roll_dice(2, 6) # 2d6 <<< 7 print roll_dice(1, 100, (‘+’, 5) # 1d100 + 5 <<< 34 print roll_dice(1, 20, conditional=(‘<’, 10) # let’say we roll 3 <<< True print roll_dice(3, 10, return_tuple=True) <<< (11, None, None, (2, 5, 4)) print roll_dice(2, 20, (‘-‘, 2), conditional=(‘>=’, 10), return_tuple=True) <<< (8, False, 2, (4, 6)) # roll was 4 + 6 - 2 = 8

class evennia.contrib.dice.CmdDice(**kwargs)[source]

Bases: evennia.commands.default.muxcommand.MuxCommand

roll dice


dice[/switch] <nr>d<sides> [modifier] [success condition]


hidden - tell the room the roll is being done, but don’t show the result secret - don’t inform the room about neither roll nor result


dice 3d6 + 4 dice 1d100 - 2 < 50

This will roll the given number of dice with given sides and modifiers. So e.g. 2d6 + 3 means to ‘roll a 6-sided die 2 times and add the result, then add 3 to the total’. Accepted modifiers are +, -, * and /. A success condition is given as normal Python conditionals (<,>,<=,>=,==,!=). So e.g. 2d6 + 3 > 10 means that the roll will succeed only if the final result is above 8. If a success condition is given, the outcome (pass/fail) will be echoed along with how much it succeeded/failed with. The hidden/secret switches will hide all or parts of the roll from everyone but the person rolling.

key = 'dice'
aliases = ['@dice', 'roll']
locks = 'cmd:all()'

Mostly parsing for calling the dice roller function

help_category = 'general'
lock_storage = 'cmd:all()'
class evennia.contrib.dice.DiceCmdSet(cmdsetobj=None, key=None)[source]

Bases: evennia.commands.cmdset.CmdSet

a small cmdset for testing purposes. Add with @py self.cmdset.add(“contrib.dice.DiceCmdSet”)


Called when set is created

path = 'evennia.contrib.dice.DiceCmdSet'