2019-01-05 18:54:14 +01:00
# include <cstrike>
2019-06-02 23:21:17 +02:00
# include <hlstatsx_loghelper>
2019-01-05 18:54:14 +01:00
# include <sourcemod>
# include <zombiereloaded>
# pragma semicolon 1
# pragma newdecls required
/* CONVARS */
ConVar g_cvarStreakInterval = null ;
ConVar g_cvarMinimumStreak = null ;
ConVar g_cvarMaximumStreak = null ;
ConVar g_cvarDifficultyHuman = null ;
ConVar g_cvarDifficultyZombie = null ;
ConVar g_cvarDifficultyDuration = null ;
/* HANDLES */
Handle g_tMinimalRoundDuration = INVALID_HANDLE ;
/* INTERGERS */
int g_iKillCount [ MAXPLAYERS + 1 ] = 0 ;
/* BOOLEANS */
bool g_bIsHuman [ MAXPLAYERS + 1 ] = false ;
bool g_bIsZombie [ MAXPLAYERS + 1 ] = false ;
bool g_bMotherZM [ MAXPLAYERS + 1 ] = false ;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = " HLstatsX CE - Zombie Escape " ,
author = " zaCade " ,
description = " Create additional actions for the default HLstatsX " ,
version = " 1.0.0 "
} ;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart ( )
{
g_cvarStreakInterval = CreateConVar ( " hlx_ze_killstreaks_interval " , " 1 " , " amount of kills required to progress to the next killstreak " , 0 , true , 1.0 ) ;
g_cvarMinimumStreak = CreateConVar ( " hlx_ze_killstreaks_minimal " , " 2 " , " amount of kills required for the lowest killstreak " , 0 , true , 0.0 ) ;
g_cvarMaximumStreak = CreateConVar ( " hlx_ze_killstreaks_maximal " , " 12 " , " amount of kills required for the highest killstreak " , 0 , true , 0.0 ) ;
g_cvarDifficultyHuman = CreateConVar ( " hlx_ze_difficulty_human " , " 0 " , " the difficulty level of the current map for humans " , 0 , true , 0.0 ) ;
g_cvarDifficultyZombie = CreateConVar ( " hlx_ze_difficulty_zombie " , " 0 " , " the difficulty level of the current map for zombies " , 0 , true , 0.0 ) ;
g_cvarDifficultyDuration = CreateConVar ( " hlx_ze_difficulty_duration " , " 60 " , " the minumum amount of time a round has to last in seconds " , 0 , true , 0.0 , true , 180.0 ) ;
HookEvent ( " round_start " , OnRoundStarting , EventHookMode_Pre ) ;
HookEvent ( " round_end " , OnRoundEnding , EventHookMode_Pre ) ;
HookEvent ( " player_spawn " , OnClientSpawn , EventHookMode_Pre ) ;
HookEvent ( " player_death " , OnClientDeath , EventHookMode_Pre ) ;
for ( int client = 1 ; client < = MaxClients ; client + + )
{
if ( IsValidClient ( client ) )
{
g_bIsHuman [ client ] = ZR_IsClientHuman ( client ) ;
g_bIsZombie [ client ] = ZR_IsClientZombie ( client ) ;
}
}
AutoExecConfig ( ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapEnd ( )
{
if ( g_tMinimalRoundDuration ! = INVALID_HANDLE & & CloseHandle ( g_tMinimalRoundDuration ) )
g_tMinimalRoundDuration = INVALID_HANDLE ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnRoundStarting ( Event hEvent , const char [ ] sEvent , bool bDontBroadcast )
{
if ( g_tMinimalRoundDuration ! = INVALID_HANDLE & & CloseHandle ( g_tMinimalRoundDuration ) )
g_tMinimalRoundDuration = INVALID_HANDLE ;
g_tMinimalRoundDuration = CreateTimer ( g_cvarDifficultyDuration . FloatValue , OnRoundMinimalDuration ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnRoundMinimalDuration ( Handle timer )
{
g_tMinimalRoundDuration = INVALID_HANDLE ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ZR_OnClientHumanPost ( int client , bool respawn , bool protect )
{
g_bIsHuman [ client ] = true ;
g_bIsZombie [ client ] = false ;
g_bMotherZM [ client ] = false ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ZR_OnClientInfected ( int client , int attacker , bool motherInfect , bool respawnOverride , bool respawn )
{
g_bIsHuman [ client ] = false ;
g_bIsZombie [ client ] = true ;
g_bMotherZM [ client ] = motherInfect ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnRoundEnding ( Event hEvent , const char [ ] sEvent , bool bDontBroadcast )
{
bool bAwardHumans = ( ( g_tMinimalRoundDuration = = INVALID_HANDLE ) & & ( hEvent . GetInt ( " winner " ) = = CS_TEAM_CT ) ) ;
bool bAwardZombies = ( ( g_tMinimalRoundDuration = = INVALID_HANDLE ) & & ( hEvent . GetInt ( " winner " ) = = CS_TEAM_T ) ) ;
2019-04-10 20:24:38 +02:00
int iAliveHumans ;
2019-05-28 21:02:07 +02:00
int iAliveZombies ;
2019-04-10 20:24:38 +02:00
for ( int client = 1 ; client < = MaxClients ; client + + )
{
if ( IsValidClient ( client ) & & GetClientTeam ( client ) = = CS_TEAM_CT )
2019-05-28 21:02:07 +02:00
{
2019-04-10 20:24:38 +02:00
iAliveHumans + + ;
2019-05-28 21:02:07 +02:00
}
else if ( IsValidClient ( client ) & & GetClientTeam ( client ) = = CS_TEAM_T )
{
iAliveZombies + + ;
}
2019-04-10 20:24:38 +02:00
}
2019-01-05 18:54:14 +01:00
for ( int client = 1 ; client < = MaxClients ; client + + )
{
if ( IsValidClient ( client ) )
{
2019-04-10 20:24:38 +02:00
if ( bAwardHumans & & g_bIsHuman [ client ] )
2019-01-05 18:54:14 +01:00
{
2019-04-10 20:24:38 +02:00
if ( iAliveHumans = = 1 )
{
2019-06-02 23:21:17 +02:00
LH_LogPlayerEvent ( client , " triggered " , " ze_h_win_solo " , true ) ;
2019-04-10 20:24:38 +02:00
}
else
{
char sPlayerEvent [ 32 ] ;
Format ( sPlayerEvent , sizeof ( sPlayerEvent ) , " ze_h_win_%d " , g_cvarDifficultyHuman . IntValue ) ;
2019-01-05 18:54:14 +01:00
2019-06-02 23:21:17 +02:00
LH_LogPlayerEvent ( client , " triggered " , sPlayerEvent , true ) ;
2019-04-10 20:24:38 +02:00
}
2019-01-05 18:54:14 +01:00
}
else if ( bAwardZombies & & g_bIsZombie [ client ] )
{
2019-05-28 21:02:07 +02:00
if ( iAliveZombies = = 1 )
{
2019-06-02 23:21:17 +02:00
LH_LogPlayerEvent ( client , " triggered " , " ze_z_win_solo " , true ) ;
2019-05-28 21:02:07 +02:00
}
else if ( g_bMotherZM [ client ] )
2019-01-05 18:54:14 +01:00
{
char sPlayerEvent [ 32 ] ;
Format ( sPlayerEvent , sizeof ( sPlayerEvent ) , " ze_m_win_%d " , g_cvarDifficultyZombie . IntValue ) ;
2019-06-02 23:21:17 +02:00
LH_LogPlayerEvent ( client , " triggered " , sPlayerEvent , true ) ;
2019-01-05 18:54:14 +01:00
}
else
{
char sPlayerEvent [ 32 ] ;
Format ( sPlayerEvent , sizeof ( sPlayerEvent ) , " ze_z_win_%d " , g_cvarDifficultyZombie . IntValue ) ;
2019-06-03 01:53:58 +02:00
LH_LogPlayerEvent ( client , " triggered " , sPlayerEvent , true ) ;
2019-01-05 18:54:14 +01:00
}
}
EndKillStreak ( client ) ;
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientSpawn ( Event hEvent , const char [ ] sEvent , bool bDontBroadcast )
{
int client = GetClientOfUserId ( hEvent . GetInt ( " userid " ) ) ;
ResetClient ( client ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientDeath ( Event hEvent , const char [ ] sEvent , bool bDontBroadcast )
{
int client = GetClientOfUserId ( hEvent . GetInt ( " userid " ) ) ;
int killer = GetClientOfUserId ( hEvent . GetInt ( " attacker " ) ) ;
EndKillStreak ( client ) ;
if ( IsValidClient ( killer ) )
{
g_iKillCount [ killer ] + = 1 ;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void EndKillStreak ( int client )
{
if ( g_iKillCount [ client ] > = g_cvarMinimumStreak . IntValue )
{
if ( g_iKillCount [ client ] > g_cvarMaximumStreak . IntValue )
g_iKillCount [ client ] = g_cvarMaximumStreak . IntValue ;
if ( g_bIsHuman [ client ] )
{
char sPlayerEvent [ 32 ] ;
Format ( sPlayerEvent , sizeof ( sPlayerEvent ) , " ze_h_kill_streak_%d " , RoundToFloor ( float ( g_iKillCount [ client ] ) / float ( g_cvarStreakInterval . IntValue ) ) * g_cvarStreakInterval . IntValue ) ;
2019-06-02 23:21:17 +02:00
LH_LogPlayerEvent ( client , " triggered " , sPlayerEvent , true ) ;
2019-01-05 18:54:14 +01:00
}
else if ( g_bIsZombie [ client ] )
{
if ( g_bMotherZM [ client ] )
{
char sPlayerEvent [ 32 ] ;
Format ( sPlayerEvent , sizeof ( sPlayerEvent ) , " ze_m_kill_streak_%d " , RoundToFloor ( float ( g_iKillCount [ client ] ) / float ( g_cvarStreakInterval . IntValue ) ) * g_cvarStreakInterval . IntValue ) ;
2019-06-02 23:21:17 +02:00
LH_LogPlayerEvent ( client , " triggered " , sPlayerEvent , true ) ;
2019-01-05 18:54:14 +01:00
}
else
{
char sPlayerEvent [ 32 ] ;
Format ( sPlayerEvent , sizeof ( sPlayerEvent ) , " ze_z_kill_streak_%d " , RoundToFloor ( float ( g_iKillCount [ client ] ) / float ( g_cvarStreakInterval . IntValue ) ) * g_cvarStreakInterval . IntValue ) ;
2019-06-02 23:21:17 +02:00
LH_LogPlayerEvent ( client , " triggered " , sPlayerEvent , true ) ;
2019-01-05 18:54:14 +01:00
}
}
}
ResetClient ( client ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock void ResetClient ( int client )
{
g_bIsHuman [ client ] = true ;
g_bIsZombie [ client ] = false ;
g_bMotherZM [ client ] = false ;
g_iKillCount [ client ] = 0 ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock bool IsValidClient ( int client )
{
return ( client > 0 & & client < = MaxClients & & IsClientInGame ( client ) & & IsPlayerAlive ( client ) ) ;
}