Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #define PLUGIN_VERSION "1.2"
- #define PLUGIN_NAME "[L4D(2)] AFK and Join Team Commands (ZMBR)"
- #define L4D_MAXCLIENTS MaxClients
- #define L4D_MAXCLIENTS_PLUS1 (L4D_MAXCLIENTS + 1)
- #define L4D_TEAM_SURVIVORS 2
- #define L4D_TEAM_INFECTED 3
- #define L4D_TEAM_SPECTATE 1
- Handle g_hTimer = null;
- Handle g_hConf = null;
- Handle g_hSHS = null;
- Handle g_hTOB = null;
- public Plugin:myinfo =
- {
- name = PLUGIN_NAME,
- author = "MasterMe, modified by SHARIVAN from ZMBR clan",
- description = "Adds commands to let the player spectate and join team. (!afk, !survivors, !infected, etc.)",
- version = PLUGIN_VERSION,
- url = "http://forums.alliedmods.net/showthread.php?t=122476"
- };
- public void OnPluginStart()
- {
- CreateConVar("afk_spectate_commands_zmbr_version", PLUGIN_VERSION, "Plugin version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
- RegConsoleCmd("sm_survivors", AFKTurnClientToSurvivors);
- RegConsoleCmd("sm_joinsurvivors", AFKTurnClientToSurvivors);
- RegConsoleCmd("sm_jointeam2", AFKTurnClientToSurvivors);
- RegConsoleCmd("sm_infected", AFKTurnClientToInfected);
- RegConsoleCmd("sm_joininfected", AFKTurnClientToInfected);
- RegConsoleCmd("sm_jointeam3", AFKTurnClientToInfected);
- g_hConf = LoadGameConfigFile("l4dunscrambler");
- if (g_hConf == null)
- {
- SetFailState("Game config file l4dunscrambler not found.");
- return;
- }
- StartPrepSDKCall(SDKCall_Player);
- PrepSDKCall_SetFromConf(g_hConf, SDKConf_Signature, "SetHumanSpec");
- PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer);
- g_hSHS = EndPrepSDKCall();
- StartPrepSDKCall(SDKCall_Player);
- PrepSDKCall_SetFromConf(g_hConf, SDKConf_Signature, "TakeOverBot");
- PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
- g_hTOB = EndPrepSDKCall();
- g_hTimer = CreateTimer(60.0, OnTimer, _, TIMER_REPEAT);
- }
- public void OnPluginEnd()
- {
- KillTimer(g_hTimer);
- }
- public Action OnTimer(Handle hTimer)
- {
- for (int client = 1; client <= MaxClients; client++)
- {
- if (!Client_IsIngame(client) || IsFakeClient(client))
- continue;
- int team = GetClientTeam(client);
- if (team == L4D_TEAM_SPECTATE)
- {
- PrintToChat(client, "Voce esta SPEC pois os times sao limitados 10vs10.");
- PrintToChat(client, "Assim que liberar uma vaga, digite !infected ou !survivor.");
- }
- }
- }
- public Action AFKTurnClientToSurvivors(int client, int args)
- {
- int team = GetClientTeam(client);
- if (team == L4D_TEAM_SPECTATE)
- ChangePlayerTeam(client, L4D_TEAM_SURVIVORS);
- else
- PrintToChat(client, "Este comando e liberado somente pra quem esta SPEC.");
- return Plugin_Handled;
- }
- public Action AFKTurnClientToInfected(int client, int args)
- {
- int team = GetClientTeam(client);
- if (team == L4D_TEAM_SPECTATE)
- ChangePlayerTeam(client, L4D_TEAM_INFECTED);
- else
- PrintToChat(client, "Este comando e liberado somente pra quem esta SPEC.");
- return Plugin_Handled;
- }
- /**
- * Checks if the specified index is a player and connected.
- *
- * @param entity An entity index.
- * @param checkConnected Set to false to skip the IsClientConnected check
- * @return Returns true if the specified entity index is a player connected, false otherwise.
- */
- stock bool Client_IsValid(int client, bool checkConnected=true)
- {
- if (client > 4096)
- client = EntRefToEntIndex(client);
- if (client < 1 || client > MaxClients)
- return false;
- if (checkConnected && !IsClientConnected(client))
- return false;
- return true;
- }
- /**
- * Checks if the specified index is a player and ingame.
- *
- * @param entity An entity index.
- * @return Returns true if the specified index is a player and ingame, false otherwise.
- */
- stock bool Client_IsIngame(int client)
- {
- if (!Client_IsValid(client, false))
- return false;
- return IsClientInGame(client);
- }
- stock int GetTeamMaxHumans(int team)
- {
- if (team == L4D_TEAM_SURVIVORS)
- return GetConVarInt(FindConVar("survivor_limit"));
- if (team == L4D_TEAM_INFECTED)
- return GetConVarInt(FindConVar("z_max_player_zombies"));
- if (team == L4D_TEAM_SPECTATE)
- return L4D_MAXCLIENTS;
- return -1;
- }
- stock bool IsClientInGameHuman(int client)
- {
- if (client > 0)
- return IsClientInGame(client) && !IsFakeClient(client);
- return false;
- }
- stock int GetTeamHumanCount(int team)
- {
- int humans = 0;
- for(int i = 1; i < L4D_MAXCLIENTS_PLUS1; i++)
- {
- if (IsClientInGameHuman(i) && GetClientTeam(i) == team)
- humans++;
- }
- return humans;
- }
- stock bool ChangePlayerTeam(int client, int team)
- {
- if (GetClientTeam(client) == team)
- return true;
- int maxHumans = GetTeamMaxHumans(team);
- if (GetTeamHumanCount(team) >= maxHumans)
- {
- PrintToChat(client, "O time está cheio. Permitido só %d jogadores", maxHumans);
- return false;
- }
- if (team != L4D_TEAM_SURVIVORS)
- {
- //we can always swap to infected or spectator, it has no actual limit
- ChangeClientTeam(client, team);
- return true;
- }
- int bot = 1;
- //for survivors its more tricky
- for (;
- bot < L4D_MAXCLIENTS_PLUS1 && (!IsClientConnected(bot) || !IsFakeClient(bot) || (GetClientTeam(bot) != L4D_TEAM_SURVIVORS));
- bot++) {}
- if(bot == L4D_MAXCLIENTS_PLUS1)
- {
- char command[] = "sb_add";
- int flags = GetCommandFlags(command);
- SetCommandFlags(command, flags & ~FCVAR_CHEAT);
- ServerCommand("sb_add");
- SetCommandFlags(command, flags);
- return false;
- }
- //have to do this to give control of a survivor bot
- SDKCall(g_hSHS, bot, client);
- SDKCall(g_hTOB, client, true);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment