Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- m = peripheral.wrap("monitor_1")
- m.clear()
- rednet.open("bottom")
- inputSide = "right"
- outputSide = "back"
- trainsInYard = 0
- stationTime = 0
- train = false
- stationSelected = false
- function checkTrains()
- trainsInYard = redstone.getBundledInput(inputSide)
- end
- function sendTrain()
- train = true
- if colors.test(trainsInYard, colors.white) then
- tbl = {"SEND_TRAIN", colors.white}
- print("1st train ordered")
- elseif colors.test(trainsInYard, colors.orange) then
- tbl = {"SEND_TRAIN", colors.orange}
- print("2nd train ordered")
- elseif colors.test(trainsInYard, colors.magenta) then
- tbl = {"SEND_TRAIN", colors.magenta}
- print("3rd train ordered")
- elseif colors.test(trainsInYard, colors.lightBlue) then
- tbl = {"SEND_TRAIN", colors.lightBlue}
- print("4th train ordered")
- else
- print("No trains available")
- train = false
- end
- if train == true then
- rednet.broadcast(textutils.serialize(tbl))
- end
- end
- function fillTable()
- button.setTable("Spawn", loc1, 10,20,3,5)
- button.setTable("AlpacaCO", loc2, 22,32,3,5)
- --button.setTable("Test3", loc3, 10,20,8,10)
- --button.setTable("Test4", loc4, 22,32,8,10)
- button.screen()
- end
- function stationClick()
- redstone.setBundledOutput("back", station)
- stationTime = os.time()
- stationSelected = true
- end
- function loc1()
- button.toggleButton("Spawn")
- print("Spawn")
- station=colors.white
- stationClick()
- end
- function loc2()
- button.toggleButton("AlpacaCO")
- print("AlpacaCO")
- station = colors.orange
- stationClick()
- end
- function loc3()
- button.toggleButton("AlpacaCO")
- print("AlpacaCO")
- station = colors.magenta
- stationClick()
- end
- function clearOutput()
- redstone.setBundledOutput(inputSide, 0)
- end
- function launchTrain()
- redstone.setBundledOutput(inputSide, colors.blue)
- os.sleep(2)
- redstone.setBundledOutput(inputSide, 0)
- button.clearButtonToggle()
- end
- function pickupPassenger()
- redstone.setBundledOutput(inputSide, colors.red)
- end
- function isTrainAtStation()
- return colors.test (redstone.getBundledInput(inputSide), colors.black) == true
- end
- function trainContainPassenger()
- return colors.test (redstone.getBundledInput(inputSide), colors.green) == true
- end
- fillTable()
- launchTrain()
- sleep(2)
- clearOutput()
- button.heading("Cake Town Main Station")
- currentState = "NO_ACTION"
- trainSentTime = os.time() - 2
- os.startTimer(2)
- while true do
- event,side,x,y = os.pullEvent()
- if event == "monitor_touch" then
- button.checkxy(x,y)
- end
- if stationSelected == true then
- print("Station Selected")
- if os.time() - 2.0 > stationTime then
- stationSelected = false
- if isTrainAtStation() == true then
- print("Sending Train Back to Refuel")
- launchTrain()
- button.clearButtonToggle()
- end
- elseif isTrainAtStation() == true then
- print("Train at Main Station")
- pickupPassenger()
- if trainContainPassenger() == true then
- print("Passenger is in train.")
- launchTrain()
- print("Train Launched.")
- end
- end
- if isTrainAtStation() == false and os.time() - 2.0 > trainSentTime then
- print("No train at Main Station, calling one")
- checkTrains()
- sendTrain()
- trainSentTime = os.time()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement