Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Credits PeachMaster 2019
- --Haha just kidding it only example
- --It's pretty basic, you can set static speed limits
- --CTRL + T to exit
- --Change these to your likings
- local monitor = peripheral.find("monitor");
- term.redirect(monitor);
- local theSpeedLimit = 200
- local theNextSpeedLimit = 0
- local radio = peripheral.find("wirelessMTCRadio") -- Finds a radio peripheral
- os.loadAPI("json")
- radio.activate() -- Activates the Radio
- print("The server UUID is: "..radio.getSelfUUID())
- while true do
- print("Waiting for response..")
- local event, side, id, uuid, message, system = os.pullEvent("radio_message") -- Waits for a radio message
- --Prints important stuff
- print("Side it came from: "..side)
- print("Train UUID: "..id)
- print("Raw Message: "..message)
- if string.find(message, "speed") then
- speed = string.gsub(message, "speed ", "");
- theSpeedLimit = speed
- end
- local theMessage = json.decode(message) -- Decodes the message from JSON to Lua Table
- print(theMessage)
- print(string.len(id))
- if string.len(id) < 8 then
- if theMessage.funct == "attemptconnection" then
- --Alright, yay! The train is attempting to connect! Send a startlevel2 to turn on W-MTC
- print("1")
- radio.sendMessage(id, json.encode({funct = "startlevel2", speedLimit = theSpeedLimit, nextSpeedLimit = theNextSpeedLimit, speedChange = false, endSoon = false, stationStopSoon = false, mtcStatus = 1, atoStatus = 1, destination = ""}))
- print("Sending a start level 2 request to "..uuid)
- end
- if theMessage.funct == "update" then
- print("2")
- if theMessage.signalBlock == "SCML-1" then
- radio.sendMessage(id, json.encode({funct = "response", speedLimit = 280, nextSpeedLimit = 100, speedChange = true, endSoon = false, stationStopSoon = false, atoStatus = 1}))
- elseif theMessage.signalBlock == "SCML-2" then
- end
- end
- --The train sends updates to the server every second or so
- -- radio.sendMessage(id, json.encode({funct = "response", speedlimit = theSpeedLimit, nextSpeedLimit = theNextSpeedLimit, speedChange = false, endSoon = false, stationStopSoon = false, mtcStatus = 1, atoStatus = 1, destination = ""}))
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement