Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("right") -- Wrap the modem on the right side.
- modem.open(25813) -- Open channel 25813
- local seed = os.time() * os.getComputerID()
- term.clear()
- term.setCursorPos(1, 1)
- print("Emergency System")
- print("Seed: " .. seed)
- math.randomseed(seed)
- while true do
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- print("Received message: " .. message)
- local args = {}
- for word in string.gmatch(message, "%S+") do -- Split the message into words
- table.insert(args, word)
- end
- local command = table.remove(args, 1) -- Remove the first element as the command
- local count = tonumber(args[1]) or 1 -- Default count is 1 if no amount specified
- local slot = tonumber(args[1]) or 1 -- Default slot is 1 if no slot specified
- if command == "update" then
- modem.closeAll()
- local code = message:sub(8) -- Ensure this starts at the correct index
- local file = fs.open("startup", "w") -- Open (or create) startup.lua for writing
- if file then
- file.write(code) -- Write the received code to the file
- file.close() -- Ensure the file is closed after writing
- print("Updated startup script. Rebooting soon...")
- else
- print("Failed to open file for writing.")
- return -- Exit or handle error appropriately
- end
- -- Generate a random wait time between 1 and 10 seconds
- local waitTime = math.random(1, 10)
- os.sleep(waitTime) -- Wait for the randomly generated time
- -- Reboot the system
- os.reboot()
- else
- print("Unknown command: " .. command)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement