Advertisement
Corbinhol

Inventory Monitor

Sep 19th, 2022 (edited)
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. --Inventory Monitor
  2. local uptime = 1;
  3. local gui = require("SmallGUI");
  4. local storage = peripheral.wrap("bottom");
  5. local protocol = "AUTOBUYER"
  6. local uptime = 0;
  7. rednet.open("top");
  8. rednet.host("StorageSystem", protocol);
  9. local currentLog = {};
  10.  
  11. function getData()
  12.     while true do
  13.         address, message = rednet.receive(protocol);
  14.         if message == "sendInventoryData" then
  15.             log("Recieved Message From " .. address);
  16.             rednet.send(address, textutils.serialize(storage.list()), protocol);
  17.         end
  18.         sleep(0);
  19.     end
  20. end
  21.  
  22. function log(input)
  23.     local tempOut = "[" .. gui.parseTime(uptime) .. "] " .. input;
  24.     table.insert(currentLog, tempOut);
  25. end
  26.  
  27. function setUptime()
  28.     while true do uptime = uptime + 1; sleep(1) end
  29. end
  30.  
  31.  
  32. function updateScreen()
  33.     while true do    
  34.         gui.printf(string.rep("=", term.getSize()),1,1);
  35.             gui.printf("Inventory Monitor: [Ver 2.0]", 1, 2)
  36.             gui.printf("| Uptime: " .. gui.parseTime(uptime));
  37.             gui.printf(string.rep("=", term.getSize()),1,3);
  38.             for i = 1, 15, 1 do
  39.                 tableLength = table.getn(currentLog);
  40.                 if currentLog[tableLength - i] ~= nil then
  41.                     gui.printf(currentLog[tableLength - i] .. string.rep(" ", term.getSize()), 1, 3+i);
  42.                 end
  43.         end
  44.         sleep(0);
  45.     end
  46. end
  47. gui.reset();
  48. parallel.waitForAny(getData, setUptime, updateScreen);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement