Epuuc

Minecraft CC Listen Local Id

Nov 22nd, 2020 (edited)
1,754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. function split(pString, pPattern)
  2.    local Table = {}  -- NOTE: use {n = 0} in Lua-5.0
  3.    local fpat = "(.-)" .. pPattern
  4.    local last_end = 1
  5.    local s, e, cap = pString:find(fpat, 1)
  6.    while s do
  7.           if s ~= 1 or cap ~= "" then
  8.          table.insert(Table,cap)
  9.           end
  10.           last_end = e+1
  11.           s, e, cap = pString:find(fpat, last_end)
  12.    end
  13.    if last_end <= #pString then
  14.           cap = pString:sub(last_end)
  15.           table.insert(Table, cap)
  16.    end
  17.    return Table
  18. end
  19. local function getId()
  20.     local id = 99
  21.     if fs.exists("/data/owner") then
  22.         local file = fs.open("/data/owner","r")
  23.         local content = file.readAll()
  24.         if content == "" then print("Computer not owned, global frequency used.") return id end
  25.         local id = tonumber(split(content,"_")[2])
  26.     return id
  27.     else
  28.         print("Computer not owned, global frequency used.")
  29.     return id
  30.     end
  31. end
  32.  
  33. local id = getId()
  34. local modem = peripheral.find("modem")
  35. if not modem then print("Modem required, please attach one before using this program") end
  36. modem.open(id)
  37. term.clear()
  38. term.setCursorPos(1,1)
  39. print("Listening on Local Frequency:",id)
  40. while true do
  41.     local ev,side,channel,rpchannel,msg,distance = os.pullEvent()
  42.     if ev == "modem_message" then
  43.         print("Frequency:",channel)
  44.         print("R:",msg.Reason)
  45.         if term.isColor() then
  46.             term.setTextColour(colors.purple)
  47.         end
  48.         print("C:",msg.Content)
  49.         term.setTextColor(colors.white)
  50.     elseif ev == "key" then
  51.         local key = keys.getName(side)
  52.         if key == "c" then
  53.             term.clear()
  54.             term.setCursorPos(1,1)
  55.             print("Listening on Local Frequency:",id)
  56.         end
  57.     end
  58. end
  59.  
  60.  
Add Comment
Please, Sign In to add comment