Advertisement
Rochet2

Ban and Bantime

Apr 9th, 2012
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. local Ban, UnBan
  2.  
  3. function Ban(event, pPlayer, pMessage, pType, pLanguage, pMisc)
  4.     local msg = pMessage:lower
  5.     if(msg:find("[.!]Ban .+ %d+")) then
  6.         local Name, Time = msg:match("[.!]Ban (%a*) (%d*)") -- Time = Minutes
  7.         local Current = os.date("!*t")
  8.         Current.min = Current.min+Time
  9.         local expire = os.time(Current)
  10.  
  11.         WorldDBQuery("UPDATE system SET banned = 1, expiredate = "..expire.." WHERE Player = '"..Name.."';")
  12.         CreateLuaEvent(function() UnBan(Name) end, Time*60000, 1)
  13.         return false
  14.     end
  15. end
  16.  
  17. function UnBan(Name)
  18.     WorldDBQuery("UPDATE system SET banned = 0 WHERE Player = '"..Name.."';")
  19. end
  20.  
  21. do
  22.     local Q = WorldDBQuery("SELECT expiredate, Player FROM system WHERE banned <> 0;")
  23.     if(Q) then
  24.         local Time = os.time()
  25.         for i = 1, Q:GetRowCount() do
  26.             local expire, Name = Q:GetColumn(0):GetULong(), Q:GetColumn(1):GetString()
  27.             if(expire <= Time) then
  28.                 UnBan(Name)
  29.             else
  30.                 CreateLuaEvent(function() UnBan(Name) end, (expire-Time)*1000, 1)
  31.             end
  32.         end
  33.     end
  34. end
  35.  
  36. RegisterServerHook(16, Ban)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement