Module:RPG: Difference between revisions

From Empire of Dragons
Jump to navigation Jump to search
No edit summary
No edit summary
Line 10: Line 10:
     sides = tonumber(sides) or 6
     sides = tonumber(sides) or 6
     modifier = tonumber(modifier) or 0
     modifier = tonumber(modifier) or 0
    local resultString = "Rolling " .. num .. "d" .. sides .. modifier


     local total = modifier
     local total = modifier
    local individualResults = {}


     for _ = 1, num do
     for i = 1, num do
         total = total + math.random(1, sides)
         local roll = math.random(1, sides)
        total = total + roll
        table.insert(individualResults, roll)
     end
     end


     return total
    resultString = resultString .. ": " .. table.concat(individualResults, ", ") .. " = " .. total
 
     return resultString
end
end


return p
return p

Revision as of 15:46, 27 January 2024

Rolling 3d63: 1, 4, 2 = 10

  • Rolling 3d60: 1, 4, 2 = 7


  • Rolling 2d62: 1, 4 = 7
  • Rolling 4d62: 1, 4, 2, 5 = 14
  • Rolling 2d44: 1, 3 = 8
  • 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(frame)
    local args = frame.args
    local diceString = args[1] or ""
    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 resultString = "Rolling " .. num .. "d" .. sides .. modifier

    local total = modifier
    local individualResults = {}

    for i = 1, num do
        local roll = math.random(1, sides)
        total = total + roll
        table.insert(individualResults, roll)
    end

    resultString = resultString .. ": " .. table.concat(individualResults, ", ") .. " = " .. total

    return resultString
end

return p