Module:DoD: Difference between revisions
No edit summary |
No edit summary |
||
| Line 15: | Line 15: | ||
-- Calculate the median value | -- Calculate the median value | ||
local median = (tonumber(numDice) * ((tonumber(diceType) + 1) / 2)) + modifier | local median = math.floor((tonumber(numDice) * ((tonumber(diceType) + 1) / 2)) + modifier) | ||
return median | return median | ||
Revision as of 09:56, 6 February 2024
Script error: The function "skills" does not exist.
0-22 : Cost of 3 : Script error: The function "calculate_A_cost" does not exist.
0-18 : Cost of 2 : Script error: The function "calculate_A_cost" does not exist.
5-10 : Cost of 1 : Script error: The function "calculate_A_cost" does not exist.
B_Skill at level 1 : Cost of 5 Script error: The function "calculate_B_cost" does not exist.
B_Skill at level 2 : Cost of 5 Script error: The function "calculate_B_cost" does not exist.
B_Skill at level 3 : Cost of 5 Script error: The function "calculate_B_cost" does not exist.
B_Skill at level 4 : Cost of 5 Script error: The function "calculate_B_cost" does not exist.
B_Skill at level 5 : Cost of 5 Script error: The function "calculate_B_cost" does not exist.
B_Skill at level 5 from 2 : Cost of 5 Script error: The function "calculate_B_cost" does not exist.
local p = {}
-- Define a function to calculate the median value of a D&D dice code
local function calculateMedian(diceCode)
-- Extract the number of dice and the type of dice from the dice code
local numDice, diceType = string.match(diceCode, "(%d+)d(%d+)")
-- Check if a modifier is present
local modifier = string.match(diceCode, "[%+%-]?%d+")
if modifier then
modifier = tonumber(modifier)
else
modifier = 0
end
-- Calculate the median value
local median = math.floor((tonumber(numDice) * ((tonumber(diceType) + 1) / 2)) + modifier)
return median
end
-- Function to parse D&D dice codes and return median value
function p.calculateMedian(frame)
local input = frame.args[1]
if not input then
return "Error: No input provided"
end
return calculateMedian(input)
end
return p