Content added Content deleted
No edit summary |
No edit summary Tag: Manual revert |
||
(215 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local lootTable = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{title='Template:Loot tables.json'}) |
|||
local json = require('Module:Json') |
|||
local jsonraw = '{"Paddy": { "chance":0.33, "item":"Blue Linen Coat", "quantity":1},"Paddy": { "chance":0.33, "item":"Blue Cloth Pads", "quantity":1},"Paddy": { "chance":0.33, "item":"Green Worker Shirt", "quantity":1}}' |
|||
local jsonparse = json.decode( jsonraw ) |
|||
local p = {} |
local p = {} |
||
p. |
p.getLootTable = function(frame) |
||
local npc = frame.args[1] |
local npc = frame.args[1] |
||
local color = '' |
|||
for k, v in pairs(jsonparse) do |
|||
local txt = frame:expandTemplate{ title = 'LootHeader' } |
|||
⚫ | |||
for i=1, #lootTable, 1 do |
|||
if lootTable[i][1] == npc then |
|||
if lootTable[i][2] >= 24.9999 then |
|||
color = 'green' |
|||
elseif lootTable[i][2] >= 9.9999 then |
|||
color = 'yellow' |
|||
elseif lootTable[i][2] >= 2.49999 then |
|||
color = 'orange' |
|||
elseif lootTable[i][2] <= 2.5 then |
|||
color = 'red' |
|||
end |
|||
txt = txt .. frame:expandTemplate{ title = 'LootRow', args = { itemname = lootTable[i][3], quantity = lootTable[i][4],color = color, rarity = lootTable[i][2] .. '%' } } |
|||
end |
|||
end |
end |
||
txt = txt .. frame:expandTemplate{ title = 'LootEnd' } |
|||
⚫ | |||
end |
|||
p.getSourceTable = function(frame) |
|||
local item = frame.args[1] |
|||
local txt = frame:expandTemplate{ title = 'SourceHeader' } |
|||
for i=1, #lootTable, 1 do |
|||
if lootTable[i][3] == item then |
|||
if lootTable[i][2] >= 24.9999 then |
|||
color = 'green' |
|||
elseif lootTable[i][2] >= 9.9999 then |
|||
color = 'yellow' |
|||
elseif lootTable[i][2] >= 2.49999 then |
|||
color = 'orange' |
|||
elseif lootTable[i][2] <= 2.5 then |
|||
color = 'red' |
|||
end |
|||
txt = txt .. frame:expandTemplate{ title = 'SourceRow', args = { npcname = lootTable[i][1], color = color, quantity = lootTable[i][4], rarity = lootTable[i][2] .. '%' } } |
|||
end |
|||
end |
|||
txt = txt .. frame:expandTemplate{ title = 'LootEnd' } |
|||
return txt |
|||
end |
end |
||
Latest revision as of 12:21, 1 February 2022
This module retrieves data from the "Loot tables.json" template according to the {{PAGENAME}} (usually, an NPC name) provided as an argument value.
local lootTable = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{title='Template:Loot tables.json'})
local p = {}
p.getLootTable = function(frame)
local npc = frame.args[1]
local color = ''
local txt = frame:expandTemplate{ title = 'LootHeader' }
for i=1, #lootTable, 1 do
if lootTable[i][1] == npc then
if lootTable[i][2] >= 24.9999 then
color = 'green'
elseif lootTable[i][2] >= 9.9999 then
color = 'yellow'
elseif lootTable[i][2] >= 2.49999 then
color = 'orange'
elseif lootTable[i][2] <= 2.5 then
color = 'red'
end
txt = txt .. frame:expandTemplate{ title = 'LootRow', args = { itemname = lootTable[i][3], quantity = lootTable[i][4],color = color, rarity = lootTable[i][2] .. '%' } }
end
end
txt = txt .. frame:expandTemplate{ title = 'LootEnd' }
return txt
end
p.getSourceTable = function(frame)
local item = frame.args[1]
local txt = frame:expandTemplate{ title = 'SourceHeader' }
for i=1, #lootTable, 1 do
if lootTable[i][3] == item then
if lootTable[i][2] >= 24.9999 then
color = 'green'
elseif lootTable[i][2] >= 9.9999 then
color = 'yellow'
elseif lootTable[i][2] >= 2.49999 then
color = 'orange'
elseif lootTable[i][2] <= 2.5 then
color = 'red'
end
txt = txt .. frame:expandTemplate{ title = 'SourceRow', args = { npcname = lootTable[i][1], color = color, quantity = lootTable[i][4], rarity = lootTable[i][2] .. '%' } }
end
end
txt = txt .. frame:expandTemplate{ title = 'LootEnd' }
return txt
end
return p