From Dark and Darker Wiki
m (p. prefix removed) Tag: Reverted |
Tag: Undo |
||
Line 6: | Line 6: | ||
local monster_grades = {"Common", "Elite", "Nightmare"} --array used just for ordering them | local monster_grades = {"Common", "Elite", "Nightmare"} --array used just for ordering them | ||
function load_data_id_page(id) | function p.load_data_id_page(id) | ||
local data_page_name = "Data:" .. id .. ".json" | local data_page_name = "Data:" .. id .. ".json" | ||
return mw.loadJsonData(data_page_name) | return mw.loadJsonData(data_page_name) | ||
end | end | ||
function create_loot_table(droprate_id, lootdrop_id) | function p.create_loot_table(droprate_id, lootdrop_id) | ||
if type(droprate_id) == "table" and droprate_id.args then -- if called via wikitext instead of lua | if type(droprate_id) == "table" and droprate_id.args then -- if called via wikitext instead of lua | ||
local frame = droprate_id | local frame = droprate_id | ||
Line 21: | Line 21: | ||
droprate_id = "Droprate Monsters Bosses" | droprate_id = "Droprate Monsters Bosses" | ||
local lootdrop_data = load_data_id_page(lootdrop_id) | local lootdrop_data = p.load_data_id_page(lootdrop_id) | ||
if lootdrop_data == nil then return "Lootdrop data file for id '" .. lootdrop_id .. "' could not be found." end | if lootdrop_data == nil then return "Lootdrop data file for id '" .. lootdrop_id .. "' could not be found." end | ||
--local droprate_data = load_data_id_page(droprate_id) | --local droprate_data = p.load_data_id_page(droprate_id) | ||
if droprate_data == nil then return "Droprate data file id'" .. droprate_id .. "' could not be found." end | if droprate_data == nil then return "Droprate data file id'" .. droprate_id .. "' could not be found." end | ||
Line 74: | Line 74: | ||
end | end | ||
function create_monster_loot_tables(frame) | function p.create_monster_loot_tables(frame) | ||
local monster_localized_name = frame.args[1] -- Ghost King | local monster_localized_name = frame.args[1] -- Ghost King | ||
Line 113: | Line 113: | ||
end | end | ||
local spawner_data = load_data_id_page(spawner_id) | local spawner_data = p.load_data_id_page(spawner_id) | ||
if spawner_data == nil then return "Spawner data page for id '" .. spawner_id "' not found." end | if spawner_data == nil then return "Spawner data page for id '" .. spawner_id "' not found." end | ||
Revision as of 21:10, 19 May 2025
Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 17: bad argument #1 to 'old_pairs' (table expected, got nil).
local utils = require("Module:Utilities")
local p = {}
local monsters_data = mw.loadJsonData("Data:Monster.json")
local monster_localized_names = monsters_data["monster_localized_names"] --nickname
local monster_ids = monsters_data["monster_ids"] --nickname
local monster_grades = {"Common", "Elite", "Nightmare"} --array used just for ordering them
function p.load_data_id_page(id)
local data_page_name = "Data:" .. id .. ".json"
return mw.loadJsonData(data_page_name)
end
function p.create_loot_table(droprate_id, lootdrop_id)
if type(droprate_id) == "table" and droprate_id.args then -- if called via wikitext instead of lua
local frame = droprate_id
droprate_id = frame.args[1]
lootdrop_id = frame.args[2]
end
lootdrop_id = "Lootdrop GhostKing"
droprate_id = "Droprate Monsters Bosses"
local lootdrop_data = p.load_data_id_page(lootdrop_id)
if lootdrop_data == nil then return "Lootdrop data file for id '" .. lootdrop_id .. "' could not be found." end
--local droprate_data = p.load_data_id_page(droprate_id)
if droprate_data == nil then return "Droprate data file id'" .. droprate_id .. "' could not be found." end
local resulting_table = ""
resulting_table = resulting_table .. '<table cellspacing="0" class="loottable stripedtable sortable jquery-tablesorter mw-collapsible" style="width:100%">'
resulting_table = resulting_table .. ' <caption>Loot Table at 0 Luck</caption>'
resulting_table = resulting_table .. ' <tr><th style="width:5%">Name</th><th class="tooltip" style="width:5%"><u>Luck Grade</u><span class="tooltiptext-left" style="left:50%; transform:translate(-50%); bottom:66%; width:100%">Luck Grades present on the graph but missing in the column below are associated with dropping nothing.</span></th><th style="width:5%">Rarity</th><th style="width:5%">Item Count</th></tr>'
-- Create body of table
-- Item name, luck grade, rarity, item count
for i, item_name in ipairs(lootdrop_data["item_order"]) do
-- Get the item's data
local item_data = lootdrop_data["item"][item_name]
if item_data == nil then return "item_name '" .. item_name .. "' from item_order not found in lootdrop_data." end
-- Iterate each record in the item data
local num_records = 0 --used for determining rowspan
for j, item_record in ipairs(item_data) do
num_records = num_records+1
end
for j, item_record in ipairs(item_data) do
local luck_grade = item_record[1] --lua is index1 based
local rarity_num = item_record[2]
local count = item_record[3]
if luck_grade == nil then return "item_name '" .. item_name .. "' has a missing luck_grade." end
if rarity_num == nil then return "item_name '" .. item_name .. "' has a missing rarity." end
if count == nil then return "item_name '" .. item_name .. "' has a missing count." end
local rarity_name = utils.rarity_num_to_name(rarity_num)
if rarity_name == nil then return "rarity_num of '" .. rarity_num .. "' was converted to a nil rarity_name." end
local rowspan_str = ""
if j==1 and num_records > 1 then --if first record and there are multiple records; span all records
rowspan_str = "<td rowspan='" .. num_records .. "'" .."><div class='iconbox'><div class='rarity2 rounded relative'>[[File:"..item_name..".png|x80px|link="..item_name.."]]</div>[[" .. item_name .. "]]</div>" .. "</td>"
end
resulting_table = resulting_table .. "<tr>"
resulting_table = resulting_table .. rowspan_str
resulting_table = resulting_table .. "<td class='cr"..luck_grade.."'><b>" .. luck_grade .. "</b></td>"
resulting_table = resulting_table .. "<td class='cr"..rarity_num.."'><b>" .. rarity_name .. "</b></td>"
resulting_table = resulting_table .. "<td>" .. count .. "</td>"
resulting_table = resulting_table .. "</tr>"
end
end
resulting_table = resulting_table .. '</table><br>'
return resulting_table
end
function p.create_monster_loot_tables(frame)
local monster_localized_name = frame.args[1] -- Ghost King
local my_monster_ids = monster_localized_names[monster_localized_name] -- {Common: id of Common monster, }
if my_monster_ids == nil then return "Monster '" .. monster_localized_name .. "' was not found in monsters_data." end
local outputted_string = ""
for i, monster_grade_key in ipairs(monster_grades) do --mgk of --Elite
-- Get the monster
monster_grade_id = my_monster_ids[monster_grade_key] --Id_Monster_GhostKing_Elite
if monster_grade_id ~= nil then
spawner_ids = monster_ids[monster_grade_id]["spawner_ids"]
outputted_string = outputted_string .. create_monster_grade_loot_tables(monster_grade_id, spawner_ids)
end
end
return outputted_string
end
function create_monster_grade_loot_tables(monster_grade_id, spawner_ids)
if type(monster_grade_id) == "table" and monster_grade_id.args then -- if called via wikitext instead of lua
local frame = monster_grade_id
monster_grade_id = frame.args[1] -- Id_Monster_GhostKing_Elite
spawner_ids = frame.args[2] -- {"Id_Spawner_New_Monster_GhostKing": true}
end
local outputted_string = ""
for spawner_id, b in pairs(spawner_ids) do
outputted_string = outputted_string .. create_spawner_loot_tables(spawner_id)
end
return outputted_string
end
function create_spawner_loot_tables(spawner_id)
if type(spawner_id) == "table" and spawner_id.args then -- if called via wikitext instead of lua
local frame = spawner_id
spawner_id = frame.args[1]
end
local spawner_data = p.load_data_id_page(spawner_id)
if spawner_data == nil then return "Spawner data page for id '" .. spawner_id "' not found." end
return "Cool" .. spawner_id
end
return p