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: Difference between revisions

From Vault Hunters Official Wiki
Undo revision 2895 by JoshuaEpstein (talk)
Tags: Undo Reverted
No edit summary
Tag: Manual revert
Line 9: Line 9:


     if name == "" then
     if name == "" then
         return "''Error: No player name provided.''"
         return "Error: No player name provided."
     end
     end


     -- Build the image URL
     -- Construct the image URL
     local url = string.format("https://mc-heads.net/avatar/%s/%d", name, size)
     local base = "https://mc-heads.net/avatar/"
    local url = string.format("%s%s/%d", base, name, size)
     if overlay == "no" then
     if overlay == "no" then
         url = url .. ".png?overlay=false"
         url = url .. ".png?overlay=false"
     end
     end


     -- Construct an external <img> using wikitext only
     -- Build the <img> tag
     local img = string.format(
     local img = mw.html.create("img")
         '<img src="%s" width="%d" height="%d" alt="%s" class="mc-player-head" />',
         :addClass("mc-player-head")
         url,
         :attr("src", url)
         size,
         :attr("width", size)
         size,
         :attr("height", size)
        title
    )


     return frame:preprocess(img)
    if title ~= "" then
        img:attr("title", title)
        img:attr("alt", title)
    else
        img:attr("alt", "")
    end
 
     return tostring(img)
end
end


return p
return p

Revision as of 18:28, 6 July 2025

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

local p = {}

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 = mw.text.trim(args[3] or "")
    local overlay = mw.text.trim(args["overlay"] or "yes")

    if name == "" then
        return "Error: No player name provided."
    end

    -- Construct the image URL
    local base = "https://mc-heads.net/avatar/"
    local url = string.format("%s%s/%d", base, name, size)
    if overlay == "no" then
        url = url .. ".png?overlay=false"
    end

    -- Build the <img> tag
    local img = mw.html.create("img")
        :addClass("mc-player-head")
        :attr("src", url)
        :attr("width", size)
        :attr("height", size)

    if title ~= "" then
        img:attr("title", title)
        img:attr("alt", title)
    else
        img:attr("alt", "")
    end

    return tostring(img)
end

return p