Try this
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
int g_iWins = 0;
const int g_iRound = 5;
public Plugin myinfo =
{
name = "Swap Teams",
author = "Cruze",
description = "Swap Teams if T wins X number of rounds consecutively.",
version = "1.0",
url = "www.github.com/cruze03"
}
public void OnPluginStart()
{
HookEvent("round_end", Event_RoundEnd);
HookUserMessage(GetUserMessageId("TextMsg"), Hook_TextMsg);
}
public void OnMapStart()
{
g_iWins = 0;
}
public Action Hook_TextMsg(UserMsg umId, Handle hMsg, const int[] iPlayers, int iPlayersNum, bool bReliable, bool bInit)
{
char name[40], szValue[40];
PbReadString(hMsg, "params", szValue, sizeof(szValue), 1);
PbReadString(hMsg, "params", name, sizeof(name), 0);
if(strcmp(name, "#SFUI_Notice_Game_will_restart_in", false) == 0)
{
CreateTimer(StringToFloat(szValue), Timer_GameRestarted);
}
return Plugin_Continue;
}
public Action Timer_GameRestarted(Handle timer)
{
g_iWins = 0;
}
public void Event_RoundEnd(Event ev, const char[] name, bool dbc)
{
int winner = ev.GetInt("winner");
if(winner == 2)
{
g_iWins++;
}
else if(winner == 3)
{
g_iWins = 0;
}
if(g_iWins >= g_iRound)
{
SwapTeams();
g_iWins = 0;
}
}
void SwapTeams()
{
int client, team;
for(client = 1; client <= MaxClients; client++)
{
if(!IsClientInGame(client))
{
continue;
}
team = GetClientTeam(client);
if(team == 2)
{
CS_SwitchTeam(client, 3);
}
else if(team == 3)
{
CS_SwitchTeam(client, 2);
}
}
PrintToChatAll("[SM] Terrorists have won %i rounds consecutively. Swapping teams.", g_iRound);
}
__________________