Editing Module:NpcData

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 13: Line 13:
end
end


-- Retrieves a specific stat value for a given NPC.
-- Retrieves a specific stat value for a given NPC. Handles both simple and nested calls.
-- Retrieves a specific stat value for a given NPC. Handles both simple and nested calls.
-- {{#invoke:NpcData|get_npc_var|NPC_KEY|STAT_KEY_1|STAT_KEY_2|...|SIG_FIGS}}
-- {{#invoke:NpcData|get_npc_var|NPC_KEY|STAT_KEY_1|STAT_KEY_2|...|SIG_FIGS}}
Line 95: Line 96:


     return current_value
     return current_value
end
-- Retrieves a nested value using dot notation (e.g., "Shield.BaseAbsorptionPerSecond")
--{{#invoke:NpcData|get_nested_var|NPC_KEY|PATH|SIG_FIGS}}--
p.get_nested_var = function(frame)
local args = frame.args
local npc_name = args[1] and mw.text.trim(args[1]) or nil
local path = args[2] and mw.text.trim(args[2]) or nil
local sig_figs = args[3] and mw.text.trim(args[3]) or nil
if not npc_name or npc_name == '' then
return '<span class="error">Error: NPC name not provided.</span>'
end
if not path or path == '' then
return '<span class="error">Error: Path not provided.</span>'
end
local npc = npcs_data[npc_name]
if not npc then
return '<span class="error">Error: NPC "' .. npc_name .. '" not found.</span>'
end
-- Traverse nested structure
local value = npc
for key in string.gmatch(path, '([^.]+)') do
    if type(value) ~= "table" then
        return '<span class="error">Error: Path "' .. path .. '" is invalid.</span>'
    end
    -- try first with the raw key, then with a number conversion
    local next = value[key] or value[tonumber(key)] or value[tostring(key)]
    if next == nil then
        return '<span class="error">Error: Key "' .. key .. '" not found in path.</span>'
    end
    value = next
end
-- Apply rounding if needed
if sig_figs and tonumber(sig_figs) then
value = util_module.round_to_sig_fig(value, sig_figs)
if value == nil then
return '<span class="error">Error: Rounding failed for value.</span>'
end
end
return value
end
end


return p
return p
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Pages included on this page: