Advertisement
SolidSnake96AS

Rednet Repeater

Oct 24th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local receiverId;
  2. local arg={...};
  3.  
  4. local function help()
  5.     print("This program turns a PC into a message repeater. The PC resends the messages it receives to another PC (which may itself be a repeater).");
  6.     print("To use this program put a wireless modem on the left side of the computer.");
  7. end
  8.  
  9. if (#arg==0)
  10. then
  11.     printError("You have to specify an argument.");
  12.     print("\nArguments:");
  13.     print("help: Display an help guide.");
  14.     print("id: Get the id of this computer to use with rednet.");
  15.     print("start id: Start the program. \"id\" is the id of the receiver.");
  16.     return;
  17. else
  18.     if (arg[1]=="id")
  19.     then
  20.         print("Receiver id: "..os.getComputerID());
  21.         return;
  22.     elseif (arg[1]=="help")
  23.     then
  24.         help();
  25.         return;
  26.     elseif (arg[1]=="start")
  27.     then
  28.         if (arg[2]~=nil)
  29.         then
  30.            
  31.             receiverId=tonumber(arg[2]);
  32.            
  33.             if (receiverId==nil)
  34.             then
  35.                 printError("\"id\" must be a number!");
  36.                 return;
  37.             end
  38.         else
  39.             printError("You have to specify the id of the receiver computer!");
  40.             return;
  41.         end
  42.     else
  43.         printError("Wrong argument!");
  44.         return;
  45.     end
  46. end
  47.  
  48. rednet.open("left");
  49. term.clear();
  50. term.setCursorPos(1, 1);
  51.  
  52.  
  53. while(true)
  54. do
  55.     senderId, msg, protocol=rednet.receive();
  56.    
  57.     term.clear();
  58.     term.setCursorPos(1, 1);
  59.    
  60.     if (protocol==nil)
  61.     then
  62.         protocol="No protocol";
  63.     end
  64.  
  65.     print("Message received:");
  66.     print("\nSender ID: "..senderId);
  67.     print("Message: "..msg);
  68.     print("Protocol: "..protocol);
  69.    
  70.    
  71.     rednet.send(receiverId, msg);
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement