Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --variables
- stationName = ""
- otherStationName = ""
- linkId = ""
- monitorSide = "top"
- cartDetectionSide = "bottom"
- callButtonSide = "left"
- railPowerSide = "front"
- function checkConnection()
- while type(http.get(url)) ~= "table" do
- print("connection test")
- end
- end
- print("Station system activated")
- callCounter = 0
- url = "http://tools.uk.ms/cc/trainstations"
- monitor = peripheral.wrap( monitorSide )
- monitor.setTextScale(1)
- while true do
- -- status
- if redstone.getInput(cartDetectionSide) then
- checkConnection()
- status = http.get(url .. "/status.php?status=" .. stationName .. "&linkid=" .. linkId).readAll()
- print("connection error")
- else
- checkConnection()
- status = http.get(url .. "/status.php" .. "?linkid=" .. linkId).readAll()
- if status == stationName then
- checkConnection()
- status = http.get(url .. "/status.php?status=none" .. "&linkid=" .. linkId).readAll()
- end
- end
- checkConnection()
- status = http.get(url .. "/status.php?linkid=" .. linkId).readAll()
- print(status)
- -- call
- -- get call
- checkConnection()
- c = http.get(url .. "/call.php?&linkid=" .. linkId).readAll()
- if c == stationName then
- redstone.setOutput(railPowerSide, true)
- sleep(1)
- redstone.setOutput(railPowerSide, false)
- end
- -- set call
- if redstone.getInput(callButtonSide) then
- checkConnection()
- c = http.get(url .. "/call.php?call=" .. otherStationName .. "&linkid=" .. linkId).readAll()
- end
- -- call counter
- if c ~= "none" then
- callCounter = callCounter + 1
- else
- callCounter = 0
- end
- if callCounter > 2 then
- callCounter = 0
- checkConnection()
- c = http.get(url .. "/call.php?call=none" .. "&linkid=" .. linkId).readAll()
- end
- print(c)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write( "Status: " .. status)
- monitor.setCursorPos(1,2)
- monitor.write( "Call: " .. c)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement