Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #define DEBUG
- #define PLUGIN_AUTHOR "Diam0ndzx"
- #define PLUGIN_VERSION "1.0"
- #include <sourcemod>
- #include <sdktools>
- #include <cstrike>
- #pragma newdecls required
- EngineVersion g_Game;
- #define PREFIX " \x01 [\x0CDeathrun\x01]\x07"
- ConVar autoHopping;
- int currentTRound = 0;
- bool isFreerun = false;
- public Plugin myinfo =
- {
- name = "Deathrun",
- author = PLUGIN_AUTHOR,
- description = "The base Deathrun plugin",
- version = PLUGIN_VERSION,
- url = "https://steamcommunity.com/id/Diam0ndz/"
- };
- public void OnPluginStart()
- {
- g_Game = GetEngineVersion();
- if(g_Game != Engine_CSGO && g_Game != Engine_CSS)
- {
- SetFailState("This plugin is for CSGO/CSS only.");
- }
- autoHopping = FindConVar("sv_autobunnyhopping");
- autoHopping.IntValue = 1;
- AddCommandListener(Command_JoinTeam, "jointeam");
- HookEvent("round_poststart", OnRoundPostStart);
- HookEvent("round_end", OnRoundEnd);
- RegConsoleCmd("sm_freerun", Command_Freerun, "If you are a T, calls a freerun.");
- }
- public void OnMapStart()
- {
- CreateTimer(90.0, Timer_CheckTPlayers, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); //Create timer that checks every 90 seconds to force player on T if there isn't already
- }
- public Action OnRoundPostStart(Event event, const char[] name, bool dontBroadcast)
- {
- if(GetTeamClientCount(CS_TEAM_T) >= 1)
- {
- currentTRound++;
- }else
- {
- PrintToChatAll("%s \x07 There are currently no Terrorists!", PREFIX);
- }
- }
- public Action OnRoundEnd(Event event, const char[] name, bool dontBroadcast)
- {
- if(GetTeamClientCount(CS_TEAM_T) >= 1)
- {
- if(currentTRound >= 3)
- {
- for (int i = 1; i <= MaxClients; i++)
- {
- if(IsValidClient(i) && GetClientTeam(i) == CS_TEAM_T)
- {
- int randomPlayer = GetRandomPlayerFromTeam(CS_TEAM_CT);
- CS_SwitchTeam(randomPlayer, CS_TEAM_T);
- ChangeTeam(i, CS_TEAM_CT);
- currentTRound = 0;
- char currentT[] = "";
- GetClientName(i, currentT, sizeof(currentT));
- char goingToBeT[] = "";
- GetClientName(i, goingToBeT, sizeof(goingToBeT));
- PrintToChatAll("%s \x07 Rotating %s out for %s.", PREFIX, currentT, goingToBeT);
- }
- }
- }
- }else
- {
- PrintToChatAll("%s \x07 There are currently no Terrorists!", PREFIX);
- }
- isFreerun = false;
- BalanceTeams();
- }
- public Action Timer_CheckTPlayers(Handle timer)
- {
- if(GetClientCount() >= 3) //Check if there are at least 3 players
- {
- if(GetTeamClientCount(CS_TEAM_T) < 1) //Check if there is no one on T
- {
- CS_SwitchTeam(GetRandomPlayerFromTeam(CS_TEAM_CT), CS_TEAM_T); //Switch a random player on CT to T
- CS_TerminateRound(0.5, CSRoundEnd_Draw, true);
- PrintToChatAll("%s \x07 Force switching a random player to T!", PREFIX);
- }else
- {
- PrintToServer("%s \x07 There is already a player on T!", PREFIX);
- }
- }else
- {
- PrintToServer("%s \x07 There aren't at least three players", PREFIX);
- }
- }
- public Action Command_Freerun(int client, int args)
- {
- if(GetClientTeam(client) != CS_TEAM_T)
- {
- PrintToChat(client, "%s \x07 You must be a T in order to call a freerun!", PREFIX);
- return Plugin_Handled;
- }
- if(isFreerun)
- {
- PrintToChat(client, "%s \x07 There is already a freerun.", PREFIX);
- return Plugin_Handled;
- }
- isFreerun = true;
- return Plugin_Handled;
- }
- public Action Command_JoinTeam(int client, const char[] command, int argc)
- {
- if(IsValidClient(client))
- {
- if(GetClientTeam(client) == CS_TEAM_T)
- {
- PrintToChat(client, "%s \x07 Switching off of T is forbidden!", PREFIX);
- return Plugin_Stop;
- }
- }
- return Plugin_Continue;
- }
- public void BalanceTeams()
- {
- if(GetClientCount(true) < 15)
- {
- if(GetPlayerTeamCount(CS_TEAM_T) > 1)
- {
- for (int i = 1; i <= MaxClients - 1; i++)
- {
- ChangeTeam(i, CS_TEAM_CT);
- }
- PrintToChatAll("%s \x07 Teams have been balanced!", PREFIX);
- }
- }else if(GetClientCount(true) >= 15)
- {
- if(GetPlayerTeamCount(CS_TEAM_T) > 2)
- {
- for (int i = 1; i <= MaxClients - 2; i++)
- {
- ChangeTeam(i, CS_TEAM_CT);
- }
- PrintToChatAll("%s \x07 Teams have been balanced!", PREFIX);
- }
- }
- }
- public void ChangeTeam(int client, int team)
- {
- if(GetClientTeam(client) == team)
- {
- PrintToChat(client, "%s \x07 Can't switch player to a team they are already on!", PREFIX);
- }
- CS_SwitchTeam(client, team);
- }
- stock int GetRandomPlayerFromTeam(int team) //Get a random player from a specific team
- {
- int[] clients = new int[MaxClients + 1];
- int clientCount;
- for (int i = 1; i <= MaxClients; i++)
- if (IsClientInGame(i) && (GetClientTeam(i) == team))
- clients[clientCount++] = i;
- return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount - 1)];
- }
- stock int GetPlayerTeamCount(int team)
- {
- int players = 0;
- for (int i = 1; i <= MaxClients; i++)
- {
- if(GetClientTeam(i) == team)
- players++;
- }
- return players;
- }
- stock bool IsValidClient(int client)
- {
- if(client <= 0 ) return false;
- if(client > MaxClients) return false;
- if(!IsClientConnected(client)) return false;
- return IsClientInGame(client);
- }
- public int HandleFreerunMenu(Menu menu, MenuAction action, int param1, int param2)
- {
- switch(action)
- {
- case MenuAction_Select:
- {
- char info[32];
- menu.GetItem(param2, info, sizeof(info));
- if(StrEqual(info, "yes"))
- {
- for (int i = 1; i <= 5; i++)
- {
- PrintToChatAll("%s \x07 Freerun Activated!", PREFIX);
- }
- isFreerun = true;
- }
- else
- {
- PrintToChat(param1, "%s \x07 Freerun confirmation canceled.", PREFIX);
- isFreerun = false;
- }
- }
- }
- }
- public Action Menu_Freerun(int client, int args)
- {
- Menu freerunMenu = new Menu(HandleFreerunMenu, MENU_ACTIONS_DEFAULT);
- freerunMenu.SetTitle("Freerun?");
- freerunMenu.AddItem("yes", "Yes");
- freerunMenu.AddItem("no", "No");
- freerunMenu.ExitButton = false;
- freerunMenu.Display(client, 20);
- return Plugin_Handled;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement