Advertisement
MichalN

ComputerCraft Lua cell tower [WIP]

Aug 13th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. --[[
  2. Made by Michal Nemecek. Please do not redistribute.
  3. ]]--
  4. rednet.open("back")
  5. while true do
  6.     phout = nil
  7.     phexists = false
  8.     id,msg = rednet.receive()
  9.     rs = msg:sub(1,1)
  10.     if rs == "R" then
  11.         if tonumber(msg:sub(2,10)) ~= nil and tonumber(msg:sub(11)) ~= nil then
  12.             for line in io.lines("phonebook.txt") do
  13.                 if line:sub(1,9) == msg:sub(2,10) then
  14.                     phexists = true
  15.                     break
  16.                 end
  17.             end
  18.         end
  19.         if not phexists then
  20.             io.close("phonebook.txt")
  21.             io.open("phonebook.txt","a")
  22.             io.write(msg:sub(2))
  23.         end
  24.     elseif rs == "S" then
  25.         for line in io.lines("phonebook.txt") do
  26.             if line:sub(1,9) == msg:sub(2,10) then
  27.                 phexists = true
  28.                 phout = line:sub(10)
  29.                 rednet.send(tonumber(phout),msg:sub(11))
  30.             end
  31.         end
  32.     end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement