Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then
- PLAYTIME_DAYS = 86400
- hook.Add("PlayerSay", "AnexPlaytimeCommand", function(ply, text, team)
- local args = string.Explode(" ",text)
- if args[1] then
- if args[1] == "!playtime" then
- args[1] = ""
- local name = string.Trim(string.Implode(" ", args))
- local ply2 = nil
- if name != nil and name != "" then
- for k, v in pairs(player.GetAll()) do
- if v:GetName() == name then
- ply2 = v
- break
- end
- end
- end
- if name != nil and name != "" and ply2 == nil then
- for k, v in pairs(player.GetAll()) do
- if string.find(string.lower(v:GetName()), string.lower(name)) then
- ply2 = v
- break
- end
- end
- end
- local target
- if ply2 then
- target = ply2
- else
- target = ply
- end
- local pattern = "(.*) (.*) ([0-9]) ([0-9][0-9]):([0-9][0-9]):([0-9][0-9]) ([0-9][0-9][0-9][0-9])"
- local query = sql.QueryRow( "SELECT totaltime FROM utime WHERE player = " .. target:UniqueID() .. " LIMIT 1;" )
- if query and query["totaltime"] then
- startTime = tonumber(query["totaltime"])
- else
- startTime = os.time()
- end
- local weeks, days, hours, minutes = FormatSeconds(startTime)
- local package = string.format("chat.AddText(Color(0, 158, 158),'%02dW, %02dD, %02dH, %02dM')", weeks, days, hours, minutes)
- local nextRank, timeUntil, nextRankQuantity, nextRankR, nextRankG, nextRankB
- if startTime < 0.5*PLAYTIME_DAYS then
- nextRank = "Member"
- nextRankR, nextRankG, nextRankB = 255, 80, 80
- timeUntil = ((0.5*PLAYTIME_DAYS)-startTime)/60/60/24
- nextRankQuantity = "Days"
- elseif startTime < 7*PLAYTIME_DAYS then
- nextRank = "Veteran"
- nextRankR, nextRankG, nextRankB = 255, 80, 80
- timeUntil = ((7*PLAYTIME_DAYS)-startTime)/60/60/24
- nextRankQuantity = "Days"
- end
- if nextRank then
- 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)
- end
- timer.Simple(0.1, function()
- ply:SendLua(package)
- end)
- end
- end
- end)
- end
- function FormatSeconds(secondsArg)
- local weeks = math.floor(secondsArg / 604800)
- local remainder = secondsArg % 604800
- local days = math.floor(remainder / 86400)
- local remainder = remainder % 86400
- local hours = math.floor(remainder / 3600)
- local remainder = remainder % 3600
- local minutes = math.floor(remainder / 60)
- local seconds = remainder % 60
- return weeks, days, hours, minutes
- end
- function EscapeName(name)
- return string.gsub(name, "[\'\"]", "\\'")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement