Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set event pulling to raw mode
- os.pullEvent = os.pullEventRaw
- -- Table to store modem locations
- 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)
- print("Rednet opened on side:", modemSide)
- return true
- else
- print("No modem found.")
- return false
- end
- end
- -- Function to log the location of the current computer
- local function logComputerLocation()
- local computerID = os.computerID()
- local computerLabel = os.getComputerLabel() or "Unnamed"
- modemLocations[computerID] = {label = computerLabel, location = os.getComputerLabel()}
- print("Logged computer ID:", computerID, "with label:", computerLabel)
- end
- -- Function to send the computer's ID to the main computer
- local function sendComputerID()
- local mainComputerID = 77 -- Replace with the ID of the main computer
- rednet.send(mainComputerID, os.computerID())
- print("Sent computer ID:", os.computerID(), "to main computer ID:")
- 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 to the main computer
- sendComputerID()
- -- 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
- print("Received command:", message)
- -- Execute the received command
- shell.run(message)
- end
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement