Advertisement
Mr_Thomson

Untitled

Apr 28th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. monitor = peripheral.wrap("top");
  2.  
  3. file = fs.open("d.json","r");
  4. d = textutils.unserialize(file.readLine());
  5. file.close();
  6.  
  7.  
  8. function adddeath(deadmeat)
  9. local playerindex = nil;
  10. for i,plyr in pairs(d) do
  11. if plyr.p == deadmeat then
  12. playerindex = i;
  13. end
  14. end
  15. if not playerindex then
  16. playerindex = #d+1;
  17. d[playerindex] = { };
  18. d[playerindex].p = deadmeat;
  19. d[playerindex].d = 0;
  20. end
  21. d[playerindex].d = d[playerindex].d + 1;
  22. file = fs.open("d.json","w");
  23. file.writeLine(textutils.serialize(d));
  24. file.close();
  25. end
  26.  
  27. function sortfn(a,b)
  28. return a.d > b.d;
  29. end
  30.  
  31. function printlist()
  32. local ds = table.sort(d,sortfn);
  33. monitor.clear();
  34. monitor.setCursorPos(1,1);
  35. local i;
  36. monitor.write("Death Counter 3000");
  37. i = 2;
  38. for _,p in pairs(d) do
  39. monitor.setCursorPos(1,i);
  40. monitor.write(p.p);
  41. monitor.setCursorPos(17,i);
  42. monitor.write("|" .. p.d);
  43. i = i + 1;
  44. end
  45. end
  46.  
  47.  
  48. repeat
  49. printlist();
  50. _,p = os.pullEvent("chat_death");
  51. adddeath(p);
  52. until false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement