2017-02-04 23:31:50 +01:00
# include <sourcemod>
# include <cstrike>
# pragma semicolon 1
# pragma newdecls required
# define MIN_PLAYERS 2
2017-08-18 22:24:22 +02:00
int g_iWarmup = 0 ;
2017-02-04 23:31:50 +01:00
bool g_bWarmup = false ;
ConVar g_CVar_sm_warmuptime ;
ConVar g_CVar_sm_warmupratio ;
bool g_bRoundEnded = false ;
bool g_bZombieSpawned = false ;
int g_TeamChangeQueue [ MAXPLAYERS + 1 ] = { - 1 , . . . } ;
public Plugin myinfo =
{
name = " TeamManager " ,
author = " BotoX " ,
description = " " ,
version = " 1.0 " ,
url = " https://github.com/CSSZombieEscape/sm-plugins/tree/master/TeamManager "
} ;
public void OnPluginStart ( )
{
AddCommandListener ( OnJoinTeamCommand , " jointeam " ) ;
2017-08-18 16:03:27 +02:00
AddCommandListener ( OnJoinTeamCommand , " joingame " ) ;
2017-02-04 23:31:50 +01:00
HookEvent ( " round_start " , OnRoundStart , EventHookMode_Pre ) ;
HookEvent ( " round_end " , OnRoundEnd , EventHookMode_PostNoCopy ) ;
g_CVar_sm_warmuptime = CreateConVar ( " sm_warmuptime " , " 10 " , " Warmup timer. " , 0 , true , 0.0 , true , 60.0 ) ;
g_CVar_sm_warmupratio = CreateConVar ( " sm_warmupratio " , " 0.60 " , " Ratio of connected players that need to be in game to start warmup timer. " , 0 , true , 0.0 , true , 1.0 ) ;
AutoExecConfig ( true , " plugin.TeamManager " ) ;
}
public void OnMapStart ( )
{
2017-08-18 22:24:22 +02:00
g_iWarmup = 0 ;
2017-02-04 23:31:50 +01:00
g_bWarmup = false ;
2017-08-18 22:24:22 +02:00
g_bRoundEnded = false ;
g_bZombieSpawned = false ;
2017-02-04 23:31:50 +01:00
if ( g_CVar_sm_warmuptime . IntValue > 0 | | g_CVar_sm_warmupratio . FloatValue > 0.0 )
{
g_bWarmup = true ;
CreateTimer ( 1.0 , OnWarmupTimer , 0 , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE ) ;
}
}
public Action OnWarmupTimer ( Handle timer )
{
if ( g_CVar_sm_warmupratio . FloatValue > 0.0 )
{
int ClientsConnected = GetClientCount ( false ) ;
int ClientsInGame = GetClientCount ( true ) ;
int ClientsNeeded = RoundToCeil ( float ( ClientsConnected ) * g_CVar_sm_warmupratio . FloatValue ) ;
ClientsNeeded = ClientsNeeded > MIN_PLAYERS ? ClientsNeeded : MIN_PLAYERS ;
if ( ClientsInGame < ClientsNeeded )
{
2017-08-18 22:24:22 +02:00
g_iWarmup = 0 ;
2017-02-04 23:31:50 +01:00
PrintCenterTextAll ( " Warmup: Waiting for %d more players to join. " , ClientsNeeded - ClientsInGame ) ;
return Plugin_Continue ;
}
}
2017-08-18 22:24:22 +02:00
if ( g_iWarmup > = g_CVar_sm_warmuptime . IntValue )
2017-02-04 23:31:50 +01:00
{
2017-08-18 22:24:22 +02:00
g_iWarmup = 0 ;
2017-02-04 23:31:50 +01:00
g_bWarmup = false ;
CS_TerminateRound ( 3.0 , CSRoundEnd_GameStart , false ) ;
return Plugin_Stop ;
}
2017-08-18 22:24:22 +02:00
PrintCenterTextAll ( " Warmup: %d " , g_CVar_sm_warmuptime . IntValue - g_iWarmup ) ;
g_iWarmup + + ;
2017-02-04 23:31:50 +01:00
return Plugin_Continue ;
}
2017-04-19 19:59:59 +02:00
public void OnClientDisconnect ( int client )
2017-02-04 23:31:50 +01:00
{
g_TeamChangeQueue [ client ] = - 1 ;
}
public Action OnJoinTeamCommand ( int client , const char [ ] command , int argc )
{
if ( client < 1 | | client > = MaxClients | | ! IsClientInGame ( client ) )
return Plugin_Continue ;
char sArg [ 8 ] ;
GetCmdArg ( 1 , sArg , sizeof ( sArg ) ) ;
int CurrentTeam = GetClientTeam ( client ) ;
int NewTeam = StringToInt ( sArg ) ;
if ( NewTeam < CS_TEAM_NONE | | NewTeam > CS_TEAM_CT )
return Plugin_Handled ;
if ( g_bRoundEnded )
{
if ( NewTeam = = CS_TEAM_T | | NewTeam = = CS_TEAM_NONE )
NewTeam = CS_TEAM_CT ;
if ( NewTeam = = CurrentTeam )
{
if ( g_TeamChangeQueue [ client ] ! = - 1 )
{
g_TeamChangeQueue [ client ] = - 1 ;
PrintCenterText ( client , " Team change request canceled. " ) ;
}
return Plugin_Handled ;
}
g_TeamChangeQueue [ client ] = NewTeam ;
PrintCenterText ( client , " You will be placed in the selected team shortly. " ) ;
return Plugin_Handled ;
}
if ( ! g_bZombieSpawned )
{
if ( NewTeam = = CS_TEAM_T | | NewTeam = = CS_TEAM_NONE )
NewTeam = CS_TEAM_CT ;
}
2017-04-19 19:59:59 +02:00
else if ( NewTeam = = CS_TEAM_CT | | NewTeam = = CS_TEAM_NONE )
2017-02-04 23:31:50 +01:00
NewTeam = CS_TEAM_T ;
if ( NewTeam = = CurrentTeam )
return Plugin_Handled ;
ChangeClientTeam ( client , NewTeam ) ;
return Plugin_Handled ;
}
public void OnRoundStart ( Event event , const char [ ] name , bool dontBroadcast )
{
g_bRoundEnded = false ;
g_bZombieSpawned = false ;
for ( int client = 1 ; client < = MaxClients ; client + + )
{
if ( ! IsClientInGame ( client ) )
continue ;
int CurrentTeam = GetClientTeam ( client ) ;
int NewTeam = CS_TEAM_CT ;
if ( g_TeamChangeQueue [ client ] ! = - 1 )
{
NewTeam = g_TeamChangeQueue [ client ] ;
g_TeamChangeQueue [ client ] = - 1 ;
}
else if ( CurrentTeam < = CS_TEAM_SPECTATOR )
continue ;
if ( NewTeam = = CurrentTeam )
continue ;
if ( NewTeam > = CS_TEAM_T )
CS_SwitchTeam ( client , NewTeam ) ;
else
ChangeClientTeam ( client , NewTeam ) ;
if ( NewTeam > = CS_TEAM_T & & ! IsPlayerAlive ( client ) )
CS_RespawnPlayer ( client ) ;
}
}
public void OnRoundEnd ( Event event , const char [ ] name , bool dontBroadcast )
{
g_bRoundEnded = true ;
g_bZombieSpawned = false ;
}
public Action CS_OnTerminateRound ( float & delay , CSRoundEndReason & reason )
{
if ( g_bWarmup )
return Plugin_Handled ;
return Plugin_Continue ;
}
public Action ZR_OnClientInfect ( int & client , int & attacker , bool & motherInfect , bool & respawnOverride , bool & respawn )
{
if ( g_bWarmup )
return Plugin_Handled ;
2017-04-19 19:59:59 +02:00
g_bZombieSpawned = true ;
2017-02-04 23:31:50 +01:00
return Plugin_Continue ;
}