Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:PlayerHead

From Vault Hunters Official Wiki
Revision as of 17:43, 6 July 2025 by JoshuaEpstein (talk | contribs) (Created page with "local p = {} -- escape HTML attribute values becuase I have idea if this exists or not local function escape(s) return (s:gsub('[\"&\'<>]', { ['"'] = """, ["&"] = "&", ["'"] = "'", ["<"] = "<", [">"] = ">" })) end function p.render(frame) local args = frame:getParent().args local name = mw.text.trim(args[1] or "") local size = tonumber(args[2]) or 64 local title = args[3] or ""...")
(diff) ← Older revision | Latest revision (diff) | Newer revision β†’ (diff)

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

local p = {}

--  escape HTML attribute values becuase I have idea if this exists or not
local function escape(s)
    return (s:gsub('[\"&\'<>]', {
        ['"'] = "&quot;",
        ["&"] = "&amp;",
        ["'"] = "&#39;",
        ["<"] = "&lt;",
        [">"] = "&gt;"
    }))
end

function p.render(frame)
    local args   = frame:getParent().args
    local name   = mw.text.trim(args[1] or "")
    local size   = tonumber(args[2]) or 64
    local title  = args[3] or ""
    local overlay = (args.overlay or "yes"):lower()  -- "yes" (default) or "no"

    if name == "" then
        return "<strong class=\"error\">PlayerHead: no player specified</strong>"
    end

    -- Build URL – MC-Heads supports sizes 8 - 600 px and an optional /nohelm suffix :contentReference[oaicite:0]{index=0}
    local url = string.format(
        "https://mc-heads.net/avatar/%s/%d%s",
        escape(name),
        size,
        overlay == "no" and "/nohelm" or ""
    )

    -- Make da tag
    local img = '<img class="mc-player-head"'
        .. string.format(' src="%s"', url)
        .. string.format(' width="%d" height="%d"', size, size)
        .. (title ~= "" and string.format(' title="%s" alt="%s"', escape(title), escape(title)) or ' alt=""')
        .. ' />'

    return img
end

return p