Module:DropsLineRoatz: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
(Replaced content with "local p = {} function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { wrappers = 'Template:DropsLineRoatz' }) local name = args.name or '' local quantity = args.quantity or '' local rarity = args.rarity or '' local rarity2 = args.rarity2 or '' local rarity3 = args.rarity3 or '' local output = '' -- Add the picture of the item if provided if args.image then output = output .. args.image...")
Tags: Replaced Reverted
No edit summary
 
(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local lang = mw.language.getContentLanguage()


-- Function to get rarity class based on value
local function get_rarity_class(val)
    local rarities_class = {
        { 1, 'table-bg-blue' },
        { 1/25, 'table-bg-green' },
        { 1/99.99, 'table-bg-yellow' },
        { 1/999.99, 'table-bg-orange' },
        { 1/9999999, 'table-bg-red' }
    }
    for i, v in ipairs(rarities_class) do
        if val >= v[1] then
            return v[2]
        end
    end
    return rarities_class[#rarities_class][2] -- default to the last rarity class
end
-- Function to format numbers with commas
local function commas(n)
    if tonumber(n) then
        return lang:formatNum(tonumber(n))
    else
        return n
    end
end
-- Main function
function p.main(frame)
function p.main(frame)
     local args = require('Module:Arguments').getArgs(frame, {
     local args = frame:getParent().args
        wrappers = 'Template:DropsLineRoatz'
    })


     local name = args.name or ''
     local name = args.name or args.Name or 'Item'
     local quantity = args.quantity or ''
     local quantity = args.quantity or args.Quantity or 'Unknown'
    local rarity = args.rarity or ''
     local rarity = args.rarity or args.Rarity or 'Unknown'
     local rarity2 = args.rarity2 or ''
    local rarity3 = args.rarity3 or ''


     local output = ''
     local output = string.format('|-\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n', name, quantity, rarity)
    -- Add the picture of the item if provided
    if args.image then
        output = output .. args.image .. ' '
    end
    -- Add the name of the item
    output = output .. name
    -- Add the quantity and rarity
    output = output .. ' ' .. quantity .. ' ' .. rarity
    if rarity2 ~= '' then
        output = output .. ', ' .. rarity2
    end
    if rarity3 ~= '' then
        output = output .. ', ' .. rarity3
    end
    -- Add the price from the JSON data
    local geprices_data = mw.loadData('Module:GEPrices/data.json')
    local price = geprices_data[name]
    if price then
        output = output .. ' ' .. price
    end


     return output
     return mw.text.tag('tr', output)
end
end


return p
return p

Latest revision as of 11:01, 4 April 2024

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

local p = {}
local lang = mw.language.getContentLanguage()

-- Function to get rarity class based on value
local function get_rarity_class(val)
    local rarities_class = {
        { 1, 'table-bg-blue' },
        { 1/25, 'table-bg-green' },
        { 1/99.99, 'table-bg-yellow' },
        { 1/999.99, 'table-bg-orange' },
        { 1/9999999, 'table-bg-red' }
    }
    for i, v in ipairs(rarities_class) do
        if val >= v[1] then
            return v[2]
        end
    end
    return rarities_class[#rarities_class][2] -- default to the last rarity class
end

-- Function to format numbers with commas
local function commas(n)
    if tonumber(n) then
        return lang:formatNum(tonumber(n))
    else
        return n
    end
end

-- Main function
function p.main(frame)
    local args = frame:getParent().args

    local name = args.name or args.Name or 'Item'
    local quantity = args.quantity or args.Quantity or 'Unknown'
    local rarity = args.rarity or args.Rarity or 'Unknown'

    local output = string.format('|-\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n', name, quantity, rarity)

    return mw.text.tag('tr', output)
end

return p