Module:Item spawns: Difference between revisions

From The Cycle: Frontier Wiki
(Created page with "local p = {} --p stands for package p.items = mw.loadJsonData( "User:VeryGreatFrog/sandbox2" ) p.lootPools = mw.loadJsonData( "User:VeryGreatFrog/sandbox3" ) p.containers = mw.loadJsonData( "User:VeryGreatFrog/sandbox4" ) local args = mw.getCurrentFrame().args for k, v in pairs(p.items) do if args[1] == v["inGameName"] then p.item = p.items[k]["inGameName"] break end end function p.main( frame ) local output = "" for container, pools in pair...")
 
mNo edit summary
Line 9: Line 9:
for k, v in pairs(p.items) do
for k, v in pairs(p.items) do
     if args[1] == v["inGameName"] then
     if args[1] == v["inGameName"] then
         p.item = p.items[k]["inGameName"]
         p.item = k
         break
         break
     end
     end
Line 17: Line 17:
local output = ""
local output = ""
for container, pools in pairs(p.containers) do
for container, pools in pairs(p.containers) do
output = output .. tostring(container)
for _, pool in ipairs(pools) do
for _, pool in ipairs(pools) do
-- filter out nil pools (Alien Vent only as of 3.0.0)
local curPools = p.lootPools[pool]
if #pool > 0 then
if curPools then
-- check if this item (the key) is in the spawns
-- check if this item (the key) is in the spawns
mw.logObject(pool .. tostring(p.lootPools[pool]))
if curPools["items"][p.item] ~= nil then
-- if p.lootPools[pool]["items"][p.item] ~= nil then
output = output .. pool .. " " .. tostring(curPools["items"][p.item]["chance"]) .. " "
-- output = output .. p.lootPools[pool]["items"][p.item]
end
-- end
end
end
end
end

Revision as of 22:27, 11 April 2023

This module spits out the containers that specific item can spawn in, including chances. Does not show other special spawns or ground spawns.

Parameters

Must always call the main function. The second argument must be the exact name of an item.

Example

{{#invoke:Item spawns|main|Pure Veltecite}}

local p = {} --p stands for package

p.items = mw.loadJsonData( "User:VeryGreatFrog/sandbox2" )
p.lootPools = mw.loadJsonData( "User:VeryGreatFrog/sandbox3" )
p.containers = mw.loadJsonData( "User:VeryGreatFrog/sandbox4" )

local args = mw.getCurrentFrame().args

for k, v in pairs(p.items) do
    if args[1] == v["inGameName"] then
        p.item = k
        break
    end
end

function p.main( frame )
	local output = ""
	for container, pools in pairs(p.containers) do
		for _, pool in ipairs(pools) do
			local curPools = p.lootPools[pool]
			if curPools then
				-- check if this item (the key) is in the spawns
				if curPools["items"][p.item] ~= nil then
					output = output .. pool .. " " .. tostring(curPools["items"][p.item]["chance"]) .. " "
				end
			end
		end
	end
	return tostring (output) 
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.