Guest User

guardTimer.sp

a guest
May 29th, 2014
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.20 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <morecolors>
  3. #include <clientprefs>
  4.  
  5. #pragma semicolon 1
  6.  
  7. new Handle:guardCookie;
  8. new Handle:cvarTimeRequired;
  9.  
  10. new bool:canUseGuard[MAXPLAYERS + 1];
  11.  
  12. public Plugin:myinfo =
  13. {
  14.     name = "Guard Timer",
  15.     author = "Bleed",
  16.     description = "Forces people to play for 1 hour before using the guard queue",
  17.     version = "0.1",
  18.     url = "www.xenogamers.org"
  19. };
  20.  
  21. public OnPluginStart()
  22. {
  23.     AddCommandListener(Command_Guard, "sm_guard");
  24.     guardCookie = RegClientCookie("clientPlayTime", "Holds the amount of time a client has played", CookieAccess_Private);
  25.     CreateTimer(60.0, Timer_MinutePassed, _, TIMER_REPEAT);
  26.    
  27.     cvarTimeRequired = CreateConVar("sm_guardqueue_timerequired", "60", "Time in minutes required for people to play as CT");
  28. }
  29.  
  30. public OnClientCookiesCached(client)
  31. {
  32.     decl String:cookie[32];
  33.     GetClientCookie(client, guardCookie, cookie, sizeof(cookie));
  34.     if(cookie[0] == '\0')
  35.     {
  36.         SetClientCookie(client, guardCookie, "0");
  37.         Format(cookie, sizeof(cookie), "0");
  38.     }
  39.     canUseGuard[client] = StringToInt(cookie) >= GetConVarInt(cvarTimeRequired);
  40. }
  41.  
  42. public Action:Command_Guard(client, const String:command[], args)
  43. {
  44.     if(canUseGuard[client])
  45.         return Plugin_Continue;
  46.     decl String:cookie[32];
  47.     GetClientCookie(client, guardCookie, cookie, sizeof(cookie) );
  48.     new timeRemaining = GetConVarInt(cvarTimeRequired) - StringToInt(cookie);
  49.     CReplyToCommand(client, "{GREEN}[xG] {BLUE}you must have played for %i minutes before you can join the guard queue!\n{GREEN}[xG] {BLUE}You have %i minutes remaining.",GetConVarInt(cvarTimeRequired), timeRemaining);
  50.     return Plugin_Handled;
  51. }
  52.  
  53. public Action:Timer_MinutePassed(Handle:timer)
  54. {
  55.     decl String:cookie[32];
  56.     new timeRequired = GetConVarInt(cvarTimeRequired);
  57.     for(new i = 1; i < MaxClients;i++)
  58.     {
  59.         if(IsClientInGame(i) && !IsFakeClient(i))
  60.         {
  61.             GetClientCookie(i, guardCookie, cookie, sizeof(cookie));
  62.             if(StringToInt(cookie) == timeRequired)
  63.             {
  64.                 CPrintToChat(i, "{GREEN}[xG] {BLUE}You can now use the guard queue. Type !guard to join the queue.");
  65.                 canUseGuard[i] = true;
  66.             }
  67.             Format(cookie, sizeof(cookie), "%i", StringToInt(cookie) + 1);
  68.             SetClientCookie(i, guardCookie, cookie);
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment