Advertisement
einsteinmaster96

QuarryControler

Jun 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. arg = { ... }
  2. currentControlID = 0
  3. prtc = "hv"
  4. name = os.getComputerLabel()
  5. criticalValue = 20
  6. loading = false
  7.  
  8. if #arg ~= 5 then
  9.   error("not 5 prog arguments its " .. #arg)
  10. end
  11.  
  12. modemside = arg[1]
  13. sensorside = arg[2]
  14. storagepos = arg[3]
  15. currentside = arg[4]
  16. switchside = arg[5]
  17.  
  18. os.loadAPI("ocs/apis/sensor")
  19. mySensor = sensor.wrap(sensorside)
  20. rednet.open(modemside)
  21. rednet.host(prtc,name)
  22. --wait for currentcontrol to initialize
  23. sleep(1)
  24. currentControlID = rednet.lookup(prtc,"currentControl")
  25.  
  26. if not currentControlID or currentControlID <= 0 then
  27.   error("currentControl not found")
  28. end
  29.  
  30. while true do
  31.  
  32.   details = mySensor.getTargetDetails(storagepos)
  33.   stored = details["StoredPercentage"]
  34.  
  35.   if loading == true and stored > criticalValue and not redstone.getInput(currentside) then
  36.     redstone.setOutput(switchside,true)
  37.     loading = false
  38.   elseif loading == false and redstone.getInput(currentside) then
  39.     loading = true
  40.   end
  41.  
  42.  
  43.   if stored < criticalValue then
  44.     rednet.send(currentControlID,"request power",prtc)
  45.     redstone.setOutput(switchside,false)
  46.   end
  47.   id,msg = rednet.receive(prtc,3)
  48.   if id then
  49.    if msg == "get status" then
  50.      loading = true
  51.      rednet.send(id,name .. " " .. stored .. " " .. tostring(loading) .. " " .. tostring(redstone.getInput(currentside)),prtc)
  52.    end
  53.    if msg == "reboot" then
  54.      os.reboot()
  55.    end
  56.   end
  57.   sleep(1)
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement