Module:NpcData: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
Fixed get_nested_var to handle numeric-string keys
LVL (talk | contribs)
Removed obsolete get_ability_key; get_nested_var covers BoundAbilities access
Line 78: Line 78:
return element
return element
end
-- Retrieves an ability key from an NPC's "BoundAbilities" map.
--{{#invoke:NpcData|get_ability_key|NPC_KEY|SLOT_KEY}}--
p.get_ability_key = function(frame)
local npc_name = frame.args[1] and mw.text.trim(frame.args[1]) or nil
local slot_name = frame.args[2] and mw.text.trim(frame.args[2]) or nil
if not npc_name or npc_name == '' then return '<span class="error">Error: NPC name not provided.</span>' end
    if not slot_name or slot_name == '' then return '<span class="error">Error: Slot name not provided.</span>' end
local npc_data = npcs_data[npc_name]
if not npc_data then return '<span class="error">Error: NPC "'..npc_name.. '" not found.</span>' end
local bound_abilities_data = npc_data["BoundAbilities"]
if not bound_abilities_data or type(bound_abilities_data) ~= "table" then
return '<span class="error">Error: NPC "' .. npc_name .. '" has no \'BoundAbilities\' data.</span>'
end
local ability_key = bound_abilities_data[slot_name]
    if not ability_key then
return '<span class="error">Error: Slot "' .. slot_name .. '" not found for NPC "' .. npc_name .. '".</span>'
end
   
return ability_key
end
end