Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.73 KB | None | 0 0
  1. #include <sdktools>
  2. #include <clientprefs>
  3.  
  4. bool g_bSpecListhidden[MAXPLAYERS + 1];
  5.  
  6. bool g_bSpecListEnabled[MAXPLAYERS + 1];
  7. bool g_bSpecListHidden[MAXPLAYERS + 1];
  8. Handle g_hSpecListEnabledCookie;
  9. Handle g_hSpecListHiddenCookie;
  10.  
  11. public Plugin myinfo =
  12. {
  13.     name = "[SM] Spectator List",
  14.     description = "",
  15.     author = "AllliedModder",
  16.     version = "1.0",
  17.     url = ""
  18. };
  19.  
  20. public void OnPluginStart()
  21. {
  22.     RegConsoleCmd("sm_speclist", Command_SpecList);
  23.     RegAdminCmd("sm_hidden", Command_hidden, ADMFLAG_GENERIC);
  24.    
  25.     g_hSpecListEnabledCookie = RegClientCookie("Speclist_Enabled", "Speclist on or off", CookieAccess_Private);
  26.     g_hSpecListHiddenCookie = RegClientCookie("Speclist_Hidden", "Hidden from speclist or shown", CookieAccess_Private);
  27.     // late loading
  28.     for(int i = 1; i <= MaxClients; i++)
  29.     {
  30.         if(IsClientConnected(i) && AreClientCookiesCached(i))
  31.         {
  32.             OnClientCookiesCached(i);
  33.         }
  34.     }
  35. }
  36.  
  37. public void OnMapStart()
  38. {
  39.     CreateTimer(2.5, Timer_UpdateHudHint, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  40. }
  41.  
  42. public void OnClientPutInServer(int client)
  43. {
  44.     g_bSpecListEnabled[client] = true;
  45.     g_bSpecListhidden[client] = false;
  46. }
  47.  
  48. public void OnClientCookiesCached(int client)
  49. {
  50.     char value[16];
  51.     GetClientCookie(client, g_hSpecListEnabledCookie, value, sizeof(value));
  52.     GetClientCookie(client, g_hSpecListHiddenCookie, value, sizeof(value));
  53.    
  54.     g_bSpecListEnabled[client] = (value[0] != '\0' && StringToInt(value));
  55.     g_bSpecListHidden[client] = (value[0] != \0' && StringToInt(value))
  56. }
  57.  
  58. public Action Command_hidden(int client, int args)
  59. {
  60.     g_bSpecListhidden[client] = !g_bSpecListhidden[client];
  61.     SetClientCookie(client, g_hSpecListHiddenCookie, g_bSpecListhidden[client] ? "1" : "0");
  62.  
  63.     if(g_bSpecListhidden[client])
  64.         ReplyToCommand(client, "\x01[\x02SM\x01] You will now be hidden from speclist.");
  65.     else
  66.         ReplyToCommand(client, "\x01[\x02SM\x01] You will now be shown on speclist.");
  67.    
  68.     return Plugin_Handled;
  69. }
  70.  
  71. public Action Command_SpecList(int client, int args)
  72. {
  73.     g_bSpecListEnabled[client] = !g_bSpecListEnabled[client];
  74.     SetClientCookie(client, g_hSpecListEnabledCookie, g_bSpecListEnabled[client] ? "1" : "0");
  75.     ReplyToCommand(client, "\x01[\x02SM\x01] Spectator list %s.", g_bSpecListEnabled[client] ? "enabled" : "disabled");
  76.    
  77.     return Plugin_Handled;
  78. }
  79.  
  80. public Action Timer_UpdateHudHint(Handle timer)
  81. {
  82.     static char szText[256];
  83.    
  84.     for(int client = 1; client <= MaxClients; client++)
  85.     {
  86.         bool bDisplayHint;
  87.         szText = "";
  88.        
  89.         if(IsValidClient(client))
  90.         {
  91.             if(IsPlayerAlive(client))
  92.             {
  93.                 // first loop, for creating the hud string
  94.                 for(int i = 1; i <= MaxClients; i++)
  95.                 {
  96.                     if(!IsClientInGame(i) || !IsClientObserver(i) || g_bSpecListhidden[i])
  97.                     {
  98.                         continue;
  99.                     }
  100.                        
  101.                     int iSpecMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
  102.                     if(iSpecMode == 4 || iSpecMode == 5)
  103.                     {
  104.                         int iTarget = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
  105.                         if(client == iTarget)
  106.                         {
  107.                             if(CheckCommandAccess(iTarget, "speclist_admin_flag", ADMFLAG_KICK))
  108.                             {
  109.                                 Format(szText, sizeof(szText), "%s<font color='#21618C'>%N.</font> ", szText, i)
  110.                             }
  111.                             else if(CheckCommandAccess(iTarget, "speclist_vip_flag", ADMFLAG_KICK))
  112.                             {
  113.                                 Format(szText, sizeof(szText), "%s<font color='#D4AC0D'>%N.</font> ", szText, i);
  114.                             }
  115.                             else
  116.                             {
  117.                                 Format(szText, sizeof(szText), "%s%N. ", szText, i);
  118.                             }
  119.                                
  120.                             bDisplayHint = true;
  121.                         }
  122.                     }
  123.                 }
  124.                
  125.                 if(bDisplayHint)
  126.                 {
  127.                     if(g_bSpecListEnabled[client])
  128.                     {
  129.                         PrintHintText(client, "<font size='12'><u>Spectators:\n</u></font><font size='15'>%s</font>", szText);
  130.                     }
  131.                    
  132.                     // second loop, to print string to all spectators with speclist enabled
  133.                     // instead of relooping through all players for all spectators as well and remaking hud
  134.                     for(int i = 1; i <= MaxClients; i++)
  135.                     {
  136.                         if(!IsClientInGame(i) || !IsClientObserver(i) || g_bSpecListEnabled[i])
  137.                         {
  138.                             continue;
  139.                         }
  140.                        
  141.                         int iSpecMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
  142.                         if(iSpecMode == 4 || iSpecMode == 5)
  143.                         {
  144.                             int iTarget = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
  145.                             if(client == iTarget)
  146.                             {
  147.                                 PrintHintText(iTarget, "<font size='12'><u>Spectators:\n</u></font><font size='15'>%s</font>", szText);
  148.                             }
  149.                         }
  150.                     }
  151.                 }
  152.             }
  153.         }
  154.     }
  155.    
  156.     return Plugin_Continue;
  157. }
  158.  
  159. stock bool IsValidClient(int iClient)
  160. {
  161.     if (iClient <= 0)
  162.     {
  163.         return false;
  164.     }
  165.     if (iClient > MaxClients)
  166.     {
  167.         return false;
  168.     }
  169.     if (!IsClientConnected(iClient))
  170.     {
  171.         return false;
  172.     }
  173.     return IsClientInGame(iClient);
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement