Module:Test: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
Tag: Manual revert
No edit summary
Tag: Reverted
Line 14: Line 14:
     denominator = tonumber(denominator) or 1 -- Convert denominator to a number or default to 1
     denominator = tonumber(denominator) or 1 -- Convert denominator to a number or default to 1
      
      
     local percentages = {}
     local percentages = frame:preprocess('{{#var:percentages}}') -- Get existing percentages or empty string if not defined
    if percentages == "" then
        percentages = "|-\n" -- Start a new table row if no existing percentages
    else
        percentages = percentages .. "\n|-\n" -- Append to existing table row
    end
   
     -- Original number
     -- Original number
     table.insert(percentages, dropRate)
     percentages = percentages .. "| " .. dropRate
   
     -- Donator (85% of original drop rate)
     -- Donator (85% of original drop rate)
     local donatorDenominator = math.floor(denominator * 0.85)
     local donatorDenominator = math.floor(denominator * 0.85)
     local donator = string.format("%d/%d", numerator, donatorDenominator)
     local donator = string.format(" || %d/%d", numerator, donatorDenominator)
     table.insert(percentages, donator)
     percentages = percentages .. donator
   
     -- Super donator (75% of original drop rate)
     -- Super donator (75% of original drop rate)
     local superDonatorDenominator = math.floor(denominator * 0.75)
     local superDonatorDenominator = math.floor(denominator * 0.75)
     local superDonator = string.format("%d/%d", numerator, superDonatorDenominator)
     local superDonator = string.format(" || %d/%d", numerator, superDonatorDenominator)
     table.insert(percentages, superDonator)
     percentages = percentages .. superDonator
   
     -- Extreme donator (70% of original drop rate)
     -- Extreme donator (70% of original drop rate)
     local extremeDonatorDenominator = math.floor(denominator * 0.70)
     local extremeDonatorDenominator = math.floor(denominator * 0.70)
     local extremeDonator = string.format("%d/%d", numerator, extremeDonatorDenominator)
     local extremeDonator = string.format(" || %d/%d", numerator, extremeDonatorDenominator)
     table.insert(percentages, extremeDonator)
     percentages = percentages .. extremeDonator
   
     -- Legendary donator (65% of original drop rate)
     -- Legendary donator (65% of original drop rate)
     local legendaryDonatorDenominator = math.floor(denominator * 0.65)
     local legendaryDonatorDenominator = math.floor(denominator * 0.65)
     local legendaryDonator = string.format("%d/%d", numerator, legendaryDonatorDenominator)
     local legendaryDonator = string.format(" || %d/%d", numerator, legendaryDonatorDenominator)
     table.insert(percentages, legendaryDonator)
     percentages = percentages .. legendaryDonator
   
     -- Royal donator (60% of original drop rate)
     -- Royal donator (60% of original drop rate)
     local royalDonatorDenominator = math.floor(denominator * 0.60)
     local royalDonatorDenominator = math.floor(denominator * 0.60)
     local royalDonator = string.format("%d/%d", numerator, royalDonatorDenominator)
     local royalDonator = string.format(" || %d/%d", numerator, royalDonatorDenominator)
     table.insert(percentages, royalDonator)
     percentages = percentages .. royalDonator
   
    -- Custom labels
    local labels = {"Drop Rate", "Donator", "Super donator", "Extreme donator", "Legendary donator", "Royal donator"}
      
      
     -- Format the result as a table
     frame:preprocess('{{#vardefine:percentages|' .. percentages .. '}}') -- Save the updated percentages
    local resultTable = "{| class=\"wikitable\"\n"
    resultTable = resultTable .. "! " .. table.concat(labels, " !! ") .. "\n|-\n"
    resultTable = resultTable .. "| " .. table.concat(percentages, " || ") .. "\n|}"
      
      
     return resultTable
     return frame:preprocess('{{#var:percentages}}') -- Return the updated percentages
end
end


-- Export the module
-- Export the module
return Test
return Test

Revision as of 16:27, 1 May 2024

Documentation for this module may be created at Module:Test/doc

-- This is a Lua module for MediaWiki
-- It provides functionality to calculate percentages of a number

-- 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+)")
    denominator = tonumber(denominator) or 1 -- Convert denominator to a number or default to 1
    
    local percentages = frame:preprocess('{{#var:percentages}}') -- Get existing percentages or empty string if not defined
    if percentages == "" then
        percentages = "|-\n" -- Start a new table row if no existing percentages
    else
        percentages = percentages .. "\n|-\n" -- Append to existing table row
    end
    
    -- Original number
    percentages = percentages .. "| " .. dropRate
    
    -- Donator (85% of original drop rate)
    local donatorDenominator = math.floor(denominator * 0.85)
    local donator = string.format(" || %d/%d", numerator, donatorDenominator)
    percentages = percentages .. donator
    
    -- Super donator (75% of original drop rate)
    local superDonatorDenominator = math.floor(denominator * 0.75)
    local superDonator = string.format(" || %d/%d", numerator, superDonatorDenominator)
    percentages = percentages .. superDonator
    
    -- Extreme donator (70% of original drop rate)
    local extremeDonatorDenominator = math.floor(denominator * 0.70)
    local extremeDonator = string.format(" || %d/%d", numerator, extremeDonatorDenominator)
    percentages = percentages .. extremeDonator
    
    -- Legendary donator (65% of original drop rate)
    local legendaryDonatorDenominator = math.floor(denominator * 0.65)
    local legendaryDonator = string.format(" || %d/%d", numerator, legendaryDonatorDenominator)
    percentages = percentages .. legendaryDonator
    
    -- Royal donator (60% of original drop rate)
    local royalDonatorDenominator = math.floor(denominator * 0.60)
    local royalDonator = string.format(" || %d/%d", numerator, royalDonatorDenominator)
    percentages = percentages .. royalDonator
    
    frame:preprocess('{{#vardefine:percentages|' .. percentages .. '}}') -- Save the updated percentages
    
    return frame:preprocess('{{#var:percentages}}') -- Return the updated percentages
end

-- Export the module
return Test