Jump to content

Module:HeroData/name

From Deadlock Wiki

Overview[edit source]

Retrieves the internal hero key matching the specified hero name.

Functions[edit source]

get_hero_key(frame)[edit source]

For Template:HeroIcon

Examples[edit source]

{{#invoke:HeroData/name|get_hero_key|Abrams}}

hero_atlas

Parameters[edit source]

hero_name_input (string) - The hero's display name to look up (case-insensitive)


local p = {}
local heroes_data = mw.loadJsonData("Data:HeroData.json")

-- {{#invoke:Sandbox|get_hero_key|hero name}}
function p.get_hero_key(frame)
    local hero_name_input = frame.args[1] -- Get the hero name from the template argument
    if not hero_name_input then
        return "Error: Hero name not specified."
    end

    hero_name_input = hero_name_input:lower() -- For case-independent search

    -- Go through all the characters and look for a name match.
    for hero_key, hero_data in pairs(heroes_data) do
        if hero_data["Name"] then
            local current_hero_name = hero_data["Name"]:lower()
            if current_hero_name == hero_name_input then
                return hero_key -- Return the key if the name matches
            end
        end
    end

    return "Hero not found." -- If nothing is found
end

return p