Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chestIDsouth = {0,1,2,3,4,5,6,7}
- chests = {}
- local tItemTbl = {}
- direction = 4
- pushDir = "south"
- function loadChests()
- for i = 1, #chestIDsouth do
- chests[i] = peripheral.wrap("diamond_chest_"..tostring(chestIDsouth[i]))
- end
- end
- function buildChestsItemList()
- local tblItemNames = {}
- for i = 1, #chestIDsouth do
- if chests[i] ~= nil then
- for j = 1, 108 do
- item = chests[i].getStackInSlot(j-1)
- if item ~= nil then
- name = item["name"]
- table.insert(tblItemNames, name)
- end
- end
- end
- end
- return tblItemNames
- end
- function buildChestsItemListQty()
- local tblItems = {}
- for i = 1, #chestIDsouth do
- if chests[i] ~= nil then
- size = chests[i].getSizeInventory()
- for j = 1, size do
- item = chests[i].getStackInSlot(j-1)
- if item ~= nil then
- table.insert(tblItems, item)
- end
- end
- end
- end
- return tblItems
- end
- function checkForNewItems(tblItemNames)
- for i = 1, #tblItemNames do
- if doesContain(tblItemNames[i]) == false then
- printf("Missing item cost for: " .. tblItemNames[i])
- printf("What should it cost? (just hit enter to skip)")
- cost = read()
- if cost ~= nil then
- row = {tblItemNames[i], tonumber(cost)}
- table.insert(tItemTbl, row)
- end
- end
- end
- end
- function doesContain(name)
- for i = 1, #tItemTbl do
- if tItemTbl[i][1] == name then
- return true
- end
- end
- return false
- end
- function doesContain2(tbl, name)
- for i = 1, #tbl do
- if tbl[i][1] == name then
- return true
- end
- end
- return false
- end
- function loadTbl()
- if fs.exists("tItemTbl") then
- local file = fs.open("tItemTbl","r")
- fileData = file.readAll()
- tItemTbl = textutils.unserialize(fileData)
- file.close()
- end
- end
- function saveTbl()
- local file = fs.open("tItemTbl", "w")
- file.write(textutils.serialize(tItemTbl))
- file.close()
- end
- function getCost(name)
- for i = 1, #tItemTbl do
- if tItemTbl[i][1] == name then
- return tItemTbl[i][2]
- end
- end
- return 0
- end
- function getChestItemsInTable(tblItemNames)
- local r = {}
- for i = 1, #tblItemNames do
- if doesContain(tblItemNames[i]) then
- if doesContain2(r, tblItemNames[i]) == false then
- row = {tblItemNames[i], getCost(tblItemNames[i])}
- if row[2] > 0 then
- table.insert(r, row)
- end
- end
- end
- end
- return r
- end
- function giveItem(name)
- for i = 1, #chestIDsouth do
- if chests[i] ~= nil then
- for j = 1, 108 do
- item = chests[i].getStackInSlot(j-1)
- if item ~= nil then
- if item["name"] == name then
- chests[i].push(pushDir, j-1, 1)
- return true
- end
- end
- end
- end
- end
- return false
- end
- function init()
- loadChests()
- loadTbl()
- if tItemTbl == nil then
- tItemTbl = {}
- end
- end
- function debugChests()
- iList = buildChestsItemList()
- t = getChestItemsInTable(iList)
- end
- function mainInput()
- iList = buildChestsItemList()
- checkForNewItems(iList)
- saveTbl()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement