Advertisement
NuAoA

Untitled

Jun 11th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. -- Death Logger 0.2
  2. -- By: NuAoA
  3. local list = {}
  4. if not fs.exists("wrap") then
  5. print("wrap API not found, downloading from http://pastebin.com/g5tBarus")
  6. shell.run("pastebin get g5tBarus wrap")
  7. end
  8. if not fs.exists("Draw") then
  9. print("Draw API not found, downloading from http://pastebin.com/3sAGiX7j")
  10. shell.run("pastebin get 3sAGiX7j Draw")
  11. end
  12. os.loadAPI("wrap")
  13. os.loadAPI("Draw")
  14. chat = wrap.attach("chat")
  15. mon = wrap.attach("monitor")
  16. function recordDeaths()
  17. sleep(0.2)
  18. os.queueEvent("read!")
  19. while true do
  20. local event,player = os.pullEvent("chat_death")
  21. local prev = ""
  22. if fs.exists("death.data") then
  23. local file = fs.open("death.data","r")
  24. prev = file.readAll()
  25. file:close()
  26. end
  27. local file = fs.open("death.data","w")
  28. file.write(player)
  29. file.write("\n")
  30. file.write(prev)
  31. file.close()
  32. os.queueEvent("read!")
  33. end
  34. end
  35.  
  36. function readDeaths()
  37. while true do
  38. local event = os.pullEvent("read!")
  39. if event ~= "read!" then
  40. else
  41. local file = fs.open("death.data","r")
  42. local slist = file.readAll()
  43. list = nil
  44. list = {}
  45. for word in string.gmatch(slist,"%S+") do
  46. if list[word] == nil then
  47. list[word] = 1
  48. else
  49. list[word] = list[word] + 1
  50. end
  51. end
  52. os.queueEvent("Print!")
  53. end
  54. end
  55. end
  56.  
  57. function writeScreen()
  58. while true do
  59. local event = os.pullEvent("Print!")
  60. if event ~= "Print!" then
  61. else
  62. local t_c,t_t = Draw.emptyScreen(mon)
  63. local BubbleList = {}
  64.  
  65. for i=1,#t_c,2 do
  66. Draw.tc(t_c,1,i,colors.brown,#t_c[1],i)
  67. end
  68. Draw.tc(t_c,1,1,colors.red,#t_c[1],1)
  69. Draw.tt(t_t,11,1,"Death Leaderboard")
  70. for i=1,#t_c do
  71. local high_val = 0
  72. local high_name = ""
  73. for k,v in pairs(list) do
  74. if v > high_val then
  75. high_val = v
  76. high_name = k
  77. end
  78. end
  79. if high_val > 0 then
  80. Draw.tt(t_t,1,i+1,string.sub(i..". ",0,5)..string.sub(high_name.." ",0,25).." "..string.sub(" ",string.len(high_val),10)..high_val)
  81. list[high_name] = nil
  82. end
  83. end
  84. Draw.draw(mon,t_c,1,1,colors.black,t_t)
  85. end
  86. end
  87. end
  88. mon.setTextScale(0.5)
  89. parallel.waitForAll(writeScreen,recordDeaths,readDeaths)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement