Advertisement
HandieAndy

IR Universal Stopping Script

Apr 26th, 2020
1,445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local sides = require("sides")
  4.  
  5. local rs = component.redstone
  6.  
  7. -- The address of the first controller, ahead of the big speed brakes.
  8. local slowdown_ctl = component.proxy("df0bff6f-4228-478e-82ac-abaf3957253d")
  9.  
  10. -- The address of the redstone IO that activates the big speed brakes.
  11. local slowdown_rs = component.proxy("8e3fac6d-89ce-42cc-b165-0e3159a0ee12")
  12.  
  13. -- The address of the second controller that stops the train at the end.
  14. local stop_ctl = component.proxy("6cae5f48-c6a1-4070-901a-ef587bbbaf43")
  15.  
  16. -- The address of the redstone IO that activates the secondary speed retarders.
  17. local stop_rs = component.proxy("e01031c3-cc85-4b8b-b23c-0ba3fb39685c")
  18.  
  19. while true do
  20.   print("Waiting for train...")
  21.   event_name, address, augment_type, stock_uuid = event.pull("ir_train_overhead")
  22.   if augment_type == "LOCO_CONTROL" and address == slowdown_ctl.address then
  23.     print("Enabling speed retarders, reducing throttle, and preparing stopping area.")
  24.     slowdown_ctl.setBrake(0)
  25.     slowdown_ctl.setThrottle(0.5)
  26.     slowdown_ctl.horn()
  27.     -- Note: Depending on where you place your IO block, you may need a different side.
  28.     slowdown_rs.setOutput(sides.north, 15)
  29.     stop_rs.setOutput(sides.up, 15)
  30.     print("Waiting 10 seconds for train to come to a complete stop.")
  31.     os.sleep(10)
  32.     print("Disabling speed retarders.")
  33.     slowdown_rs.setOutput(sides.north, 0)
  34.   elseif augment_type == "LOCO_CONTROL" and address == stop_ctl.address then
  35.     print("Train has reached stopping point. Braking and setting throttle to 0.")
  36.     stop_ctl.setBrake(1)
  37.     stop_ctl.setThrottle(0)
  38.     stop_ctl.horn()
  39.     -- Once again, you may need to specify a different side.
  40.     stop_rs.setOutput(sides.up, 0)
  41.     print("Waiting a few seconds for train to stop.")
  42.     os.sleep(3)
  43.     print("Disabling brakes.")
  44.     stop_ctl.setBrake(0)
  45.     print("Brakes disabled. Train is ready.")
  46.   end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement