Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function split(pString, pPattern)
- local Table = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table, cap)
- end
- return Table
- end
- local function getId()
- local id = 99
- if fs.exists("/data/owner") then
- local file = fs.open("/data/owner","r")
- local content = file.readAll()
- if content == "" then print("Computer not owned, global frequency used.") return id end
- local id = tonumber(split(content,"_")[2])
- return id
- else
- print("Computer not owned, global frequency used.")
- return id
- end
- end
- local id = getId()
- local modem = peripheral.find("modem")
- if not modem then print("Modem required, please attach one before using this program") end
- modem.open(id)
- term.clear()
- term.setCursorPos(1,1)
- print("Listening on Local Frequency:",id)
- while true do
- local ev,side,channel,rpchannel,msg,distance = os.pullEvent()
- if ev == "modem_message" then
- print("Frequency:",channel)
- print("R:",msg.Reason)
- if term.isColor() then
- term.setTextColour(colors.purple)
- end
- print("C:",msg.Content)
- term.setTextColor(colors.white)
- elseif ev == "key" then
- local key = keys.getName(side)
- if key == "c" then
- term.clear()
- term.setCursorPos(1,1)
- print("Listening on Local Frequency:",id)
- end
- end
- end
Add Comment
Please, Sign In to add comment