Advertisement
BillBodkin

CC Train Stations

Dec 27th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --variables
  2. stationName = ""
  3. otherStationName = ""
  4. linkId = ""
  5.  
  6. monitorSide = "top"
  7. cartDetectionSide = "bottom"
  8. callButtonSide = "left"
  9. railPowerSide = "front"
  10.  
  11. function checkConnection()
  12.     while type(http.get(url)) ~= "table" do
  13.         print("connection test")
  14.     end
  15. end
  16.  
  17. print("Station system activated")
  18. callCounter = 0
  19. url = "http://tools.uk.ms/cc/trainstations"
  20. monitor = peripheral.wrap( monitorSide  )
  21. monitor.setTextScale(1)
  22. while true do
  23.     -- status
  24.     if redstone.getInput(cartDetectionSide) then
  25.         checkConnection()
  26.         status = http.get(url .. "/status.php?status=" .. stationName .. "&linkid=" .. linkId).readAll()
  27.         print("connection error")
  28.     else
  29.         checkConnection()
  30.         status = http.get(url .. "/status.php" .. "?linkid=" .. linkId).readAll()
  31.         if status == stationName then
  32.             checkConnection()
  33.             status = http.get(url .. "/status.php?status=none" .. "&linkid=" .. linkId).readAll()
  34.         end
  35.     end
  36.     checkConnection()
  37.     status = http.get(url .. "/status.php?linkid=" .. linkId).readAll()
  38.     print(status)
  39.     -- call
  40.     -- get call
  41.     checkConnection()
  42.     c = http.get(url .. "/call.php?&linkid=" .. linkId).readAll()
  43.     if c == stationName then   
  44.         redstone.setOutput(railPowerSide, true)
  45.         sleep(1)
  46.         redstone.setOutput(railPowerSide, false)
  47.     end
  48.     -- set call
  49.     if redstone.getInput(callButtonSide) then
  50.         checkConnection()
  51.         c = http.get(url .. "/call.php?call=" .. otherStationName .. "&linkid=" .. linkId).readAll()
  52.     end
  53.     -- call counter
  54.     if c ~= "none" then
  55.         callCounter = callCounter + 1
  56.     else
  57.         callCounter = 0
  58.     end
  59.     if callCounter > 2 then
  60.         callCounter = 0
  61.         checkConnection()
  62.         c = http.get(url .. "/call.php?call=none" .. "&linkid=" .. linkId).readAll()
  63.     end
  64.     print(c)
  65.     monitor.clear()
  66.     monitor.setCursorPos(1,1)
  67.     monitor.write( "Status: " .. status)
  68.     monitor.setCursorPos(1,2)
  69.     monitor.write( "Call: " .. c)
  70.     sleep(1)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement