ecco7777

Player lister

Jun 12th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. p=peripheral.wrap("top")
  2. file="players"
  3. function fileToTable(file)
  4. if fs.exists(file)~=true then
  5. print("file"..file.." not found")
  6. return(false)
  7. end
  8. fp=fs.open(file,"r")
  9. line={}
  10. i=1
  11. line[i]=fp.readLine()
  12. if line[i]==nil then return(false) end
  13. while line[i]~=nil do
  14. i=i+1
  15. line[i]=fp.readLine()
  16. end
  17. return(line)
  18. end
  19.  
  20. function addPlayer()
  21. e,player=os.pullEvent("player")
  22. eingetragen=false
  23. if fs.exists(file) then
  24. players=fileToTable(file)
  25. i=1
  26. while players[i]~=nil do
  27. if players[i]==player then
  28. eingetragen=true
  29. end
  30. end
  31. end
  32. if eingetragen==false then
  33. fp=fs.open(file,"a")
  34. fp.writeLine(player)
  35. end
  36. end
Add Comment
Please, Sign In to add comment