Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TEAM_SPECTATOR 1
- #define TEAM_SURVIVORS 2
- #define TEAM_INFECTED 3
- #define ZOMBIECLASS_SMOKER 1
- #define ZOMBIECLASS_BOOMER 2
- #define ZOMBIECLASS_HUNTER 3
- #define ZOMBIECLASS_SPITTER 4
- #define ZOMBIECLASS_JOCKEY 5
- #define ZOMBIECLASS_CHARGER 6
- #define ZOMBIECLASS_TANK 8
- #define PLUGIN_VERSION "2.3.4"
- #define PLAYERPLUS_VERSION "1.2"
- #define EAVESDROP_VERSION "1.1"
- #define CVAR_SHOW FCVAR_NOTIFY | FCVAR_PLUGIN
- #define MAX_CHAT_LENGTH 1024
- #define CAMPAIGN_ENABLED "Whether or not this campaign shows as a vote-able option in the vote menu."
- #define LOGFILE "addons/sourcemod/logs/teammanager/teammanager.log"
- #define STEAM_ID_LENGTH 64
- #define NICK_NET 0
- #define ROCHELLE_NET 1
- #define COACH_NET 2
- #define ELLIS_NET 3
- #define ZOEY_NET 5
- #define FRANCIS_NET 6
- #define LOUIS_NET 7
- #define NICK_MODEL "models/survivors/survivor_gambler.mdl"
- #define ROCHELLE_MODEL "models/survivors/survivor_producer.mdl"
- #define COACH_MODEL "models/survivors/survivor_coach.mdl"
- #define ELLIS_MODEL "models/survivors/survivor_mechanic.mdl"
- #define ZOEY_MODEL "models/survivors/survivor_teenangst.mdl"
- #define FRANCIS_MODEL "models/survivors/survivor_biker.mdl"
- #define LOUIS_MODEL "models/survivors/survivor_manager.mdl"
- #include <sourcemod>
- #include <sdkhooks>
- #include <sdktools>
- #include <adminmenu>
- #include "left4downtown.inc"
- #include <l4d2_direct>
- #include "gamemode.inc"
- #include "l4d_stocks.inc"
- #include "wrap.inc"
- #include "readyup.inc"
- #include "teammanager/definitions.sp"
- public Plugin:myinfo = {
- name = "Teams Manager",
- author = "Sky",
- description = "steamcommunity.com/groups/skyrpg",
- version = PLUGIN_VERSION,
- url = "skyrpg.donations@gmail.com"
- }
- public OnPluginStart()
- {
- g_SteamgroupCvar = FindConVar("sv_steamgroup");
- SetConVarFlags(g_SteamgroupCvar, GetConVarFlags(g_SteamgroupCvar) & ~FCVAR_NOTIFY);
- g_Module_AFK_Enabled = CreateConVar("teammanager_afk_enabled","1","If enabled, the idle cycle will run, otherwise it won\'t.");
- g_Module_AFK_CycleWarn = CreateConVar("teammanager_afk_cyclewarn","30","How many cycles a player must fail before being warned about being kicked.");
- g_Module_AFK_CycleKick = CreateConVar("teammanager_afk_cyclekick","45","How many cycles a player must fail to be kicked from the server.");
- g_Module_Fly_Enabled = CreateConVar("teammanager_fly_enabled","1","If enabled, infected players will be able to toggle ghost fly with their reload key.");
- g_Module_InfectedRotation_Enabled = CreateConVar("teammanager_infectedrotation_enabled","1","If enabled, infected players will have a new infected class assigned to them when they enter ghost mode.");
- g_Module_InfectedRotation_Random = CreateConVar("teammanager_infectedrotation_random","1","If enabled, the infected class assigned to infected players will be random. If not, it will follow the order: smoker, boomer, hunter, spitter, jockey, charger.");
- g_Module_BlockVote_Enabled = CreateConVar("teammanager_blockvote_enabled","1","If enabled, players will not be able to issue votes outside of the plugin.");
- g_Module_Campaign_Enabled = CreateConVar("teammanager_campaign_enabled","1","If enabled, a new campaign will load when one completes, otherwise it will return players to the lobby.");
- g_Module_Campaign_Rounds = CreateConVar("teammanager_campaign_rounds","2","The number of rounds before the map changes on a qualifying map.");
- g_Module_Campaign_MapchangeDelay = CreateConVar("teammanager_campaign_mapchangedelay","10","The time in seconds before a map changes.");
- g_Module_ReserveSettings_TotalSlots = CreateConVar("teammanager_reservesettings_totalslots","8","The total amount of slots on the server.");
- g_Module_ReserveSettings_ReserveSlots = CreateConVar("teammanager_reservesettings_reserveslots","0","The total amount of reserve slots on the server.");
- g_Module_ReserveSettings_HideReserveSlots = CreateConVar("teammanager_reservesettings_hidereserveslots","1","If enabled, total slots - reserve slots is the value of total slots displayed.");
- g_Module_ReserveSettings_AutomatedSlots = CreateConVar("teammanager_reservesettings_automatedslots","1","If enabled, slots are automated. If disabled, slot settings must be defined in this config.");
- g_Module_ReserveSettings_SurvivorLimit = CreateConVar("teammanager_reservesettings_survivorlimit","4","If automated slots is disabled, the number of survivor slots.");
- g_Module_ReserveSettings_InfectedLimit = CreateConVar("teammanager_reservesettings_infectedlimit","4","If automated slots is disabled, the number of infected slots.");
- g_Module_Teams_MaintainTeams = CreateConVar("teammanager_teams_maintainteams","1","Whether or not to make sure players are always on their appropriate team when a new map loads.");
- g_Module_Teams_Scramble = CreateConVar("teammanager_teams_scramble","400","The point difference that must exist for teams to be scrambled.");
- g_Module_Teams_SmartScramble = CreateConVar("teammanager_teams_smartscramble","1","Smart scramble is based on player rankings, otherwise it\'s completely random.");
- g_Module_Teams_ScrambleRequirement = CreateConVar("teammanager_teams_scramblerequirement","8","The number of players required for a scramble to occur.");
- g_Module_Teams_SpectatorAllowed = CreateConVar("teammanager_teams_spectatorallowed","1","If enabled, anyone can join the spectator team.");
- g_Module_Teams_SpectatorSlots = CreateConVar("teammanager_teams_spectatorslots","1","If enabled, server slots will be automated based on the number of spectators.");
- g_Control_FriendlyFire = CreateConVar("teammanager_control_friendlyfire","0","Whether or not friendly fire deals damage.");
- g_Control_FriendlyFire_PenaltyAmount = CreateConVar("teammanager_control_friendlyfire_penalty","1","The amount of damage a player takes if they shoot a teammate.");
- g_Control_FriendlyFireLimit[0] = CreateConVar("teammanager_friendlyfire_limit_survivor","200","Survivor team friendly fire limit.");
- g_Control_FriendlyFireLimit[1] = CreateConVar("teammanager_friendlyfire_limit_infected","1000","Infected team friendly fire limit.");
- g_Control_FriendlyFireResponse = CreateConVar("teammanager_control_friendlyfire_response","0","If 0, no response is taken. If 1, the player is kicked. If 2, the player is banned.");
- g_Control_FriendlyFireBanTime = CreateConVar("teammanager_control_friendlyfire_bantime","180.0","The amount of time (in minutes) to ban a player for friendly fire, if banning is enabled.");
- g_Module_Configs_Enabled = CreateConVar("teammanager_configs_enabled","0","If enabled, team manager will allow gametypevoting and require a default config file.");
- g_Module_Configs_Voting = CreateConVar("teammanager_configs_voting_enabled","1","If disabled, gametypevote cannot be called, even if configs are enabled.");
- g_Module_Configs_CoopConfig = CreateConVar("teammanager_configs_coopconfig","server_coop.cfg","The config for coop game modes. Changing this in the config will not have any effect.");
- g_Module_Configs_VersusConfig = CreateConVar("teammanager_configs_versusconfig","server_versus.cfg","The config for versus game modes. Changing this in the config will not have any effect.");
- g_Module_Configs_SurvivalConfig = CreateConVar("teammanager_configs_survivalconfig","server_survival.cfg","The config for survival game modes. Changing this in the config will not have any effect.");
- g_Module_Configs_VoteCooldown = CreateConVar("teammanager_configs_votecooldown","900","The amount of time players must wait, in seconds, between gametype votes.");
- g_Module_Configs_VoteTime = CreateConVar("teammanager_configs_votetime","30","The amount of time players can vote, in seconds, for a gametype vote.");
- g_Survivors = CreateConVar("teammanager_survivor_limit","4","Survivor limit.");
- g_Infected = CreateConVar("teammanager_infected_limit","4","Infected limit.");
- g_Debug = CreateConVar("teammanager_debug","0","Whether we run debug mode.");
- g_CheckTeams_PlayerRequirement = CreateConVar("teammanager_checkteams_requirement","4","The amount of players that must be on both teams for player team count check to occur when a player disconnects or changes teams.");
- g_SurvivorBots_KickOnDisconnect = CreateConVar("teammanager_survivorbots_kickondisconnect","0","If enabled, bots are kicked before teams are checked to see if any players need to be team-swapped. Only functions in versus.");
- g_Survivors_BotsRequireHumans = CreateConVar("teammanager_survivorbots_requirehumans","1","Extra survivor bots will only be spawned if there is at least one human player on either survivor or infected.");
- g_Survivors_MinimumRequired = CreateConVar("teammanager_survivorbots_playersrequired","4","If the criteria are met, there must be at least this many survivors, humans and bots combined.");
- g_CoopAllowed = CreateConVar("teammanager_coop_allowed","1","If coop is allowed. This is added since the server seems to crash in coop on the credit screen and not in other game modes.");
- g_SmartScrambleCountdown = CreateConVar("teammanager_smartscramble_countdown","5","How long to notify players before smart team scramble occurs.");
- g_PingRestriction = CreateConVar("teammanager_restriction_ping","300.0","The maximum ping a player can have on the server.");
- g_PackRestriction = CreateConVar("teammanager_restriction_packetloss","30.0","The maximum packet loss a player can have on the server.");
- g_LatencyFailure = CreateConVar("teammanager_restriction_latency_failure","15","The amount of latency failures a player must accrue to be removed from the server. Does not affect players with the admin or reserve flags.");
- HookEvent("player_death", Event_PlayerDeath);
- HookEvent("player_hurt", Event_PlayerHurt);
- HookEvent("infected_death", Event_InfectedDeath);
- HookEvent("player_incapacitated", Event_PlayerIncapacitated);
- HookEvent("choke_stopped", Event_ChokeStopped);
- HookEvent("jockey_ride_end", Event_JockeyRideEnd);
- HookEvent("pounce_stopped", Event_PounceStopped);
- HookEvent("revive_success", Event_ReviveSuccess);
- HookEvent("lunge_pounce", Event_EnsnareBegin);
- HookEvent("jockey_ride", Event_EnsnareBegin);
- HookEvent("tongue_grab", Event_EnsnareBegin);
- HookEvent("tongue_release", Event_EnsnareEnd);
- HookEvent("choke_start", Event_EnsnareBegin);
- HookEvent("tongue_pull_stopped", Event_EnsnareEnd);
- HookEvent("charger_carry_start", Event_EnsnareBegin);
- HookEvent("charger_carry_end", Event_EnsnareEnd);
- HookEvent("charger_pummel_start", Event_EnsnareBegin);
- HookEvent("charger_pummel_end", Event_EnsnareEnd);
- RegConsoleCmd("go_away_from_keyboard", BlockIdle);
- RegConsoleCmd("score", CMD_ShowScoreboard);
- RegConsoleCmd("top10", CMD_Top10Players);
- RegConsoleCmd("ff", CMD_FriendlyFireTotal);
- RegConsoleCmd("team", CMD_Teams);
- RegConsoleCmd("teams", CMD_Teams);
- RegConsoleCmd("callvote", CMD_BlockVotes);
- RegConsoleCmd("vote", CMD_BlockVotes);
- RegConsoleCmd("gametypevote", CMD_GameTypeVote);
- RegConsoleCmd("eavesdrop", CMDEavesdrop);
- RegAdminCmd("teleport", CMDTeleport, ADMFLAG_KICK);
- RegAdminCmd("swap", CMD_SwapPlayer, ADMFLAG_KICK);
- Format(white, sizeof(white), "\x01");
- Format(blue, sizeof(blue), "\x03");
- Format(orange, sizeof(orange), "\x04");
- Format(green, sizeof(green), "\x05");
- Database_OnPluginStart();
- SetAndMaintainSlots();
- LoadTranslations("common.phrases");
- LoadTranslations("teammanager.phrases");
- g_sGameConf = LoadGameConfigFile("skyrpg_v2");
- if (g_sGameConf != INVALID_HANDLE)
- {
- StartPrepSDKCall(SDKCall_Player);
- PrepSDKCall_SetFromConf(g_sGameConf, SDKConf_Signature, "RoundRespawn");
- hRoundRespawn = EndPrepSDKCall();
- StartPrepSDKCall(SDKCall_Player);
- PrepSDKCall_SetFromConf(g_sGameConf, SDKConf_Signature, "SetHumanSpec");
- PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer);
- hSetHumanSpec = EndPrepSDKCall();
- StartPrepSDKCall(SDKCall_Player);
- PrepSDKCall_SetFromConf(g_sGameConf, SDKConf_Signature, "TakeOverBot");
- PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
- hTakeOverBot = EndPrepSDKCall();
- StartPrepSDKCall(SDKCall_Player);
- PrepSDKCall_SetFromConf(g_sGameConf, SDKConf_Signature, "SetClass");
- PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
- g_hSetClass = EndPrepSDKCall();
- StartPrepSDKCall(SDKCall_Static);
- PrepSDKCall_SetFromConf(g_sGameConf, SDKConf_Signature, "CreateAbility");
- PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer);
- PrepSDKCall_SetReturnInfo(SDKType_CBaseEntity, SDKPass_Pointer);
- g_hCreateAbility = EndPrepSDKCall();
- g_oAbility = GameConfGetOffset(g_sGameConf, "oAbility");
- }
- AutoExecConfig(true, "teammanager");
- }
- public Action:BlockIdle(client, args) { return Plugin_Handled; }
- public Action:CMD_ShowScoreboard(client, args)
- {
- if (IsVersus()) SendPanelToClientAndClose(Scoreboard_Menu(client), client, Scoreboard_Menu_Init, MENU_TIME_FOREVER);
- return Plugin_Handled;
- }
- public Action:CMD_Top10Players(client, args)
- {
- SendPanelToClientAndClose(Top10Players(client), client, Top10Players_Init, MENU_TIME_FOREVER);
- return Plugin_Handled;
- }
- public Action:CMD_FriendlyFireTotal(client, args)
- {
- if (GetClientTeam(client) == TEAM_SURVIVORS) PrintToChat(client, "%T", "Friendly Fire Amount", client, white, blue, white, orange, FriendlyFire[client], GetConVarInt(g_Control_FriendlyFireLimit[0]));
- else if (GetClientTeam(client) == TEAM_INFECTED) PrintToChat(client, "%T", "Friendly Fire Amount", client, white, blue, white, orange, FriendlyFire[client], GetConVarInt(g_Control_FriendlyFireLimit[1]));
- return Plugin_Handled;
- }
- public Action:CMD_GameTypeVote(client, args)
- {
- if (GetConVarInt(g_Module_Configs_Enabled) == 0 || GetConVarInt(g_Module_Configs_Voting) == 0 ||
- bRoundOver || (args < 1 && !bIsVoteExisting))
- {
- if (args < 1 && !bIsVoteExisting) PrintToChat(client, "!gametypevote <coop | versus | survival>");
- return Plugin_Handled;
- }
- decl String:GameType[128];
- GetConVarString(FindConVar("mp_gamemode"), GameType, 128);
- decl String:arg1[MAX_NAME_LENGTH];
- GetCmdArg(1, arg1, sizeof(arg1));
- if (StrEqual(GameType, "versus") && StrEqual(arg1, "versus") ||
- StrEqual(GameType, "coop") && StrEqual(arg1, "coop") ||
- StrEqual(GameType, "survival") && StrEqual(arg1, "survival") ||
- (StrEqual(arg1, "coop") && GetConVarInt(g_CoopAllowed) == 0) ||
- (!StrEqual(arg1, "versus") && !StrEqual(arg1, "coop") && !StrEqual(arg1, "survival"))) return Plugin_Handled;
- if (bIsVoteCooldown)
- {
- new seconds = VoteTimeCooldown;
- new minutes = 0;
- while (seconds > 60)
- {
- minutes++;
- seconds -= 60;
- }
- PrintToChat(client, "%T", "Gametype Vote Cooldown", client, white, blue, minutes, seconds, white);
- return Plugin_Handled;
- }
- bIsVoteCooldown = true;
- bIsVoteExisting = true;
- VoteType[client] = 0;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i) && i != client) VoteType[i] = 0;
- }
- decl String:caller[MAX_NAME_LENGTH];
- GetClientName(client, caller, sizeof(caller));
- Format(GameTypeVote, sizeof(GameTypeVote), "%s", arg1);
- PrintToChatAll("%t", "Gametype Vote", white, green, caller, white, green, white, blue, GetConVarInt(g_Module_Configs_VoteTime), white);
- VoteTimeCooldown = GetConVarInt(g_Module_Configs_VoteCooldown);
- VoteTimeRemaining = -1;
- CreateTimer(1.0, Timer_VoteCooldown, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- CreateTimer(1.0, Timer_VoteTime, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- return Plugin_Handled;
- }
- public FirstClientLoaded()
- {
- IsChangingGametype = false;
- CheckLobbyConnection();
- CreateTimer(1.0, Timer_PingValidation, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- }
- stock CheckLobbyConnection()
- {
- decl String:ServerGametype[128];
- GetConVarString(FindConVar("mp_gamemode"), ServerGametype, sizeof(ServerGametype));
- if (!IsGametypeSet) return;
- if (IsGametypeVote)
- {
- // If the gametype and map changed as the result of a vote, we change the CurrentGametype to match it
- // so this function doesn't override the vote.
- GetConVarString(FindConVar("mp_gamemode"), CurrentGametype, sizeof(CurrentGametype));
- LogToFile(LOGFILE, "Locking gametype to %s via vote.", CurrentGametype);
- IsGametypeVote = false;
- return;
- }
- if (!StrEqual(CurrentGametype, ServerGametype))
- {
- LogToFile(LOGFILE, "Gametype doesn't match the config, executing %s", CurrentGametype);
- if (StrEqual(CurrentGametype, "versus")) GetConVarString(g_Module_Configs_VersusConfig, GameTypeVote, sizeof(GameTypeVote));
- else if (StrEqual(CurrentGametype, "coop")) GetConVarString(g_Module_Configs_CoopConfig, GameTypeVote, sizeof(GameTypeVote));
- else GetConVarString(g_Module_Configs_SurvivalConfig, GameTypeVote, sizeof(GameTypeVote));
- ServerCommand("sm_execcfg %s", GameTypeVote);
- if (!StrEqual(CurrentGametype, "survival"))
- {
- ResetCampaignScores();
- ChangeCampaign(true);
- }
- else
- {
- ResetCampaignScores();
- new random = GetRandomInt(1, 22);
- ChangeSurvival(random);
- }
- }
- }
- stock PlayerVoteRequirement()
- {
- new count = 0;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i)) count++;
- }
- count /= 2;
- count++;
- return count;
- }
- stock PlayerVoteFavour()
- {
- new count = 0;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientInGame(i) && !IsFakeClient(i) && VoteType[i] == 2) count++;
- }
- return count;
- }
- stock ResetPlayerVotes()
- {
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientInGame(i) && !IsFakeClient(i)) VoteType[i] = 0;
- }
- }
- public Action:Timer_VoteCooldown(Handle:timer)
- {
- if (bRoundOver) return Plugin_Stop;
- if (VoteTimeCooldown > 0)
- {
- VoteTimeCooldown--;
- }
- if (VoteTimeCooldown < 1)
- {
- VoteTimeCooldown = 0;
- bIsVoteCooldown = false;
- PrintToChatAll("%t", "Gametype Vote Allowed", white, blue);
- return Plugin_Stop;
- }
- return Plugin_Continue;
- }
- public Action:Timer_VoteTime(Handle:timer)
- {
- if (VoteTimeRemaining == -1) VoteTimeRemaining = GetConVarInt(g_Module_Configs_VoteTime);
- VoteTimeRemaining--;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i)) SendPanelToClientAndClose(Gametypevote_panel(i), i, Gametypevote_panel_init, 1);
- }
- if (VoteTimeRemaining > 0 && !bRoundOver) return Plugin_Continue;
- if (PlayerVoteFavour() < PlayerVoteRequirement() || bRoundOver) PrintToChatAll("%t", "Gametype Vote Failed", white, orange);
- else
- {
- ResetPlayerVotes();
- IsGametypeVote = true;
- ChangeGameType(false);
- }
- if (bRoundOver)
- {
- // Vote ended because the round ended, so we don't put a cooldown.
- VoteTimeCooldown = 0;
- }
- return Plugin_Stop;
- }
- public ChangeGameType(bool:StartConfig) //argument is deprecated
- {
- decl String:MapName[128];
- GetCurrentMap(MapName, sizeof(MapName));
- decl String:GameType[128];
- if (!StartConfig)
- {
- if (StrEqual(GameTypeVote, "versus")) GetConVarString(g_Module_Configs_VersusConfig, GameType, sizeof(GameType));
- else if (StrEqual(GameTypeVote, "coop")) GetConVarString(g_Module_Configs_CoopConfig, GameType, sizeof(GameType));
- else if (StrEqual(GameTypeVote, "survival")) GetConVarString(g_Module_Configs_SurvivalConfig, GameType, sizeof(GameType));
- }
- LogToFile(LOGFILE, "Executing Config: %s", GameType);
- ServerCommand("sm_execcfg %s", GameType);
- Format(GameTypeVote, sizeof(GameTypeVote), "%s", GameType);
- IsChangingGametype = true;
- if (!IsGametypeSet)
- {
- CreateTimer(3.0, Timer_SetStartGametype);
- }
- else CreateTimer(2.0, Timer_SlayAll, _, TIMER_FLAG_NO_MAPCHANGE);
- }
- public Action:Timer_SetStartGametype(Handle:timer)
- {
- // This only occurs if it is the servers first boot.
- GetConVarString(FindConVar("mp_gamemode"), CurrentGametype, sizeof(CurrentGametype));
- LogToFile(LOGFILE, "Server first boot. Gametype locked at %s", CurrentGametype);
- IsGametypeSet = true;
- if (!StrEqual(CurrentGametype, "survival"))
- {
- ResetCampaignScores();
- ChangeCampaign(true);
- }
- else
- {
- ResetCampaignScores();
- new random = GetRandomInt(1, 22);
- ChangeSurvival(random);
- }
- return Plugin_Stop;
- }
- public Action:Timer_SlayAll(Handle:timer)
- {
- ServerCommand("sm_slay @all");
- return Plugin_Stop;
- }
- public Action:CMDTeleport(client, args)
- {
- if (args < 1)
- {
- PrintToChat(client, "!teleport <player>");
- return;
- }
- decl String:arg1[MAX_NAME_LENGTH];
- GetCmdArg(1, arg1, sizeof(arg1));
- if (!StrEqual(arg1, "all", false))
- {
- decl String:target_name[MAX_NAME_LENGTH];
- decl target_list[MAXPLAYERS + 1], target_count, bool:tn_is_ml;
- new name;
- new i = 0;
- if ((target_count = ProcessTargetString(
- arg1,
- client,
- target_list,
- MAXPLAYERS,
- COMMAND_FILTER_CONNECTED,
- target_name,
- sizeof(target_name),
- tn_is_ml)) > 0)
- {
- for (i = 0; i < target_count; i++) { name = target_list[i]; }
- }
- new survivorsalive = 0;
- for (new j = 1; j <= MaxClients; j++)
- {
- if (!IsClientInGame(j) || IsFakeClient(j) || !IsPlayerAlive(j) || GetClientTeam(j) != 2 || j == name) continue;
- survivorsalive++;
- }
- if (survivorsalive < 1)
- {
- PrintToChat(client, "No survivors found, cannot teleport player.");
- return;
- }
- new survivorfound = 0;
- while (survivorfound == 0)
- {
- i = GetRandomInt(1, MaxClients);
- if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2 && i != name)
- {
- new Float:teleport[3];
- GetClientAbsOrigin(i, teleport);
- TeleportEntity(name, Float:teleport, NULL_VECTOR, NULL_VECTOR);
- survivorfound = 1;
- PrintToChatAll("%N teleported %N to %N.", client, name, i);
- }
- }
- }
- else
- {
- if (IsPlayerAlive(client))
- {
- // teleport all human survivors to the players location.
- new Float:SurvivorLocation[3];
- GetClientAbsOrigin(client, SurvivorLocation);
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i) && IsPlayerAlive(i) && GetClientTeam(i) == TEAM_SURVIVORS && i != client)
- {
- TeleportEntity(i, Float:SurvivorLocation, NULL_VECTOR, NULL_VECTOR);
- }
- }
- }
- }
- }
- /*stock CheckLoadAttemptEveryone()
- {
- for (new client = 1; client <= MaxClients; client++)
- {
- if (IsClientHuman(client) && !bLoadAttempted[client])
- {
- bLoadAttempted[client] = true;
- LoadPlayerData(client);
- }
- }
- }*/
- public Action:CMD_Teams(client, args)
- {
- if (!bLoadAttempted[client])
- {
- bLoadAttempted[client] = true;
- LoadPlayerData(client);
- }
- GetClientRank(client);
- SendPanelToClientAndClose(TeamManagerMenu(client), client, TeamManagerMenu_Init, MENU_TIME_FOREVER);
- return Plugin_Handled;
- }
- public Action:CMD_BlockVotes(client, args)
- {
- if (GetConVarInt(g_Module_BlockVote_Enabled) == 1) return Plugin_Handled;
- else return Plugin_Continue;
- }
- public OnConfigsExecuted()
- {
- AutoExecConfig(true, "teammanager");
- // will make modules optional at some point
- CreateConVar("teammanager_version", PLUGIN_VERSION, "The current version release of the plugin.", CVAR_SHOW);
- SetConVarString(FindConVar("teammanager_version"), PLUGIN_VERSION);
- CreateConVar("teammanager_playerplus_version", PLAYERPLUS_VERSION, "The current version of player plus module.", CVAR_SHOW);
- SetConVarString(FindConVar("teammanager_playerplus_version"), PLAYERPLUS_VERSION);
- CreateConVar("teammanager_eavesdrop_version", EAVESDROP_VERSION, "The current version of eavesdrop module.", CVAR_SHOW);
- SetConVarString(FindConVar("teammanager_eavesdrop_version"), EAVESDROP_VERSION);
- SetAndMaintainSlots();
- SetConVarFlags(g_SteamgroupCvar, GetConVarFlags(g_SteamgroupCvar) & ~FCVAR_NOTIFY);
- }
- public AllClientsLoaded()
- {
- bTransition = false;
- Format(MapPath, sizeof(MapPath), "none");
- if (IsFirstMap() || !IsVersus()) ResetCampaignScores();
- roundCounter = 0;
- if (IsVersus())
- {
- new ScoreDifference = TeamDifference();
- if (!bFirstMapOfCampaign())
- {
- if (GetConVarInt(g_Debug) == 1) LogToFile(LOGFILE, "Score Difference: %d", ScoreDifference);
- if (ScoreDifference <= GetConVarInt(g_Module_Teams_Scramble) || LastScramble < 2) TeamAssignmentCheck(true);
- else if (GetConVarInt(g_Module_Teams_SmartScramble) == 1) Scramble(true);
- else if (GetConVarInt(g_Module_Teams_SmartScramble) == 0) Scramble(false);
- }
- else
- {
- if (GetConVarInt(g_Module_Teams_SmartScramble) == 1) Scramble(true);
- else if (GetConVarInt(g_Module_Teams_SmartScramble) == 0) Scramble(false);
- }
- }
- else
- {
- // Not versus, make sure they're survivor.
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientHuman(i) || GetClientTeam(i) == TEAM_SURVIVORS || bAway[i]) continue;
- JoinTargetTeam(i, TEAM_SURVIVORS);
- }
- }
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientHuman(i)) continue;
- //bLoadAttempted[i] = false;
- bFlyCooldown[i] = false;
- Fly[i] = false;
- }
- //SurvivorCheck();
- KickSurvivorBots();
- }
- stock TeamDifference()
- {
- new ScoreDifference = 0;
- if (L4D2Direct_GetVSCampaignScore(0) > L4D2Direct_GetVSCampaignScore(1))
- {
- ScoreDifference = L4D2Direct_GetVSCampaignScore(0) - L4D2Direct_GetVSCampaignScore(1);
- }
- else
- {
- ScoreDifference = L4D2Direct_GetVSCampaignScore(1) - L4D2Direct_GetVSCampaignScore(0);
- }
- return ScoreDifference;
- }
- stock bool:bFirstMapOfCampaign()
- {
- decl String:MapName[128];
- GetCurrentMap(MapName, sizeof(MapName));
- if (StrContains(MapName, "c1m1", true) > -1 ||
- StrContains(MapName, "c2m1", true) > -1 ||
- StrContains(MapName, "c3m1", true) > -1 ||
- StrContains(MapName, "c4m1", true) > -1 ||
- StrContains(MapName, "c5m1", true) > -1 ||
- StrContains(MapName, "c6m1", true) > -1 ||
- StrContains(MapName, "c7m1", true) > -1 ||
- StrContains(MapName, "c8m1", true) > -1 ||
- StrContains(MapName, "c9m1", true) > -1 ||
- StrContains(MapName, "c10m1", true) > -1 ||
- StrContains(MapName, "c11m1", true) > -1 ||
- StrContains(MapName, "c12m1", true) > -1 ||
- StrContains(MapName, "c13m1", true) > -1 ||
- StrContains(MapName, "zero01", true) > -1) return true;
- return false;
- }
- public ReadyUpEnd()
- {
- decl String:GameTypeCurrent2[128];
- GetConVarString(FindConVar("mp_gamemode"), GameTypeCurrent2, 128);
- if (!StrEqual(GameTypeCurrent2, "survival")) SetMapPath();
- else ServerCommand("sm_forcepath easy");
- if (GetConVarInt(g_Module_Campaign_Enabled) == 0) return;
- //bTransition = false;
- bRoundOver = false;
- CreateTimer(1.0, Timer_AFK_CycleTime, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- bIsVoteCooldown = true;
- bIsVoteExisting = false;
- CreateTimer(1.0, Timer_VoteCooldown, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- //SurvivorCheck();
- KickSurvivorBots();
- }
- public CoopMapFailed()
- {
- roundCounter--;
- SaveAllPlayers();
- }
- public SetMapPath()
- {
- if (StrEqual(MapPath, "none"))
- {
- new random = GetRandomInt(1,3);
- if (random == 1) Format(MapPath, sizeof(MapPath), "easy");
- else if (random == 2) Format(MapPath, sizeof(MapPath), "medium");
- else Format(MapPath, sizeof(MapPath), "hard");
- }
- ServerCommand("sm_forcepath %s", MapPath);
- }
- stock HumanSurvivorCount()
- {
- new count = 0;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i) && GetClientTeam(i) == TEAM_SURVIVORS) count++;
- }
- return count;
- }
- public CheckTeams(client)
- {
- if (!IsVersus()) return;
- new survivors = 0;
- new infected = 0;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i) && (client == 0 || client != i))
- {
- if (GetClientTeam(i) == TEAM_SURVIVORS) survivors++;
- else if (GetClientTeam(i) == TEAM_INFECTED) infected++;
- }
- }
- if (infected < GetConVarInt(g_CheckTeams_PlayerRequirement) || survivors < GetConVarInt(g_CheckTeams_PlayerRequirement)) return;
- if (infected > survivors + 1) RandomAssignment(TEAM_INFECTED, TEAM_SURVIVORS);
- else if (survivors > infected + 1) RandomAssignment(TEAM_SURVIVORS, TEAM_INFECTED);
- }
- public RandomAssignment(TargetTeam, DestinationTeam)
- {
- new String:Name[MAX_NAME_LENGTH];
- new i = 0;
- while (i < 1)
- {
- new client = GetRandomInt(1, MaxClients);
- i = GetClientOfUserId(client);
- if (IsClientHuman(i) && GetClientTeam(i) == TargetTeam)
- {
- if (DestinationTeam == TEAM_INFECTED)
- {
- JoinTargetTeam(i, TEAM_INFECTED);
- GetClientName(i, Name, sizeof(Name));
- PrintToChatAll("%t", "Player Forced Infected Team", white, orange, white, Name);
- }
- else if (DestinationTeam == TEAM_SURVIVORS)
- {
- JoinTargetTeam(i, TEAM_SURVIVORS);
- GetClientName(i, Name, sizeof(Name));
- PrintToChatAll("%t", "Player Forced Survivor Team", white, blue, white, Name);
- CreateTimer(1.0, Timer_RespawnOnSurvivorForce, i, TIMER_FLAG_NO_MAPCHANGE);
- }
- }
- else i = 0;
- }
- // Check the teams again, just in case the teams are so imbalanced that they need more players moved.
- //CheckTeams(0);
- }
- public Action:Timer_RespawnOnSurvivorForce(Handle:timer, any:client)
- {
- if (bRoundOver) return Plugin_Stop;
- if (IsClientHuman(client) && GetClientTeam(client) == TEAM_SURVIVORS)
- {
- if (IsPlayerAlive(client))
- {
- if (TeleportSurvivor(client)) return Plugin_Stop;
- else
- {
- LogToFile(LOGFILE, "No survivor to teleport respawned player on automatic team switch.");
- return Plugin_Stop;
- }
- }
- else SDKCall(hRoundRespawn, client);
- }
- return Plugin_Continue;
- }
- public TeleportSurvivor(client)
- {
- new Float:Origin[3];
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i) && GetClientTeam(i) == TEAM_SURVIVORS && IsPlayerAlive(i) && i != client)
- {
- GetClientAbsOrigin(i, Origin);
- TeleportEntity(client, Origin, NULL_VECTOR, NULL_VECTOR);
- return true;
- }
- }
- return false;
- }
- stock bool:RespawnHumans()
- {
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i) && GetClientTeam(i) == TEAM_SURVIVORS && !IsPlayerAlive(i)) SDKCall(hRoundRespawn, i);
- }
- }
- stock bool:bAnyHumansAlive()
- {
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i) && GetClientTeam(i) == TEAM_SURVIVORS && IsPlayerAlive(i)) return true;
- }
- return false;
- }
- public CampaignComplete()
- {
- CheckForCampaignChange();
- }
- public RoundTimeRecorder(NewRound)
- {
- if (NewRound) StartTime = GetTime();
- else
- {
- StartTime = GetTime() - StartTime;
- new Hours = 0;
- new Minutes = 0;
- new Seconds = 0;
- while (StartTime > 3600)
- {
- Hours++;
- StartTime -= 3600;
- }
- while (StartTime > 60)
- {
- Minutes++;
- StartTime -= 60;
- }
- Seconds = StartTime;
- PrintToChatAll("%t", "Round Length", white, blue, white, blue, white, blue, white, Hours, Minutes, Seconds);
- }
- }
- /*stock LoadAllPlayersData()
- {
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i)) LoadPlayerData(i);
- }
- }*/
- public CheckpointDoorStartOpened()
- {
- bTransition = false; // used for coop if the map fails and it isn't a finale.
- //LoadAllPlayersData();
- GetTop10();
- RoundTimeRecorder(true);
- if (!bAnyHumansAlive()) RespawnHumans();
- DisableAllEavesdropValues();
- }
- public Action:Timer_ForceScoreboard(Handle:timer)
- {
- if (!bForceScoreboard) return Plugin_Stop;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i)) SendPanelToClientAndClose(Scoreboard_Menu(i), i, Scoreboard_Menu_Init, 1);
- }
- return Plugin_Continue;
- }
- public ReadyUpStart()
- {
- bForceScoreboard = false;
- }
- public OnMapStart()
- {
- bRoundOver = true;
- IsSurvivorCheck = false;
- PrecacheModel(NICK_MODEL);
- PrecacheModel(ROCHELLE_MODEL);
- PrecacheModel(COACH_MODEL);
- PrecacheModel(ELLIS_MODEL);
- PrecacheModel(ZOEY_MODEL);
- PrecacheModel(FRANCIS_MODEL);
- PrecacheModel(LOUIS_MODEL);
- }
- public RoundIsOver()
- {
- if (!IsChangingGametype)
- {
- if (IsVersus())
- {
- CalculateSurvivorScore();
- CreateTimer(1.0, Timer_ForceScoreboard, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- }
- RoundTimeRecorder(false);
- bRoundOver = true;
- bForceScoreboard = true;
- roundCounter++;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientHuman(i)) continue;
- bCFF[i] = false;
- EavesdropAll[i] = false;
- FriendlyFire[i] = 0;
- bFlyCooldown[i] = false;
- Fly[i] = false;
- if (GetClientTeam(i) == TEAM_SURVIVORS) SurvivorRoundsPlayed[i]++;
- else if (GetClientTeam(i) == TEAM_INFECTED) InfectedRoundsPlayed[i]++;
- }
- DisableAllEavesdropValues();
- if (roundCounter >= GetConVarInt(g_Module_Campaign_Rounds))
- {
- mapcounter++;
- bTransition = true;
- if (IsVersus()) TeamAssignmentCheck(false);
- CheckForCampaignChange();
- CheckForSurvivalChange();
- }
- else if (roundCounter < GetConVarInt(g_Module_Campaign_Rounds) && !IsCoop())
- {
- SaveAllPlayers();
- }
- }
- else
- {
- IsChangingGametype = false;
- OfficiateGametype();
- }
- }
- stock OfficiateGametype()
- {
- if (!StrEqual(GameTypeVote, "survival"))
- {
- ResetCampaignScores();
- ChangeCampaign(true);
- }
- else
- {
- ResetCampaignScores();
- new random = GetRandomInt(1, 22);
- ChangeSurvival(random);
- }
- }
- stock SaveAllPlayers()
- {
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientHuman(i)) SavePlayerData(i);
- }
- }
- public GetTeamPlayers(team)
- {
- new count = 0;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientHuman(i) || GetClientTeam(i) != team) continue;
- count++;
- }
- return count;
- }
- bool:IsRoot(client)
- {
- if (IsClientHuman(client))
- {
- decl flags;
- flags = GetUserFlagBits(client);
- if (!(flags & ADMFLAG_ROOT)) return false;
- return true;
- }
- else return false;
- }
- bool:IsReserve(client)
- {
- if (IsClientHuman(client))
- {
- decl flags;
- flags = GetUserFlagBits(client);
- if (!(flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)) return false;
- return true;
- }
- else return false;
- }
- stock bool:IsAdmin(client)
- {
- if (IsClientHuman(client))
- {
- decl flags;
- flags = GetUserFlagBits(client);
- if (!(flags & ADMFLAG_ROOT || flags & ADMFLAG_GENERIC)) return false;
- return true;
- }
- else return false;
- }
- stock bool:IsIncapacitated(client)
- {
- return bool:GetEntProp(client, Prop_Send, "m_isIncapacitated");
- }
- stock SendPanelToClientAndClose(Handle:panel, client, MenuHandler:handler, time)
- {
- SendPanelToClient(panel, client, handler, time);
- CloseHandle(panel);
- }
- public GetCampaignScore(team)
- {
- new score = 0;
- for (new i = 0; i <= mapcounter; i++)
- {
- if (MapScores[i][team] < 0) MapScores[i][team] *= -1;
- if (MapScores[i][team] > 400) MapScores[i][team] = 400;
- score += MapScores[i][team];
- }
- return score;
- }
- public CalculateSurvivorScore()
- {
- new Float:FlowPercent = GetSurvivorTeamDistance();
- FlowPercent *= 400.0;
- new bFlipped = GameRules_GetProp("m_bAreTeamsFlipped");
- MapScores[mapcounter][bFlipped] += RoundToFloor(FlowPercent);
- new String:text[512];
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientHuman(i)) continue;
- if (!bFlipped) Format(text, sizeof(text), "%T", "Score Map Total", i, blue, white, green, orange, white, green, white, blue, white, white, orange, white, MapScores[mapcounter][0], MapScores[mapcounter][1], GetCampaignScore(0), GetCampaignScore(1));
- else Format(text, sizeof(text), "%T", "Score Map Total", i, blue, white, green, orange, white, green, white, blue, white, white, orange, white, MapScores[mapcounter][1], MapScores[mapcounter][0], GetCampaignScore(1), GetCampaignScore(0));
- PrintToChat(i, text);
- }
- }
- public Float:GetSurvivorTeamDistance()
- {
- new Float:value = 0.0;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientHuman(i) || GetClientTeam(i) != TEAM_SURVIVORS) continue;
- value += (L4D2Direct_GetFlowDistance(i) / L4D2Direct_GetMapMaxFlowDistance());
- }
- value /= HumanSurvivorCount();
- return value;
- }
- stock FindZombieClass(client)
- {
- return GetEntProp(client, Prop_Send, "m_zombieClass");
- }
- #include "teammanager/database.sp"
- #include "teammanager/login.sp"
- #include "teammanager/afk.sp"
- #include "teammanager/rotation.sp"
- #include "teammanager/fly.sp"
- #include "teammanager/reserve.sp"
- #include "teammanager/campaign.sp"
- #include "teammanager/teams.sp"
- #include "teammanager/scramble.sp"
- #include "teammanager/events.sp"
- #include "teammanager/eavesdrop.sp"
- #include "teammanager/ping.sp"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement