Aixler

monitorSpawner

Nov 8th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. monitorSide = "top"
  2. modemSide = "right"
  3. slaveID = 111
  4.  
  5. m = peripheral.wrap(monitorSide)
  6. rednet.open(modemSide)
  7. m.setBackgroundColor(colors.black)
  8. m.clear()
  9.  
  10. tArgs = { ... }
  11.  
  12. if #tArgs == 2 then
  13.     redstone = tArgs[1]
  14.     spawner = tArgs[2]
  15. else
  16.     redstone = "Off"
  17.     spawner = "Empty"
  18. end
  19.  
  20. function screen(pos_x, pos_y, color, msg)
  21.     m.setCursorPos(pos_x, pos_y)
  22.     m.setBackgroundColor(color)
  23.     m.write(msg)
  24. end
  25.  
  26. function save()             --saving position
  27.     file = fs.open("startup", "w")      --open startup in writemode
  28.     file.write('shell.run("monitor", \''..redstone..'\', \''..spawner..'\')')
  29.     file.close()
  30. end
  31.  
  32. screen(2,2,colors.black,"Spawner Control")
  33.  
  34. function full()
  35.     spawner = "Full"
  36.     save()
  37.     screen(2,6,colors.green,"Full")
  38.     screen(13,6,colors.black,"Empty")
  39. end
  40.  
  41. function empty()
  42.     spawner = "Empty"
  43.     save()
  44.     screen(2,6,colors.black,"Full")
  45.     screen(13,6,colors.red,"Empty")
  46. end
  47.  
  48. function on()
  49.     redstone = "On"
  50.     save()
  51.     screen(2,4,colors.green,"On")
  52.     screen(13,4,colors.black,"Off")
  53. end
  54.  
  55. function off()
  56.     redstone = "Off"
  57.     save()
  58.     screen(2,4,colors.black,"On")
  59.     screen(13,4,colors.red,"Off")
  60. end
  61.    
  62. function noResponse()
  63.     screen(2,2,colors.red,"spawner is not responding")
  64.     error()
  65. end
  66.  
  67. function wrong()
  68.     screen(2,2,colors.red,"error, manual intervention required")
  69. end
  70.  
  71. if #tArgs == 2 then
  72.     if redstone == "On" then
  73.         on()
  74.     else
  75.         off()
  76.     end
  77.     if spawner == "Full" then
  78.         full()
  79.     else
  80.         empty()
  81.     end
  82. else
  83.     off()
  84.     empty()
  85. end
  86.  
  87. function main()
  88.     xPos, yPos = 0, 0
  89.     _, side, xPos, yPos = os.pullEvent("monitor_touch")
  90.     print("x= "..xPos.."y= "..yPos)
  91.        
  92.     if 2 <= xPos and xPos <= 3 and yPos == 4 then           --on = 2,4
  93.         rednet.send(slaveID, "On")
  94.         print("sending on")
  95.         id, msg, distance = rednet.receive(5)
  96.         if id == nil then
  97.             noResponse()
  98.         elseif id == slaveID and msg == "On done" then
  99.             on()
  100.         end    
  101.    
  102.     elseif 13 <= xPos and xPos <= 15 and yPos == 4 then     --off = 13,4
  103.         rednet.send(slaveID, "Off")
  104.         print("sending off")
  105.         id, msg, distance = rednet.receive(5)
  106.         if id == nil then
  107.             noResponse()
  108.         elseif id == slaveID and msg == "Off done" then
  109.             off()
  110.         end
  111.            
  112.     elseif 2 <= xPos and xPos <= 5 and yPos == 6 then       --full = 2,6
  113.         rednet.send(slaveID, "Full")
  114.         print("sending full")
  115.         id, msg, distance = rednet.receive(5)
  116.         if id == nil then
  117.             noResponse()
  118.         elseif id == slaveID and msg == "Full done" then
  119.             full()
  120.         end
  121.    
  122.     elseif 13 <= xPos and xPos <= 17 and yPos == 6 then     --empty = 13,6
  123.         rednet.send(slaveID, "Empty")
  124.         print("sending empty")
  125.         id, msg, distance = rednet.receive(5)
  126.         if id == nil then
  127.             noResponse()
  128.         elseif id == slaveID and msg == "Empty done" then
  129.             empty()
  130.         end
  131.     end
  132. end
  133.  
  134. while true do
  135.     main()
  136.     sleep(1)
  137. end
Advertisement
Add Comment
Please, Sign In to add comment