Jump to content

Module:GetEffect

From Untitled Monster Game
Revision as of 16:06, 9 February 2026 by imported>Ziebster (Created page with "local p = {} function p.getEffect(frame) local pageName = frame.args[1] or mw.title.getCurrentTitle().text local statName = frame.args[2] local page = mw.title.new(pageName) if not page then return 'Page not found' end local content = page:getContent() local effect = content:match('|%s*effects%s*=%s*(.-)\n%s*|') or content:match('|%s*effects%s*=%s*(.-)$') or '' effect = mw.text.trim(effect) if not statName or st...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Example usage here:


local p = {}

function p.getEffect(frame)
    local pageName = frame.args[1] or mw.title.getCurrentTitle().text
    local statName = frame.args[2]
    
    local page = mw.title.new(pageName)
    if not page then
        return 'Page not found'
    end
    
    local content = page:getContent()
    local effect = content:match('|%s*effects%s*=%s*(.-)\n%s*|') or content:match('|%s*effects%s*=%s*(.-)$') or ''
    effect = mw.text.trim(effect)
    
    if not statName or statName == '' then
        -- Return full effect if no stat specified
        return effect
    end
    
    -- Normalize statName for case-insensitive matching
    local normalizedStat = statName:lower()
    
    -- Split the effect into comma-separated parts
    local parts = mw.text.split(effect, ',')
    for _, part in ipairs(parts) do
        part = mw.text.trim(part)
        -- Match pattern: +number%? stat (e.g., +15 W.PWR, +15% CRIT, +1.5 Speed)
        local num, percent, key = part:match('^([+-]?[%d%.]+)(%%?)%s+(.*)$')
        if num and key then
            local normKey = mw.text.trim(key):lower()
            if normKey == normalizedStat then
                -- Strip leading '+' if present
                if num:sub(1,1) == '+' then
                    num = num:sub(2)
                end
                return num
            end
        end
    end
    
    -- If not found, return empty string
    return ''
end

return p