Advertisement
An93l0fD3ath

train shed

Jul 19th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. --Acquire the redstone component
  2. local component = require("component")
  3. local redstone = component.redstone
  4. local routing = component.routing_track
  5. -- Acquire helper libraries
  6. local sides = require("sides")
  7. local colors = require("colors")
  8. local os = require("os")
  9. local term = require("term")
  10. local event = require("event")
  11.  
  12. --Acquire GERTi library and open socket to farm computer
  13. local GERTi = require("GERTiClient")
  14. local socket = GERTi.openSocket(0.2, true, 1)
  15.  
  16. --Template local function--
  17. local train1 = redstone.getBundledInput(sides.north, colors.gray)
  18. local train2 = redstone.getBundledInput(sides.north, colors.lime)
  19. local train3 = redstone.getBundledInput(sides.north, colors.pink)
  20.  
  21. local function sendTrain1()
  22.     --needs rewrite--
  23.     --monitor.write("Theres A Train Leaving Bay 1")
  24.        
  25.     print("Theres A Train Leaving Bay 1")
  26.     redstone.setBundledOutput(sides.north, colors.orange, 253)
  27.     os.sleep(1)
  28.     redstone.setBundledOutput(sides.north, colors.orange, 0)
  29. end
  30.  
  31. local function sendTrain2()
  32.     print("Theres A Train Leaving Bay 2")
  33.     redstone.setBundledOutput(sides.north, colors.white, 253)
  34.     os.sleep(1)
  35.     redstone.setBundledOutput(sides.north, colors.white, 0)
  36. end
  37.  
  38. local function sendTrain3()
  39.     print("Theres A Train Leaving Bay 3")
  40.     redstone.setBundledOutput(sides.north, colors.yellow, 253)
  41.     os.sleep(1)
  42.     redstone.setBundledOutput(sides.north, colors.yellow, 0)
  43. end
  44.  
  45. local function checkTrainHold()
  46.  train1 = redstone.getBundledInput(sides.north, colors.gray)
  47.  train2 = redstone.getBundledInput(sides.north, colors.lime)
  48.  train3 = redstone.getBundledInput(sides.north, colors.pink)
  49. if  train1 == 235 then
  50.         sendTrain1()
  51.         --print(train1)
  52.     elseif
  53.     train2 == 238 then
  54.         sendTrain2()
  55.         --print(train2)
  56.     elseif
  57.     train3 == 228 then
  58.         sendTrain3()
  59.         --print(train3)
  60.     else
  61.         print("Theres No Trains Available!!")    
  62. end
  63. end
  64.  
  65. --local function getPass(checkPass)
  66. --  local pass = ""
  67.  
  68. --  term.write("Please Enter The Password: ")
  69. --  pass = read()
  70. --  if pass ~= checkPass then
  71. --      print("Wrong Password!!")
  72. --      return false  
  73. --   else
  74. --      print("Correct Password!!")
  75. --      return true
  76. --   end
  77. --end
  78.  
  79.  
  80. --while not getPass("test") do
  81. --  print("Incorrect")
  82. --end
  83.  
  84. local function getTicketdest()
  85. routing.getDestination()
  86. end
  87.  
  88. local function setTicket(dest)
  89. routing.setDestination(dest)
  90. end
  91.  
  92. local function listenMessage()
  93.     local incData = socket:read()
  94.     if incData[1] == "Requesting Train" then
  95.     checkTrainHold()
  96.     setTicket("Farm")
  97.     print("Setting Track Destination",dest)
  98.   end
  99. end
  100. event.listen("GERTData", listenMessage)
  101.  
  102. local function finishConnect()
  103.     socket:read()
  104.     return false
  105. end
  106. event.listen("GERTConnectionID", finishConnect)
  107.  
  108.  
  109.  
  110. print("Starting Program!")
  111. print(train1,"train1")
  112. print(train2,"train2")
  113. print(train3,"train3") 
  114.        
  115.  while true do
  116.  train1 = redstone.getBundledInput(sides.north, colors.gray)
  117.  train2 = redstone.getBundledInput(sides.north, colors.lime)
  118.  train3 = redstone.getBundledInput(sides.north, colors.pink)
  119.  incData = socket:read()
  120.  if incData[1] == "Requesting Train" then
  121.   checkTrainHold()
  122.     setTicket("Farm")
  123.         print("Setting Track Destination",dest)
  124.         print(train1,"train1")
  125.         print(train2,"train2")
  126.         print(train3,"train3") 
  127.     os.sleep(20)
  128.     term.setCursor(1,1)
  129.     term.clearLine()
  130.     term.clear()
  131.  else
  132.     print("Nothing To Do")
  133.         print(train1,"train1")
  134.         print(train2,"train2")
  135.         print(train3,"train3")
  136.     os.sleep(20)
  137.     end
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement