Advertisement
Guest User

Untitled

a guest
May 11th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. local function ncleanup()
  2.     game.ConsoleCommand("gmod_admin_cleanup\n")
  3.     timer.Remove("timeleft")
  4.     for k,v in pairs(player.GetAll()) do
  5.         v:SendLua([[chat.AddText(Color(0,255,0), "[Cleanup Timer] - ",Color(255,0,0), " Log | ", Color(255,255,255), " Map cleaned up succesfully!")]])
  6.     end
  7. end
  8.  
  9. function SecondsToClock(seconds)
  10.   local seconds = tonumber(seconds)
  11.  
  12.   if seconds <= 0 then
  13.     return "00:00:00";
  14.   else
  15.     hours = string.format("%02.f", math.floor(seconds/3600));
  16.     mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
  17.     secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
  18.     return mins..":"..secs
  19.   end
  20. end
  21.    
  22. hook.Add("PlayerSay", "CleanupTimer", function(ply, text)
  23.     local text = string.lower( text )
  24.     local args = string.Explode(" ", text )
  25.     if (args[1] == "/cleanupt") then
  26.     if (ply:IsAdmin() == false) then
  27.     ply:SendLua([[chat.AddText(Color(0,255,0), "[Cleanup Timer] - ",Color(255,0,0), " Error | ", Color(255,255,255), " Incorrect Rank! your current rank is " .. ply:GetUserGroup() .. " and you must be an Admin in order to start a cleanup timer!")]])
  28.     return false
  29.     end
  30.    
  31.         if ( tonumber(args[2]) == nil) || (tonumber(args[2]) > 120) || (tonumber(args[2]) < 0) then
  32.             ply:SendLua([[chat.AddText(Color(0,255,0), "[Cleanup Timer] - ",Color(255,0,0), " Error | ", Color(255,255,255), " Possible reasons: \n-No integer specified \n-Entered a string instead \n-Above 120 or below 0")
  33.             surface.PlaySound("buttons/button11.wav")]])
  34.             return false
  35.         end
  36.        
  37.     local timeleft = tonumber(args[2])
  38.     if(timer.Exists("cleanupt")) then
  39.         ply:SendLua([[chat.AddText(Color(0,255,0), "[Cleanup Timer] - ",Color(255,0,0), " Error | ", Color(255,255,255), " Timer already exists! ")]])
  40.     return false
  41.     end
  42.     timer.Create("cleanupt", tonumber(args[2]), 1, ncleanup)
  43.    
  44.     for k,v in pairs(player.GetAll()) do
  45.         v:SendLua([[chat.AddText(Color(0,255,0), "[Cleanup Timer] - ", Color(0, 200, 255), ply:Nick() .. " Started a cleanup!") surface.PlaySound("buttons/button17.wav")]])
  46.         timer.Create("timeleft", 1, tonumber(args[2]), function() timeleft = timeleft - 1 PrintMessage(HUD_PRINTCENTER, "The map will cleanup in: " .. SecondsToClock(timeleft) .. "\nSave all your work!") if (timeleft < 20) then v:SendLua([[surface.PlaySound("hl1/fvox/blip.wav")]]) end end)
  47.         return false
  48.     end
  49.    
  50.     elseif(text =="/cancel") then
  51.     if (ply:IsAdmin() == false) then
  52.     ply:SendLua([[chat.AddText(Color(0,255,0), "[Cleanup Timer] - ",Color(255,0,0), " Error | ", Color(255,255,255), " Incorrect Rank! Are you an admin ?")]])
  53.     return false
  54.     end
  55.     if(timer.Exists("cleanupt") == false) then
  56.         ply:SendLua([[chat.AddText(Color(0,255,0), "[Cleanup Timer] - ",Color(255,0,0), " Error | ", Color(255,255,255), " There is no cleanup going on at  the moment! Create one using /cleanupt <number> ")]])
  57.     return false
  58.     end
  59.     timer.Remove("cleanupt")
  60.     timer.Remove("timeleft")
  61.         for k,v in pairs (player.GetAll()) do
  62.             v:SendLua([[chat.AddText(Color(0,255,0), "[Cleanup Timer] - ", Color(0, 200, 255), ply:Nick() .. " has cancelled the cleanup!") surface.PlaySound("buttons/button17.wav")]])
  63.         end
  64.     return false
  65.     end
  66. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement