Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 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. elseif startTime < 7*PLAYTIME_DAYS then
  62. nextRank = "Veteran"
  63. nextRankR, nextRankG, nextRankB = 255, 80, 80
  64. timeUntil = ((7*PLAYTIME_DAYS)-startTime)/60/60/24
  65. nextRankQuantity = "Days"
  66. end
  67.  
  68. if nextRank then
  69. 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)
  70. end
  71.  
  72. timer.Simple(0.1, function()
  73. ply:SendLua(package)
  74. end)
  75. end
  76. end
  77. end)
  78. end
  79.  
  80. function FormatSeconds(secondsArg)
  81.  
  82. local weeks = math.floor(secondsArg / 604800)
  83. local remainder = secondsArg % 604800
  84. local days = math.floor(remainder / 86400)
  85. local remainder = remainder % 86400
  86. local hours = math.floor(remainder / 3600)
  87. local remainder = remainder % 3600
  88. local minutes = math.floor(remainder / 60)
  89. local seconds = remainder % 60
  90.  
  91. return weeks, days, hours, minutes
  92. end
  93.  
  94.  
  95. function EscapeName(name)
  96. return string.gsub(name, "[\'\"]", "\\'")
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement