Module:Sandbox/Soreness: Difference between revisions
From Growtopia Wiki
More actions
mNo edit summary |
mNo edit summary |
||
| Line 25: | Line 25: | ||
end | end | ||
local function | local function setDoesntContains(set, key) | ||
return | return set[key] == nil | ||
end | end | ||
local function addtoList(strname) | local function addtoList(strname) | ||
local rarity = getItemData(md5.md5(strname))[3] | local rarity = getItemData(md5.md5(strname))[3] | ||
--local DEBUG = {} | --local DEBUG = {} | ||
if | if setDoesntContains(f, rarity) then | ||
addToSet(f, rarity) | addToSet(f, rarity) | ||
table.insert(sc,{"<br>'''Rarity "..rarity..": ''' | table.insert(sc,{"<br>'''Rarity "..rarity..": '''"}) | ||
table.insert(sc[#sc],"[["..strname.."]]") | table.insert(sc[#sc],"[["..strname.."]]") | ||
else | else | ||
| Line 51: | Line 50: | ||
local DEBUG = {} | local DEBUG = {} | ||
local a = getItemName() | local a = getItemName() | ||
table.insert(DEBUG, "1st contains: "..a[1].."\n") | --table.insert(DEBUG, "1st contains: "..a[1].."\n") | ||
for x=2, (a[1]+1),1 | for x=2, (a[1]+1),1 | ||
do | do | ||
addtoList(a[x]) | addtoList(a[x]) | ||
table.insert(DEBUG, "add: "..a[x].." with hash: "..md5.md5(a[x]).." and rarity: "..getItemData(md5.md5(a[x]))[3]) | --table.insert(DEBUG, "add: "..a[x].." with hash: "..md5.md5(a[x]).." and rarity: "..getItemData(md5.md5(a[x]))[3]) | ||
x=x+1 | x=x+1 | ||
end | end | ||
Revision as of 13:31, 9 May 2022
Documentation for this module may be created at Module:Sandbox/Soreness/doc
local raritylist = {}
local md5 = require('Module:Md5')
local sc= {}
local f = {}
local printset = {}
local function getItemData(hash)
local a = mw.loadData('Module:Item/Data')
return a[hash] or {-1, -1}
end
local function getItemName()
local a = mw.loadData('Module:Sandbox/Soreness/Data')
return a
end
local function addToSet(set, key)
set[key] = true
end
local function removeFromSet(set, key)
set[key] = nil
end
local function setDoesntContains(set, key)
return set[key] == nil
end
local function addtoList(strname)
local rarity = getItemData(md5.md5(strname))[3]
--local DEBUG = {}
if setDoesntContains(f, rarity) then
addToSet(f, rarity)
table.insert(sc,{"<br>'''Rarity "..rarity..": '''"})
table.insert(sc[#sc],"[["..strname.."]]")
else
for i=1,#sc,1
do
if sc[i][1] == "'''Rarity "..rarity..": '''" then
table.insert(sc[i],", [["..strname.."]]")
end
end
end
end
function raritylist.list()
local x=1
local DEBUG = {}
local a = getItemName()
--table.insert(DEBUG, "1st contains: "..a[1].."\n")
for x=2, (a[1]+1),1
do
addtoList(a[x])
--table.insert(DEBUG, "add: "..a[x].." with hash: "..md5.md5(a[x]).." and rarity: "..getItemData(md5.md5(a[x]))[3])
x=x+1
end
----------------------------------All items listed in array-------------------------------------
for i=1, #sc, 1
do
for j=1,#sc[i], 1
do
table.insert(printset, sc[i][j])
end
end
return table.concat(printset)
end
return raritylist