DaGamer12345

CCLForward

Jul 19th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. --Functions
  2. function forwardloop()
  3.  local event, modemSide, senderChannel,
  4.     replyChannel, message, senderDistance = os.pullEvent("modem_message")
  5.  print("I just received a message from: "..senderChannel)
  6.  print("I should apparently reply on: "..replyChannel)
  7.  print("The modem receiving this is located on the "..modemSide.." side")
  8.  print("The message was: "..message)
  9.  print("The sender is: "..senderDistance.." blocks away from me.")
  10.  peripheral.call(side, "transmit", replyChannel, senderChannel, message)
  11.  forwardloop()
  12. end
  13.  
  14. print("--ComputerCraft Local Forwarder--")
  15. print("What do you want to do?")
  16. print("1. Send a message to Forwarder")
  17. print("2. Be a Forwarder")
  18. query = io.read()
  19. --Send to Forwarder
  20. if query == "1" then
  21.  print("What side is the modem on?")
  22.  side = io.read()
  23.  print("What is the forwarder's channel?")
  24.  forwardchan = io.read()
  25.  print("What is the recipient's channel?")
  26.  receivechan = io.read()
  27.  print("Type the message you want to send:")
  28.  message = io.read()
  29.  forwardchan = tonumber(forwardchan)
  30.  receivechan = tonumber(receivechan)
  31.  print("Sending message on channel "..forwardchan)
  32.  peripheral.call(side, "transmit", forwardchan, receivechan, message)
  33.  print("Sending complete!")
  34. end
  35. --Forward Send/Receive
  36. if query == "2" then
  37.  print("What side is the modem on?")
  38.  side = io.read()
  39.  print("What channel do you want to use for forwarding?")
  40.  forwardchan = io.read()
  41.  forwardchan = tonumber(forwardchan)
  42.  print("Receiving and forwarding messages...")
  43.  peripheral.call(side, "open", forwardchan)
  44.  forwardloop()
  45. end
Advertisement
Add Comment
Please, Sign In to add comment