Advertisement
Zantag

tbl Builder

Sep 12th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. chestIDsouth = {0,1,2,3,4,5,6,7}
  2. chests = {}
  3. local tItemTbl = {}
  4. direction = 4
  5.  
  6. function loadChests()
  7. for i = 1, #chestIDsouth do
  8. chests[i] = peripheral.wrap("diamond_chest_"..tostring(chestIDsouth[i-1])
  9. end
  10. end
  11.  
  12. function buildChestsItemList()
  13. local tblItemNames = {}
  14. for i = 1, #chestIDsouth do
  15. if chests[i-1] ~= nil then
  16. for j = 1, 108 do
  17. item = chests[i].getStackInSlot(j-1)
  18. if item ~= nil then
  19. name = item["name"]
  20. table.insert(tItemNames, row)
  21. end
  22. end
  23. end
  24. end
  25. return tblItemNames
  26. end
  27. function checkForNewItems(tblItemNames)
  28. for i = 1, #tblItemNames do
  29. if doesContain(tblItemNames[i]) == false then
  30. printf("Missing item cost for: " .. tblItemNames[i])
  31. printf("What should it cost? (just hit enter to skip)")
  32. cost = read()
  33. if cost ~= nil then
  34. row = (tblItemNames[i], tonumber(cost))
  35. table.insert(tItemTbl, row)
  36. end
  37. end
  38. end
  39. end
  40. function doesContain(name)
  41. for i = 1, #tItemTbl do
  42. if tItemTbl[i][1] == name then
  43. return true
  44. end
  45. end
  46. return false
  47. end
  48. function loadTbl()
  49. if fs.exists("tItemTbl") then
  50. local file = fs.open("tItemTbl","r")
  51. fileData = file.readAll()
  52. tItemTbl = textutils.unserialize(fileData)
  53. file.close()
  54. end
  55. end
  56. function saveTbl()
  57. local file = fs.open("tItemTbl", "w")
  58. file.write(textutils.serialize(tItemTbl))
  59. file.close()
  60. end
  61.  
  62. loadTbl()
  63. if tItemTbl == nil then
  64. tItemTbl = {}
  65. end
  66. iList = buildChestsItemList()
  67. checkForNewItems(iList)
  68. saveTbl()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement