Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 21:41, 11 May 2026 by NIK220V (talk | contribs) (Created page with "local p = {} -- Load the data from the database module using mw.loadData for caching efficiency local db = mw.loadData('Module:Mob/Aliases') function p.main(frame) -- Get arguments from either the module call or the parent template local args = frame:getParent().args local mobName = args[1] or frame.args[1] if not mobName or mobName == "" then return "<strong class='error'>Error: Please specify a mob name.</strong>" end local mob = db[...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

-- Load the data from the database module using mw.loadData for caching efficiency
local db = mw.loadData('Module:Mob/Aliases')

function p.main(frame)
    -- Get arguments from either the module call or the parent template
    local args = frame:getParent().args
    local mobName = args[1] or frame.args[1]

    if not mobName or mobName == "" then
        return "<strong class='error'>Error: Please specify a mob name.</strong>"
    end

    local mob = db[mobName]
    if not mob then
        return "<strong class='error'>Error: Mob '" .. mobName .. "' not found in database.</strong>"
    end

    -- 1. Format the layers
    local layersHtml = {}
    if mob.layers and #mob.layers > 0 then
        for _, layer in ipairs(mob.layers) do
            table.insert(layersHtml, "[[File:" .. layer .. ".png|16px|link=]]")
        end
    end

    -- 2. Format the drops table
    local dropsHtml = ""
    if mob.drops and #mob.drops > 0 then
        dropsHtml = '<table class="wikitable" style="width:100%; margin-top:5px;">\n<tr><th>Drop</th><th>Chance</th><th>Amount</th></tr>\n'
        for _, drop in ipairs(mob.drops) do
            local title = drop.lootingWorks and "Looting works" or "No looting"
            local amountStr = drop.lootingWorks and ("<b>" .. drop.amount .. "</b>") or drop.amount
            -- Uses the {{Slot}} template dynamically
            dropsHtml = dropsHtml .. string.format(
                '<tr><td>{{Slot|%s}}</td><td>%s</td><td title="%s">%s</td></tr>\n', 
                drop.item, drop.chance, title, amountStr
            )
        end
        dropsHtml = dropsHtml .. "</table>"
    end

    -- 3. Construct the arguments to pass to the visual Template
    local targs = {
        name = mob.name,
        namecolor = mob.nameColor or "inherit",
        health = tostring(mob.health),
        category = mob.category,
        layers = table.concat(layersHtml, " "),
        drops = dropsHtml,
        -- You can override the image by passing a 2nd argument, otherwise it falls back to the default in the Layout
        image = args.image or args[2] or "" 
    }

    -- 4. Pass the calculated data to the layout template
    return frame:expandTemplate{ title = 'Template:Mob/Layout', args = targs }
end

return p