Module:HeroList
From Heroes of Might and Magic: Olden Era Official Wiki
Description
This module generates an automated table of heroes belonging to a specific faction. It dynamically retrieves localization for hero names, classes, and specializations, and formats the starting skills and spells into a clean, sortable layout.
Usage
The module is invoked via the display function:
{{#invoke:HeroList|display|faction=...|language=...}}
Parameters
| Parameter | Description | Example |
|---|---|---|
faction |
The name of the faction (as stored in the Translation table). | faction=Necropolis
|
language |
Forces the Wiki language (if omitted, it detects the page suffix). | language=fr
|
Key Features
- Dynamic Localization: Translates headers (Name, Class, etc.) and hero-specific data (Names, Skills, Spells) based on the provided language.
- Automatic Formatting:
- Displays hero portraits and icons.
- Formats specializations with tooltips showing descriptions.
- Lists starting skills and spells as link-lists with icons.
- Sorting Support: The table uses the
sortableclass, allowing users to reorder heroes based on columns. - Data Cleanup: Automatically filters out campaign, tutorial, and internal testing heroes (e.g.,
cm_fun).
Implementation Example
To display all heroes of the "Necropolis" faction:
== Necropolis Heroes ==
{{#invoke:HeroList|display|faction=Necropolis}}
Technical Notes
- The module queries the
Herotable and joins data with theTranslationtable. - It uses
sortabletables; ensure the MediaWiki "Sortable" extension is active for full functionality. - Specialization icons are automatically inferred from the
HeroSpecializationtable and formatted to match faction naming conventions.
Examples
{{#invoke:HeroList|display|faction=Necropolis}}
| Portrait | Nom | Classe | Icône | Spécialisation |
|---|---|---|---|---|
| Bulwark | Death Knight | File:Necro Hero 1 Specialization Icon.png | Built Different (+++++) | |
| King-of-Kings | Death Knight | File:Necro Hero 2 Specialization Icon.png | Charismatic (+++++) | |
| Onkos | Death Knight | File:Necro Hero 3 Specialization Icon.png | Perfect Puppets <span title="Skeleton growth in your cities increases by 1. Under his command, Skeletons gain 1 Speed, 1 Initiative, and 20% HP. Their Attack and Defense increase by 1 for every 3 hero levels, and enemy Skeletons lose an equal amount of Attack and Defense.">(+++++) | |
| Kel'Ghul | Death Knight | File:Necro Hero 4 Specialization Icon.png | Dreadful War <span title="Dread Knight growth in your cities increases by 1. Under his command, Dread Knights gain 1 Speed, 1 Initiative, and 20% HP. Their Attack and Defense increase by 1 for every 3 hero levels, and enemy Dread Knights lose an equal amount of Attack and Defense.">(+++++) | |
| Natalida | Death Knight | File:Necro Hero 5 Specialization Icon.png | Part of a Pack <span title="Undead Pet growth in your cities increases by 1. Under her command, Undead Pets gain 1 Speed, 1 Initiative, and 20% HP. Their Attack and Defense increase by 1 for every 3 hero levels, and enemy Undead Pets lose an equal amount of Attack and Defense.">(+++++) | |
| Artorius Veritas | Death Knight | File:Necro Hero 6 Specialization Icon.png | Drive 'em Crazy <span title="He starts with the “Masterful Berserk” spell. This version of the spell affects all creatures adjacent to the target. The cost of this spell is reduced by 1 mana for every 3 hero level(s).">(+++++) | |
| Marl | Death Knight | File:Necro Hero 7 Specialization Icon.png | Languid Soil <span title="He starts with the “Masterful Web” spell. This version of the spell affects all enemies. While casting this spell, effective Spell Power is increased by 1 for every 2 hero level(s).">(+++++) | |
| Tarius | Death Knight | File:Necro Hero 8 Specialization Icon.png | Undead Legion (+++++) | |
| Zam | Death Knight | File:Necro Hero 9 Specialization Icon.png | Alchemist (+++++) | |
| Mag | Necromancer | File:Necro Hero 10 Specialization Icon.png | Arcane Dominion (+++++) | |
| Adahn | Necromancer | File:Necro Hero 11 Specialization Icon.png | Amnesiac <span title="Wight growth in your cities increases by 1. Under his command, Wights gain 1 Speed, 1 Initiative, and 20% HP. Their Attack and Defense increase by 1 for every 3 hero levels, and enemy Wights lose an equal amount of Attack and Defense.">(+++++) | |
| Ethric | Necromancer | File:Necro Hero 12 Specialization Icon.png | Tomb-bound Will <span title="Lich growth in your cities increases by 1. Under his command, Liches gain 1 Speed, 1 Initiative, and 20% HP. Their Attack and Defense increase by 1 for every 3 hero levels, and enemy Liches lose an equal amount of Attack and Defense.">(+++++) | |
| Guildmaster Klastor | Necromancer | File:Necro Hero 13 Specialization Icon.png | Bones Guild <span title="Graverobber growth in your cities increases by 1. Under his command, Graverobbers gain 1 Speed, 1 Initiative, and 20% HP. Their Attack and Defense increase by 1 for every 3 hero levels, and enemy Graverobbers lose an equal amount of Attack and Defense.">(+++++) | |
| Shadespinner Oona | Necromancer | File:Necro Hero 14 Specialization Icon.png | Shadowmastery (+++++) | |
| Laura | Necromancer | File:Necro Hero 15 Specialization Icon.png | Moldering <span title="She starts with the “Masterful Despair” spell. This version of the spell affects all types of enemies. While casting this spell, effective Spell Power is increased by 1 for every 2 hero level(s).">(+++++) | |
| Lord Rufus | Necromancer | File:Necro Hero 16 Specialization Icon.png | Wistful Nostalgia <span title="He starts with the “Masterful Rewind Life” spell. This version of the spell can revive units beyond their original amount. While casting this spell, effective Spell Power is increased by 1 for every 2 hero level(s).">(+++++) | |
| Funerella | Necromancer | File:Necro Hero 17 Specialization Icon.png | Undead Legion (+++++) | |
| Milossa the Golden | Necromancer | File:Necro Hero 18 Specialization Icon.png | Wealthy (+++++) |
{{#invoke:HeroList|display|faction=Grove|language=ja}}
| Portrait | Nom | Classe | Icône | Spécialisation |
|---|---|---|---|---|
| イース | ウォーデン | File:Nature Hero 1 Specialization Icon.png | パスファインダー (+++++) | |
| 槍頭のゴレル | ウォーデン | File:Nature Hero 2 Specialization Icon.png | 射手 (+++++) | |
| ジンジャーテール | ウォーデン | File:Nature Hero 3 Specialization Icon.png | フォーンソング <span title="自都市における「フォーン」の生産数が1増加する。 指揮下の「フォーン」の素早さとイニシアチブが1、HPが20%増加する。さらに、ヒーローレベル3ごとに攻撃力と防御力が1増加し、敵の「フォーン」は同じ値だけ攻撃力と防御力が減少する。">(+++++) | |
| 巡礼の老人 | ウォーデン | File:Nature Hero 4 Specialization Icon.png | 自然の選択 <span title="呪文「マスター:ギロチン」を習得した状態で開始する。このマスター呪文は、同一の対象に対して唱えると、ダメージの増加速度が通常の2倍となる。 また、詠唱中は有効な呪文力がヒーローレベル2ごとに1増加する。">(+++++) | |
| オクタヴィア | ウォーデン | File:Nature Hero 5 Specialization Icon.png | 四葉の馬蹄 (+++++) | |
| ニャオワ | ウォーデン | File:Nature Hero 6 Specialization Icon.png | 魅惑の輝き (+++++) | |
| ファレオール | ウォーデン | File:Nature Hero 7 Specialization Icon.png | フクスミラの歩み <span title="呪文「マスター:火球」を習得した状態で開始する。このマスター呪文は、通常の「火球」よりも広い範囲に効果を及ぼす。 また、詠唱中は有効な呪文力がヒーローレベル2ごとに1増加する。">(+++++) | |
| 魅惑のシャー | ウォーデン | File:Nature Hero 8 Specialization Icon.png | カリスマ (+++++) | |
| ダリアおばさん | ウォーデン | File:Nature Hero 9 Specialization Icon.png | 学びの願い (+++++) | |
| ヴァトウナ | ドルイド | File:Nature Hero 10 Specialization Icon.png | 魂の活力 (+++++) | |
| 老ツ=キッシュ | ドルイド | File:Nature Hero 11 Specialization Icon.png | 最古の樹 <span title="自都市における「薬草術士」の生産数が1増加する。 指揮下の「薬草術士」は素早さとイニシアチブが1、HPが20%増加する。さらに、ヒーローレベル3ごとに攻撃力と防御力が1増加し、敵の「薬草術士」は同じ値だけ攻撃力と防御力が減少する。">(+++++) | |
| エアリニエル | ドルイド | File:Nature Hero 12 Specialization Icon.png | 穏やかな燃えさし <span title="呪文「マスター:紅蓮の壁」を習得した状態で開始する。このマスター呪文は、通常の「紅蓮の壁」よりも効果の持続時間が2ラウンド長い。 また、詠唱中は有効な呪文力がヒーローレベル2ごとに1増加する。">(+++++) | |
| グレイシア | ドルイド | File:Nature Hero 13 Specialization Icon.png | 氷撃 <span title="呪文「マスター:氷撃」を習得した状態で開始する。このマスター呪文は、通常の「氷撃」よりもイニシアチブのペナルティが2倍になる。 また、詠唱中は有効な呪文力がヒーローレベル2ごとに1増加する。">(+++++) | |
| ヴィム | ドルイド | File:Nature Hero 14 Specialization Icon.png | ぶちかませ! <span title="呪文「マスター:降石」を習得した状態で開始する。このマスター呪文で生成された障害物を破壊するには、通常の「降石」よりもダメージを1回多く与える必要がある。 また、詠唱中は有効な呪文力がヒーローレベル2ごとに1増加する。">(+++++) | |
| ハロン | ドルイド | File:Nature Hero 15 Specialization Icon.png | 轟雷 <span title="呪文「マスター:連鎖雷撃」を習得した状態で開始する。このマスター呪文は、対象間で連鎖するときに減衰するダメージが通常の半分になる。 また、詠唱中は有効な呪文力がヒーローレベル2ごとに1増加する。">(+++++) | |
| エコリリー | ドルイド | File:Nature Hero 16 Specialization Icon.png | ざわめきの模倣 <span title="呪文「マスター:ミラーコピー」を習得した状態で開始する。このマスター呪文は、敵のクリーチャーを対象にできる。 また、詠唱中は有効な呪文力がヒーローレベル2ごとに1増加する。">(+++++) | |
| サリー | ドルイド | File:Nature Hero 17 Specialization Icon.png | ざわめきの森の原住民 <span title="自身が召喚した化身は魔法ダメージを無効化する。 「化身召喚」を唱えるとき、有効な呪文力がヒーローレベル2ごとに1増加する。">(+++++) | |
| 吟遊詩人 | ドルイド | File:Nature Hero 18 Specialization Icon.png | 放浪の音楽家 (+++++) |
local p = {}
-- Fonction pour mettre la première lettre de chaque mot en majuscule
local function toTitleCase(str)
return str:gsub("(%a)([%w_]*)", function(first, rest)
return first:upper() .. rest:lower()
end)
end
-- Fonction utilitaire pour récupérer une traduction
local function getTrans(target_id, lang, type, field)
field = field or "name"
if not target_id or target_id == "" then return nil end
local query = mw.ext.cargo.query("Translation", field, {
where = string.format("target_id = '%s' AND language = '%s' AND type = '%s'", target_id, lang, type),
limit = 1
})
if not query or #query == 0 then
query = mw.ext.cargo.query("Translation", "name", {
where = string.format("target_id = '%s' AND language = 'en' AND type = '%s'", target_id, type),
limit = 1
})
end
return (query and #query > 0) and query[1][field] or nil
end
function p.display(frame)
local raw_faction = frame.args.faction
local lang = frame.args.language or mw.title.getCurrentTitle().text:match("/(%a%a)$") or "en"
local faction_query = mw.ext.cargo.query("Translation", "target_id", {
where = string.format("name = '%s' AND type = 'faction'", raw_faction),
limit = 1
})
local faction_id = (faction_query and #faction_query > 0) and faction_query[1].target_id or raw_faction
local heroes = mw.ext.cargo.query("Hero", "id, name_sid, class_id, specialization_id", {
where = string.format("faction = '%s' AND id NOT LIKE '%%campaign%%' AND id NOT LIKE '%%tutorial%%' AND id NOT LIKE '%%cm_fun%%'", faction_id)
})
table.sort(heroes, function(a, b)
local numA = tonumber(a.id:match("(%d+)$")) or 0
local numB = tonumber(b.id:match("(%d+)$")) or 0
return numA < numB
end)
local html = {'{| class="wikitable sortable"', '! Portrait !! Nom !! Classe !! Icône !! Spécialisation'}
for _, h in ipairs(heroes) do
local name = getTrans(h.name_sid, lang, 'hero') or h.name_sid
local file_name = getTrans(h.name_sid, 'en', 'hero') or h.id
-- CLASSE
local class_name = getTrans(h.class_id, lang, 'hero_class') or h.class_id
-- SPÉCIALISATION
local spec_name = getTrans(h.specialization_id, lang, 'hero_specialization') or h.specialization_id
local spec_desc = getTrans(h.specialization_id, lang, 'hero_specialization', 'description') or "Pas de description"
-- Nettoyage de la description pour l'infobulle (retrait des sauts de ligne et échappement)
local clean_desc = spec_desc:gsub("\n", " "):gsub("\r", " "):gsub('"', '"')
-- Récupération et formatage icône
local icon_data = mw.ext.cargo.query("HeroSpecialization", "icon", {where = string.format("id = '%s'", h.specialization_id), limit = 1})
local icon_val = (icon_data and #icon_data > 0) and icon_data[1].icon or ""
local formatted_icon = toTitleCase(icon_val:gsub("_", " "))
local spec_icon = string.format("[[File:%s.png|70px|link=]]", formatted_icon)
-- Construction du bloc spécialisation formaté
local spec_formatted = string.format("'''%s'''<br><span title=\"%s\"><sup>(+++++)</sup></span>", spec_name, clean_desc)
table.insert(html, "|-")
table.insert(html, string.format('| [[File:%s.png|70px]]', file_name))
table.insert(html, string.format('| [[%s|%s]]', file_name, name))
table.insert(html, "| " .. class_name)
table.insert(html, "| " .. spec_icon)
table.insert(html, "| " .. spec_formatted)
end
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


