Advertisement
BillBodkin

BBCCitemServer

Jun 3rd, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. rednet.open("bottom")
  2. --shell.setDir("/BillBodkinCompCraft")
  3.  
  4. storageBot = 0
  5.  
  6. if fs.exists("/BillBodkinCompCraft/chestData") then
  7. else
  8.     shell.run("pastebin get vUypHecK /BillBodkinCompCraft/chestData")
  9. end
  10.  
  11. function load(name)
  12.     local file = fs.open(name,"r")
  13.     local data = file.readAll()
  14.     file.close()
  15.     return textutils.unserialize(data)
  16. end
  17.  
  18. function save(table,name)
  19.     local file = fs.open(name,"w")
  20.     file.write(textutils.serialize(table))
  21.     file.close()
  22. end
  23.  
  24. function getItemsChest(id)
  25.     i = 1
  26.     while i < #chests + 2 do
  27.         --print("i: "..i)
  28.         --print(chests[i])
  29.         if tonumber(i) > #chests then
  30.             if tonumber(messageId) == storageBot then
  31.                 --print("b")
  32.                 table.insert(chests, tonumber(i), itemChestToFind)
  33.                 --print("bc")
  34.                 return tostring(i)
  35.             else
  36.                 return "not avaliable to retrive"
  37.             end
  38.         else
  39.             --print("a")
  40.             if tostring(chests[i]) == itemChestToFind then
  41.                 --print("ac")
  42.                 return tostring(i)
  43.             end
  44.         end
  45.         i = i + 1
  46.     end
  47. end
  48.  
  49. chests = load("/BillBodkinCompCraft/chestData")
  50. itemChestToFind = "0"
  51. chestForItem = 0
  52. i = 1
  53. messageId = 0
  54.  
  55. on = true
  56.  
  57. print("Ready To Retrieve Data")
  58.  
  59. while on == true do
  60.     messageId, message, protocol = rednet.receive()
  61.     print("ID: "..messageId.."  |  Item To Locate: "..message)
  62.     itemChestToFind = tostring(message)
  63.     if itemChestToFind == "wallBuilder" then
  64.         chestForItem = tostring(#chests)
  65.     else
  66.         chestForItem = getItemsChest(itemChestToFind)
  67.     end
  68.     print("Item's Chest: "..chestForItem)
  69.     rednet.send(messageId, chestForItem)
  70.     save(chests,"/BillBodkinCompCraft/chestData")
  71. end
  72.  
  73. save(chests,"/BillBodkinCompCraft/chestData")
  74.  
  75. rednet.close("bottom")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement