Advertisement
Guest User

test.lua

a guest
Jul 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. while true do
  2. function split(pString, pPattern)
  3.     local Table = {}
  4.     local fpat = "(.-)" .. pPattern
  5.     local last_end = 1
  6.     local s, e, cap = pString:find(fpat, 1)
  7.     while s do
  8.         if s ~= 1 or cap ~= "" then
  9.             table.insert(Table,cap)
  10.         end
  11.         last_end = e+1
  12.         s, e, cap = pString:find(fpat, last_end)
  13.     end
  14.     if last_end <= #pString then
  15.         cap = pString:sub(last_end)
  16.         table.insert(Table, cap)
  17.     end
  18.     return Table
  19. end    
  20.  
  21. rednet.open("top")
  22. id,msg = rednet.receive()
  23. data = split(msg, "-")
  24. user = data[1]
  25. action = tonumber(data[2])
  26. if action == 1 then
  27.     f = fs.open(user .. ".txt", "r")
  28.     fc = f.readAll()
  29.     f.close()
  30.     if tonumber(fc) > 0 then
  31.         w = fs.open(user .. ".txt", "w")
  32.         new = tonumber(fc) - 1
  33.         w.write(new)
  34.         w.close()      
  35.         rednet.send(id,"ok")
  36.     else
  37.         rednet.send(id,"no")
  38.     end
  39. end
  40. if action == 2 then
  41.     f = fs.open(user .. ".txt", "r")
  42.     fc = f.readAll()
  43.     f.close()
  44.     rednet.send(id,fc)
  45. end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement