Advertisement
Guest User

Untitled

a guest
May 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.78 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <cstrike>
  3. #include <sdktools>
  4. #pragma newdecls required
  5. #pragma semicolon 1
  6.  
  7. ConVar cvTeamchangelimit;
  8. ConVar cvExcludespec;
  9. Handle hTeam;
  10. int iTeamchangecount[MAXPLAYERS+1];
  11.  
  12. public Plugin myinfo =
  13. {
  14.     name = "Team Change Regulator",
  15.     author = "Shibby",
  16.     description = "Regulates team change.",
  17.     version = "1.0",
  18.     url = ""
  19. };
  20.  
  21. public void OnPluginStart()
  22. {
  23.     hTeam = CreateConVar("sm_join_team", "1", "Do not edit this");
  24.     cvTeamchangelimit = CreateConVar("sm_teamchange_limit", "1", "Sets how many times a player may switch between teams. Default = 1");
  25.     cvExcludespec = CreateConVar("sm_teamchange_excludespec", "1", "Should we exclude counting team changes to spectators? 0 = Disable");
  26.     AddCommandListener(cmdListener_Changeteam, "jointeam");
  27.     HookEvent("player_connect_full", vEvent_OnFullConnect, EventHookMode_Post);
  28. }
  29.  
  30. public void vEvent_OnFullConnect(Event event, const char[] name, bool dontBroadcast)
  31. {
  32.     int client = GetClientOfUserId(event.GetInt("userid"));
  33.     if (client != 0 && IsClientInGame(client) && !IsFakeClient(client) && !bIsAdminRoot(client))
  34.     {
  35.         CreateTimer(0.5, tAssignTeam, client);
  36.     }
  37. }
  38.  
  39. public void OnClientPutInServer(int client)
  40. {
  41.     if (!IsFakeClient(client) && IsClientInGame(client))
  42.     {
  43.         iTeamchangecount[client] = 0;
  44.     }
  45. }
  46.  
  47. public Action tAssignTeam(Handle timer, any client)
  48. {
  49.     if (IsClientInGame(client))
  50.     {
  51.         int iCvar = GetConVarInt(hTeam);
  52.         switch (iCvar)
  53.         {
  54.             case 0:
  55.             {
  56.                 return Plugin_Handled;
  57.             }
  58.  
  59.             case 1:
  60.             {
  61.                 int iRed;
  62.                 int iBlue;
  63.                 for (int i = 1; i <= MaxClients; i++)
  64.                 {
  65.                     if (!IsClientInGame(i))
  66.                     {
  67.                         continue;
  68.                     }
  69.  
  70.                     int iTeam = GetClientTeam(i);
  71.                     if (iTeam == CS_TEAM_T)
  72.                     {
  73.                         iRed++;
  74.                     }
  75.  
  76.                     else if (iTeam == CS_TEAM_CT)
  77.                     {
  78.                         iBlue++;
  79.                     }
  80.                 }
  81.  
  82.                 if (iRed > iBlue)
  83.                 {
  84.                     ChangeClientTeam(client, 3);
  85.                 }
  86.  
  87.                 else if (iRed < iBlue || iRed == iBlue)
  88.                 {
  89.                     ChangeClientTeam(client, 2);
  90.                 }
  91.             }
  92.  
  93.             case 2:
  94.             {
  95.                 ChangeClientTeam(client, 2);
  96.             }
  97.  
  98.             case 3:
  99.             {
  100.                 ChangeClientTeam(client, 3);
  101.             }
  102.         }
  103.     }
  104.  
  105.     return Plugin_Continue;
  106. }
  107.  
  108. public Action cmdListener_Changeteam(int client, const char[] command, int args)
  109. {
  110.     if (bIsAdminRoot(client))
  111.     {
  112.         return Plugin_Continue;
  113.     }
  114.  
  115.     if (iTeamchangecount[client] == cvTeamchangelimit.IntValue)
  116.     {
  117.         PrintToChat(client, "[TeamManager] Nie mozesz ponownie zmienic teamu!!!");
  118.         PrintCenterText(client, "<font color='#FF0000'><b>[TeamManager]</font> <font color='#FFFFFF'>Nie mozesz ponownie zmienic teamu!!!</font>");
  119.         return Plugin_Handled;
  120.     }
  121.  
  122.     char arg1[3];
  123.     GetCmdArg(1, arg1, sizeof(arg1));
  124.     int target_team = StringToInt(arg1);
  125.     int current_team = GetClientTeam(client);
  126.     if (target_team == current_team)
  127.     {
  128.         return Plugin_Handled;
  129.     }
  130.  
  131.     else if ((target_team > 1 && cvExcludespec.IntValue >= 1) || cvExcludespec.IntValue < 1)
  132.     {
  133.         iTeamchangecount[client]++;
  134.     }
  135.  
  136.     return Plugin_Handled;
  137. }
  138.  
  139. bool bIsAdminRoot(int client)
  140. {
  141.     return (CheckCommandAccess(client, "team_change_admin", ADMFLAG_ROOT, false));
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement