Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- local WaitingForInput = true
- local commands = {"Time"}
- --local time = 10 --tonumber(io.read())
- local speaker = peripheral.wrap("back")
- local monitor = peripheral.find("monitor")
- monitor.setCursorPos(1, 1)
- monitor.clear()
- monitor.write(os.getComputerID())
- print(os.getComputerID())
- monitor.setCursorPos(1,2)
- print("Waiting For Command...")
- monitor.write("Waiting For Command...")
- function mvalid(message)
- for _, validMessage in ipairs(commands) do
- if string.find(message, validMessage) then
- return true
- end
- end
- return false
- end
- function convertTime(time)
- local hours = math.floor(time / 3600)
- local minutes = math.floor((time % 3600) / 60)
- local seconds = time % 60
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Hours: "..hours)
- monitor.setCursorPos(1,2)
- monitor.write("Minutes: "..minutes)
- monitor.setCursorPos(1,3)
- monitor.write("Seconds: "..seconds)
- end
- function StartTimer(time)
- repeat
- convertTime(time)
- time = time - 1
- os.sleep(1)
- until time == -1
- monitor.clear()
- if speaker then
- -- Play a sound (replace "sound_name" with the name of the sound file)
- speaker.playSound("UwU")
- else
- print("Speaker not avalable right now")
- end
- WaitingForInput = true
- end
- function executeCommand(command)
- local action, value = string.match(command, "(%a+)%s+(%d+)")
- if action == "Time" then
- local number = tonumber(value)
- if number then
- StartTimer(number)
- return "Running Command: Time"
- else
- return "Invalid format."
- end
- else
- return "Unknown command."
- end
- end
- while WaitingForInput do
- local senderId, message, protocol = rednet.receive()
- monitor.setCursorPos(1,3)
- local Text = "Received message from ID" .. senderId .. ": " .. message
- print(Text)
- monitor.write(Text)
- os.sleep(1.5)
- Text = "Message Type: Command"
- monitor.setCursorPos(1,4)
- print(Text)
- monitor.write(Text)
- os.sleep(2)
- monitor.setCursorPos(1,5)
- Text = executeCommand(message)
- print(Text)
- monitor.write(Text)
- os.sleep(0.5)
- if message == "Invalid format." or "Unknown command." then
- monitor.setCursorPos(1, 1)
- monitor.clear()
- monitor.write(os.getComputerID())
- print(os.getComputerID())
- monitor.setCursorPos(1,2)
- print("Waiting For Command...")
- monitor.write("Waiting For Command...")
- else
- WaitingForInput = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment