Advertisement
LegoStax

Rednet Cloaking API

Jun 2nd, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. -- Rednet Cloaking API
  2. local function generate(recipient, msg, protocol)
  3.     local nMessageID = math.random(1, 2147483647)
  4.     tMessage = {
  5.         nMessageID = nMessageID,
  6.         nRecipient = recipient,
  7.         message = msg,
  8.         sProtocol = protocol,
  9.     }
  10.     return tMessage
  11. end
  12. -- cloak.send(side, recipient, message, fake_local_address, [protocol])
  13. function send(side, recipient, msg, localhost, protocol)
  14.     local reply = localhost
  15.     local tMessage = generate(recipient, msg, protocol)
  16.     local m = peripheral.wrap(side)
  17.     m.transmit(recipient, reply, tMessage)
  18. end
  19. -- cloak.toggleListen(channel)
  20. function toggleListen(channel, side)
  21.     local m = peripheral.wrap(side)
  22.     if channel ~= nil and type(channel) == "number" and m.isOpen(channel) == false then
  23.         m.open(channel)
  24.     elseif channel ~= nil and type(channel) == "number" and m.isOpen(channel, side) == true then
  25.         m.close(channel)
  26.     end
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement