Module:RPG

From Empire of Dragons
Revision as of 15:41, 27 January 2024 by Oberoten (talk | contribs)
Jump to navigation Jump to search

Invalid input. Please provide a valid dice string.

  • Invalid input. Please provide a valid dice string.


  • Invalid input. Please provide a valid dice string.
  • Invalid input. Please provide a valid dice string.
  • Invalid input. Please provide a valid dice string.
  • Script error: The function "rollStats" does not exist.
  • Script error: The function "rollStats" does not exist.
  • Script error: The function "rollStats" does not exist.
  • Script error: The function "rollStats" does not exist.

-- Module for rolling RPG dice
local p = {}

-- Function to roll dice
function p.rollDice(diceString)
    if type(diceString) == "string" then
        local num, sides, modifier = string.match(diceString, "(%d+)d(%d+)([%+%-]?%d*)")
        num = tonumber(num) or 1
        sides = tonumber(sides) or 6
        modifier = tonumber(modifier) or 0

        local total = modifier

        for _ = 1, num do
            total = total + math.random(1, sides)
        end

        return total
    else
        return "Invalid input. Please provide a valid dice string."
    end
end

return p