Module:DoD: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- | -- Function to parse D&D dice codes and return median value | ||
function p.calculateMedian(diceCode) | |||
-- Extract the number of dice | -- Extract the number of dice, the type of dice, and the modifier from the dice code | ||
local numDice, diceType = string.match(diceCode, "(%d+)d(%d+)") | local numDice, diceType, modifier = string.match(diceCode, "(%d+)d(%d+)([%+%-]?%d*)") | ||
-- | -- Convert modifier to number | ||
modifier = tonumber(modifier) or 0 | |||
-- Calculate the median value | -- Calculate the median value | ||
Line 18: | Line 13: | ||
return median | return median | ||
end | end | ||
return p | return p |
Revision as of 09:58, 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 = {} -- Function to parse D&D dice codes and return median value function p.calculateMedian(diceCode) -- Extract the number of dice, the type of dice, and the modifier from the dice code local numDice, diceType, modifier = string.match(diceCode, "(%d+)d(%d+)([%+%-]?%d*)") -- Convert modifier to number modifier = tonumber(modifier) or 0 -- Calculate the median value local median = math.floor((tonumber(numDice) * ((tonumber(diceType) + 1) / 2)) + modifier) return median end return p