SHARE
TWEET

test.lua

a guest Jul 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function split(pString, pPattern)
  2.     local Table = {}
  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.  
  20. rednet.open("top")
  21. id,msg = rednet.receive()
  22. data = split(msg, "-")
  23. user = data[1]
  24. action = data[2]
  25. if action == 1 then
  26.     f = fs.open(user .. ".txt", "r")
  27.     fc = f.readAll()
  28.     f.close
  29.     if tonumber(fc) > 0 then
  30.         w = fs.open(user .. ".txt", "w")
  31.         new = fc - 1
  32.         w.write(new)
  33.         w.close()      
  34.         rednet.send(id,"ok")
  35.     else
  36.         rednet.send(id,"no")
  37.     end
  38. 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