Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
inventoryList = {}
function asInventoryList(gmcpItems)
local tableResult = {}
for _, item in ipairs(gmcpItems) do
local listItem = tableResult[item.name]
if not listItem then
tableResult[item.name] = 0
end
tableResult[item.name] = tableResult[item.name] + 1
end
return tableResult
end
function updateInventory()
inventoryList = asInventoryList(gmcp.Char.Items.List.items)
saveInventory()
end
function saveInventory()
if string.char(getMudletHomeDir():byte()) == "/"
then _sep = "/"
else _sep = "\"
end -- if
shop_inventory = getMudletHomeDir() .. _sep .. "shop_inventory.lua"
table.save(shop_inventory, inventoryList)
end -- func
function loadInventory()
if string.char(getMudletHomeDir():byte()) == "/"
then _sep = "/"
else _sep = "\"
end -- if
shop_inventory = getMudletHomeDir() .. _sep .. "shop_inventory.lua"
if (io.exists(shop_inventory)) then
table.load(shopinventory, inventoryList)
end -- if
end -- func
function compareInventory()
tempinventoryList = asInventoryList(gmcp.Char.Items.List.items)
loadInventory()
missingItems = {}
for name, count in pairs(inventoryList) do
if not tempinventoryList[name] or tempinventoryList[name] < count then
local currentCount = tempinventoryList[name] or 0
table.insert(missingItems, { name = name, diff = count - currentCount })
end
end
for , v in ipairs(missingItems) do
cecho("\n<green>Item: " ..v.name.. " - <blue>Sold: " ..v.diff)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.