sharivan

l4d_afk_commands_zmbr.sp

Oct 28th, 2017 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.49 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  4. #define PLUGIN_VERSION    "1.2"
  5. #define PLUGIN_NAME       "[L4D(2)] AFK and Join Team Commands (ZMBR)"
  6.  
  7. #define L4D_MAXCLIENTS MaxClients
  8. #define L4D_MAXCLIENTS_PLUS1 (L4D_MAXCLIENTS + 1)
  9. #define L4D_TEAM_SURVIVORS 2
  10. #define L4D_TEAM_INFECTED 3
  11. #define L4D_TEAM_SPECTATE 1
  12.  
  13. Handle g_hTimer = null;
  14. Handle g_hConf = null;
  15. Handle g_hSHS = null;
  16. Handle g_hTOB = null;
  17.  
  18. public Plugin:myinfo =
  19. {
  20.     name = PLUGIN_NAME,
  21.     author = "MasterMe, modified by SHARIVAN from ZMBR clan",
  22.     description = "Adds commands to let the player spectate and join team. (!afk, !survivors, !infected, etc.)",
  23.     version = PLUGIN_VERSION,
  24.     url = "http://forums.alliedmods.net/showthread.php?t=122476"
  25. };
  26.  
  27. public void OnPluginStart()
  28. {
  29.     CreateConVar("afk_spectate_commands_zmbr_version", PLUGIN_VERSION, "Plugin version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  30.  
  31.     RegConsoleCmd("sm_survivors", AFKTurnClientToSurvivors);
  32.     RegConsoleCmd("sm_joinsurvivors", AFKTurnClientToSurvivors);
  33.     RegConsoleCmd("sm_jointeam2", AFKTurnClientToSurvivors);
  34.     RegConsoleCmd("sm_infected", AFKTurnClientToInfected);
  35.     RegConsoleCmd("sm_joininfected", AFKTurnClientToInfected);
  36.     RegConsoleCmd("sm_jointeam3", AFKTurnClientToInfected);
  37.    
  38.     g_hConf = LoadGameConfigFile("l4dunscrambler");
  39.     if (g_hConf == null)
  40.     {
  41.         SetFailState("Game config file l4dunscrambler not found.");
  42.         return;
  43.     }
  44.    
  45.     StartPrepSDKCall(SDKCall_Player);
  46.     PrepSDKCall_SetFromConf(g_hConf, SDKConf_Signature, "SetHumanSpec");
  47.     PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer);
  48.     g_hSHS = EndPrepSDKCall();
  49.    
  50.     StartPrepSDKCall(SDKCall_Player);
  51.     PrepSDKCall_SetFromConf(g_hConf, SDKConf_Signature, "TakeOverBot");
  52.     PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
  53.     g_hTOB = EndPrepSDKCall();
  54.    
  55.     g_hTimer = CreateTimer(60.0, OnTimer, _, TIMER_REPEAT);
  56. }
  57.  
  58. public void OnPluginEnd()
  59. {
  60.     KillTimer(g_hTimer);
  61. }
  62.  
  63. public Action OnTimer(Handle hTimer)
  64. {
  65.     for (int client = 1; client <= MaxClients; client++)
  66.     {
  67.         if (!Client_IsIngame(client) || IsFakeClient(client))
  68.             continue;
  69.  
  70.         int team = GetClientTeam(client);
  71.         if (team == L4D_TEAM_SPECTATE)
  72.         {
  73.             PrintToChat(client, "Voce esta SPEC pois os times sao limitados 10vs10.");
  74.             PrintToChat(client, "Assim que liberar uma vaga, digite !infected ou !survivor.");
  75.         }
  76.     }
  77. }
  78.  
  79. public Action AFKTurnClientToSurvivors(int client, int args)
  80. {
  81.     int team = GetClientTeam(client);
  82.     if (team == L4D_TEAM_SPECTATE)
  83.         ChangePlayerTeam(client, L4D_TEAM_SURVIVORS);
  84.     else
  85.         PrintToChat(client, "Este comando e liberado somente pra quem esta SPEC.");
  86.  
  87.     return Plugin_Handled;
  88. }
  89.  
  90. public Action AFKTurnClientToInfected(int client, int args)
  91. {
  92.     int team = GetClientTeam(client);
  93.     if (team == L4D_TEAM_SPECTATE)
  94.         ChangePlayerTeam(client, L4D_TEAM_INFECTED);
  95.     else
  96.         PrintToChat(client, "Este comando e liberado somente pra quem esta SPEC.");
  97.  
  98.     return Plugin_Handled;
  99. }
  100.  
  101. /**
  102. * Checks if the specified index is a player and connected.
  103. *
  104. * @param entity             An entity index.
  105. * @param checkConnected     Set to false to skip the IsClientConnected check
  106. * @return                   Returns true if the specified entity index is a player connected, false otherwise.
  107. */
  108. stock bool Client_IsValid(int client, bool checkConnected=true)
  109. {
  110.     if (client > 4096)
  111.         client = EntRefToEntIndex(client);
  112.  
  113.     if (client < 1 || client > MaxClients)
  114.         return false;
  115.  
  116.     if (checkConnected && !IsClientConnected(client))
  117.         return false;
  118.    
  119.     return true;
  120. }
  121.  
  122. /**
  123. * Checks if the specified index is a player and ingame.
  124. *
  125. * @param entity     An entity index.
  126. * @return           Returns true if the specified index is a player and ingame, false otherwise.
  127. */
  128. stock bool Client_IsIngame(int client)
  129. {
  130.     if (!Client_IsValid(client, false))
  131.         return false;
  132.  
  133.     return IsClientInGame(client);
  134. }
  135.  
  136. stock int GetTeamMaxHumans(int team)
  137. {
  138.     if (team == L4D_TEAM_SURVIVORS)
  139.         return GetConVarInt(FindConVar("survivor_limit"));
  140.  
  141.     if (team == L4D_TEAM_INFECTED)
  142.         return GetConVarInt(FindConVar("z_max_player_zombies"));
  143.  
  144.     if (team == L4D_TEAM_SPECTATE)
  145.         return L4D_MAXCLIENTS;
  146.    
  147.     return -1;
  148. }
  149.  
  150. stock bool IsClientInGameHuman(int client)
  151. {
  152.     if (client > 0)
  153.         return IsClientInGame(client) && !IsFakeClient(client);
  154.  
  155.     return false;
  156. }
  157.  
  158. stock int GetTeamHumanCount(int team)
  159. {
  160.     int humans = 0;
  161.    
  162.     for(int i = 1; i < L4D_MAXCLIENTS_PLUS1; i++)
  163.     {
  164.         if (IsClientInGameHuman(i) && GetClientTeam(i) == team)
  165.             humans++;
  166.     }
  167.    
  168.     return humans;
  169. }
  170.  
  171. stock bool ChangePlayerTeam(int client, int team)
  172. {
  173.     if (GetClientTeam(client) == team)
  174.         return true;
  175.        
  176.     int maxHumans = GetTeamMaxHumans(team);
  177.     if (GetTeamHumanCount(team) >= maxHumans)
  178.     {
  179.         PrintToChat(client, "O time está cheio. Permitido só %d jogadores", maxHumans);
  180.         return false;
  181.     }
  182.    
  183.     if (team != L4D_TEAM_SURVIVORS)
  184.     {
  185.         //we can always swap to infected or spectator, it has no actual limit
  186.         ChangeClientTeam(client, team);
  187.         return true;
  188.     }
  189.    
  190.     int bot = 1;
  191.     //for survivors its more tricky
  192.     for (;
  193.         bot < L4D_MAXCLIENTS_PLUS1 && (!IsClientConnected(bot) || !IsFakeClient(bot) || (GetClientTeam(bot) != L4D_TEAM_SURVIVORS));
  194.         bot++) {}
  195.    
  196.     if(bot == L4D_MAXCLIENTS_PLUS1)
  197.     {
  198.         char command[] = "sb_add";
  199.         int flags = GetCommandFlags(command);
  200.         SetCommandFlags(command, flags & ~FCVAR_CHEAT);
  201.         ServerCommand("sb_add");
  202.         SetCommandFlags(command, flags);
  203.         return false;
  204.     }
  205.    
  206.     //have to do this to give control of a survivor bot
  207.     SDKCall(g_hSHS, bot, client);
  208.     SDKCall(g_hTOB, client, true);
  209.    
  210.     return true;
  211. }
Advertisement
Add Comment
Please, Sign In to add comment