Fabrimat

LiquidCounter

Oct 4th, 2020 (edited)
1,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. sensorSide = "back"
  2. inputRSSide = "top"
  3. outputRSSide = "left"
  4. flowRSInputSide = "right"
  5. monitorSide = "front"
  6.  
  7. -- DO NOT EDIT
  8. os.loadAPI("ocs/apis/sensor")
  9. se = sensor.wrap("back")
  10.  
  11. counter = 0
  12.  
  13. -- 0 Loading
  14. -- 1 Start Unloading
  15. -- 2 Unloading
  16. -- 3 Finish Unloading
  17. status = 0
  18. rs.setOutput("top", false)
  19. rs.setOutput("left", true)
  20.  
  21. local maxw, maxh = term.getSize()
  22.  
  23. function printCentered(text)
  24.     local maxw, maxh = term.getSize()
  25.     local curx, cury = term.getCursorPos()
  26.     term.setCursorPos((maxw - #text) / 2, cury)
  27.     term.write(text)
  28.     term.setCursorPos(curx, cury + 1)
  29. end
  30.  
  31. while true do
  32.      targets = se.getTargets()
  33.     for name, data in pairs(targets) do
  34.         details = se.getTargetDetails(name)
  35.         if data["Name"] == "tile.tankBlock" and details ~= nil then
  36.             if status == 0 then
  37.                 if details.Tanks[1].Amount >= 1000 then
  38.                     rs.setOutput("top", true)
  39.                     sleep(0.5)
  40.                     details = se.getTargetDetails(name)
  41.                     counter = counter + details.Tanks[1].Amount + 500
  42.                    
  43.                     rs.setOutput("left", false)
  44.                     status = 1
  45.                 end
  46.                
  47.                 term.clear()
  48.                 term.setCursorPos(1, math.floor(maxh / 2))
  49.                 printCentered("Count: "..counter)
  50.                
  51.             elseif status == 1 then
  52.                 if details.Tanks[1].Amount == 0 then
  53.                     status = 2
  54.                 end
  55.             elseif status == 2 then
  56.                 if rs.getInput("right") then
  57.                     status = 3
  58.                 end
  59.             elseif status == 3 then
  60.                 if not rs.getInput("right") then
  61.                     rs.setOutput("top", false)
  62.                     rs.setOutput("left", true)
  63.                     status = 0
  64.                 end
  65.             end
  66.         end
  67.     end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment