Module:TableGenerator: Difference between revisions

From AoP Wiki
Created Ammo List Module for testing out stuffs
 
Tier should be greater then 0.
 
(13 intermediate revisions by the same user not shown)
Line 3: Line 3:
local p = {}
local p = {}


function p.getAmmoList()
function p.getAmmoTable()
local records = mw.ext.externalData.getExternalData 'http://localhost/foaop/planner/ammo.json'.__json
--local records = mw.ext.externalData.getExternalData 'http://localhost/foaop/planner/ammo.json'.__json
local table = {}
local records = mw.ext.externalData.getExternalData {
source = 'ammo'
}.__json
 
local ammoTable = {}
for k,v in pairs(records) do
for k,v in pairs(records) do
if v.Tier then
if v.Tier and v.Tier > 0 then
mw.logObject(v)
table.insert(ammoTable, v)
--mw.log(k,v)
length = length +1
end
end
end
if length == 5 then
return true
function sortingFunction(a, b)
if a.Tier ~= b.Tier then
return a.Tier < b.Tier
else
return a.Name < b.Name
end
end
end
end
table.sort(ammoTable, sortingFunction)
 
if not ammoTable then
return true
        return "No ammo data available."
    end
   
    local output = ""
    for _, ammo in ipairs(ammoTable) do
    output = output .."|-".."\n"
output = output .."|".. ammo.Tier .."\n"
output = output .."|[[".. ammo.Name .."]]\n"
output = output .."|https://uralez.de/foaop/planner/".. ammo.PicInv .."\n"
    end
    return output
end
end


function p.main(frame)
function p.main(frame)

Latest revision as of 18:13, 24 February 2025

Documentation for this module may be created at Module:TableGenerator/doc

--print(), mw.log() and mw.logObject()

local p = {}

function p.getAmmoTable()
	--local records = mw.ext.externalData.getExternalData 'http://localhost/foaop/planner/ammo.json'.__json
	
	local records = mw.ext.externalData.getExternalData {
	source = 'ammo'
	}.__json

	local ammoTable = {}
	
	for k,v in pairs(records) do
		if v.Tier and v.Tier > 0 then
			table.insert(ammoTable, v)
		end
	end
	
	function sortingFunction(a, b)
		if a.Tier ~= b.Tier then
			return a.Tier < b.Tier
		else
			return a.Name < b.Name
		end
	end
	table.sort(ammoTable, sortingFunction)
	
	if not ammoTable then
        return "No ammo data available."
    end
    
    local output = ""
    for _, ammo in ipairs(ammoTable) do
    	output = output .."|-".."\n"
		output = output .."|".. ammo.Tier .."\n"
		output = output .."|[[".. ammo.Name .."]]\n"
		output = output .."|https://uralez.de/foaop/planner/".. ammo.PicInv .."\n"
    end
    return output
end

function p.main(frame)
   local args = frame.args
   
   
   local records = mw.ext.externalData.getExternalData 'http://localhost/foaop/planner/ammo.json'.__json
   
   
   local id = 29
	local record = mw.ext.externalData.getExternalData {
	source = 'http://localhost/foaop/planner/ammo.json',
	format = 'json with jsonpath',
	data = { record = '$[?(@.ProtoId == ' .. tostring (id) .. ')]' }
	}.record

	mw.logObject(record2)
   
   return args[1]..args["sep"]..args[2]
end
return p