SHARE
TWEET

gps_tools

JustGekto Oct 21st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local CHANNEL_REPEAT = 65533
  2. local tArgs = { ... }
  3. local side
  4. kek = {}
  5. local function findModem()
  6.   local PeriList = peripheral.getNames()
  7.   for i=1,#PeriList do
  8.     if peripheral.getType(PeriList[i]) == "modem" then
  9.       return PeriList[i]
  10.     end
  11.   end
  12. end
  13. local function open(nChanel)
  14.     peripheral.call(side, "open", nChanel )
  15. end
  16. local function send( nRecipient,nSender,message)
  17.     nMessageID = math.random( 1, 2147483647 )
  18.     local tMessage = {
  19.         nMessageID = nMessageID,
  20.         nRecipient = nRecipient,
  21.         message = message,
  22.         sProtocol = sProtocol,
  23.     }
  24.     peripheral.call(side,"transmit",nRecipient,nSender,tMessage)
  25. end
  26. side = findModem()
  27. if side == nil then
  28.     error("You need modem to use this program")
  29. end
  30. if #tArgs>0 then
  31.     if tArgs[1] == "r" then
  32.         shell.run("clear")
  33.         open(gps.CHANNEL_GPS)
  34.         open(1)
  35.         while true do
  36.             e = {os.pullEvent("modem_message")}
  37.             for i=1,#e do
  38.                
  39.                 if i == 5 then
  40.                     if type(e[5]) == "table" then
  41.                         print(table.unpack(e[5]))
  42.                     else
  43.                         print(e[i])
  44.                     end
  45.                 else
  46.                     print(e[i])
  47.                 end
  48.             end
  49.         end
  50.     elseif tArgs[1] == "s" then
  51.         shell.run("clear")
  52.         term.setCursorPos(1,1)
  53.         term.write("Enter sender id:")
  54.         local s_id = tonumber(read())
  55.         term.setCursorPos(1,2)
  56.         term.write("Enter recipient id:")
  57.         local r_id = tonumber(read())
  58.         term.write("Enter message:")
  59.         local msg = read()
  60.         open(s_id)
  61.         send(r_id,s_id,msg)
  62.     end
  63. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top