Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1.  
  2. if SERVER then
  3. PLAYTIME_DAYS = 86400
  4.  
  5. hook.Add("PlayerSay", "AnexPlaytimeCommand", function(ply, text, team)
  6. local args = string.Explode(" ",text)
  7. if args[1] then
  8. if args[1] == "!playtime" then
  9.  
  10. args[1] = ""
  11. local name = string.Trim(string.Implode(" ", args))
  12. local ply2 = nil
  13.  
  14. if name != nil and name != "" then
  15. for k, v in pairs(player.GetAll()) do
  16. if v:GetName() == name then
  17. ply2 = v
  18. break
  19. end
  20. end
  21. end
  22.  
  23. if name != nil and name != "" and ply2 == nil then
  24. for k, v in pairs(player.GetAll()) do
  25. if string.find(string.lower(v:GetName()), string.lower(name)) then
  26. ply2 = v
  27. break
  28. end
  29. end
  30. end
  31.  
  32. local target
  33. if ply2 then
  34. target = ply2
  35. else
  36. target = ply
  37. end
  38.  
  39. local pattern = "(.*) (.*) ([0-9]) ([0-9][0-9]):([0-9][0-9]):([0-9][0-9]) ([0-9][0-9][0-9][0-9])"
  40.  
  41. local query = sql.QueryRow( "SELECT totaltime FROM utime WHERE player = " .. target:UniqueID() .. " LIMIT 1;" )
  42.  
  43. if query and query["totaltime"] then
  44. startTime = tonumber(query["totaltime"])
  45. else
  46. startTime = os.time()
  47. end
  48.  
  49. local weeks, days, hours, minutes = FormatSeconds(startTime)
  50.  
  51.  
  52. local package = string.format("chat.AddText(Color(0, 158, 158),'%02dW, %02dD, %02dH, %02dM')", weeks, days, hours, minutes)
  53.  
  54. local nextRank, timeUntil, nextRankQuantity, nextRankR, nextRankG, nextRankB
  55.  
  56. if startTime < 0.5*PLAYTIME_DAYS then
  57. nextRank = "Member"
  58. nextRankR, nextRankG, nextRankB = 255, 80, 80
  59. timeUntil = ((0.5*PLAYTIME_DAYS)-startTime)/60/60/24
  60. nextRankQuantity = "Days"
  61. if timeUntil <= 0 then
  62. timeUntil = ((0.5*PLAYTIME_DAYS)-startTime)/60/60
  63. nextRankQuantity = "Hours"
  64. end
  65.  
  66. elseif startTime < 7*PLAYTIME_DAYS then
  67. nextRank = "Veteran"
  68. nextRankR, nextRankG, nextRankB = 255, 80, 80
  69. timeUntil = ((7*PLAYTIME_DAYS)-startTime)/60/60/24
  70. nextRankQuantity = "Days"
  71. end
  72.  
  73. if nextRank then
  74. package = package .. string.format("chat.AddText(Color(255, 255, 255), 'Next Rank: ', Color(%d, %d, %d), '[%s]', Color(255, 255, 255), ' %d %s Left')", nextRankR, nextRankG, nextRankB, nextRank, timeUntil, nextRankQuantity)
  75. end
  76.  
  77. timer.Simple(0.1, function()
  78. ply:SendLua(package)
  79. end)
  80. end
  81. end
  82. end)
  83. end
  84.  
  85. function FormatSeconds(secondsArg)
  86.  
  87. local weeks = math.floor(secondsArg / 604800)
  88. local remainder = secondsArg % 604800
  89. local days = math.floor(remainder / 86400)
  90. local remainder = remainder % 86400
  91. local hours = math.floor(remainder / 3600)
  92. local remainder = remainder % 3600
  93. local minutes = math.floor(remainder / 60)
  94. local seconds = remainder % 60
  95.  
  96. return weeks, days, hours, minutes
  97. end
  98.  
  99.  
  100. function EscapeName(name)
  101. return string.gsub(name, "[\'\"]", "\\'")
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement