Module:Test: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- Create a table to hold the functions | -- Create a table to hold the functions | ||
local Test = {} | local Test = {} | ||
Line 17: | Line 14: | ||
-- Original number | -- Original number | ||
table.insert(percentages, dropRate) | table.insert(percentages, dropRate) | ||
-- Donator | -- Donator (90% of original drop rate) | ||
local | local donatorNumerator = math.floor(number * 0.9) | ||
local donator = donatorNumerator .. "/" .. denominator | |||
table.insert(percentages, donator) | table.insert(percentages, donator) | ||
-- Super donator | -- Super donator (80% of original drop rate) | ||
local | local superDonatorNumerator = math.floor(number * 0.8) | ||
local superDonator = superDonatorNumerator .. "/" .. denominator | |||
table.insert(percentages, superDonator) | table.insert(percentages, superDonator) | ||
-- Extreme donator | -- Extreme donator (70% of original drop rate) | ||
local | local extremeDonatorNumerator = math.floor(number * 0.7) | ||
local extremeDonator = extremeDonatorNumerator .. "/" .. denominator | |||
table.insert(percentages, extremeDonator) | table.insert(percentages, extremeDonator) | ||
Revision as of 22:55, 3 April 2024
Documentation for this module may be created at Module:Test/doc
-- Create a table to hold the functions
local Test = {}
-- Function to calculate percentages
function Test.calculatePercentages(frame)
local args = frame.args
local dropRate = args[1] or "0/1" -- Extract the drop rate from the args, default to "0/1"
-- Parsing the drop rate
local numerator, denominator = dropRate:match("(%d+)/(%d+)")
local number = tonumber(numerator) / tonumber(denominator) or 0 -- Calculate the fraction
local percentages = {}
-- Original number
table.insert(percentages, dropRate)
-- Donator (90% of original drop rate)
local donatorNumerator = math.floor(number * 0.9)
local donator = donatorNumerator .. "/" .. denominator
table.insert(percentages, donator)
-- Super donator (80% of original drop rate)
local superDonatorNumerator = math.floor(number * 0.8)
local superDonator = superDonatorNumerator .. "/" .. denominator
table.insert(percentages, superDonator)
-- Extreme donator (70% of original drop rate)
local extremeDonatorNumerator = math.floor(number * 0.7)
local extremeDonator = extremeDonatorNumerator .. "/" .. denominator
table.insert(percentages, extremeDonator)
-- Custom labels
local labels = {"Drop Rate", "Donator", "Super donator", "Extreme donator"}
-- Format the result as a table
local resultTable = "{| class=\"wikitable\"\n"
resultTable = resultTable .. "! " .. table.concat(labels, " !! ") .. "\n|-\n"
resultTable = resultTable .. "| " .. table.concat(percentages, " || ") .. "\n|}"
return resultTable
end
-- Export the module
return Test