2019-06-10 17:13:55 +02:00
# pragma semicolon 1
# include <sourcemod>
# include <cstrike>
# include <multicolors>
# include <zombiereloaded>
2019-09-20 14:01:14 +02:00
# include <AFKManager>
2020-08-05 17:49:59 +02:00
# include <clientprefs>
2019-11-23 14:25:04 +01:00
# tryinclude <entWatch_core>
2019-06-10 17:13:55 +02:00
bool g_bTestRound ;
bool g_bAdminTestRound ;
bool g_bMotherZM [ MAXPLAYERS + 1 ] = { false , . . . } ;
2020-08-08 21:56:59 +02:00
/ * bool g_bZHP [ MAXPLAYERS + 1 ] = { false , . . . } ;
Handle g_hCookieZHP = null ; * /
2020-08-05 17:49:59 +02:00
int g_iZHPMax [ MAXPLAYERS + 1 ] ;
int g_iZShield [ MAXPLAYERS + 1 ] ;
2020-08-05 18:29:35 +02:00
bool g_bShield ;
2020-08-05 17:49:59 +02:00
2019-11-23 14:25:04 +01:00
bool g_Plugin_entWatch ;
2019-09-20 13:59:27 +02:00
int g_iAFKTime ;
2019-06-10 17:13:55 +02:00
public Plugin myinfo =
{
name = " Zombie Manager " ,
author = " Dogan " ,
description = " Tools to manage testround and zombies " ,
2020-08-05 17:49:59 +02:00
version = " 2.0.0 " ,
2019-06-10 17:13:55 +02:00
url = " "
} ;
public void OnPluginStart ( )
{
g_bTestRound = false ;
g_bAdminTestRound = false ;
2019-09-20 13:59:27 +02:00
2019-06-10 17:13:55 +02:00
RegAdminCmd ( " sm_testround " , Command_Testround , ADMFLAG_GENERIC , " Toggle to enable/disable a test round. " ) ;
2020-08-06 16:55:34 +02:00
RegAdminCmd ( " sm_shield " , Command_ZShield , ADMFLAG_GENERIC , " Toggle to enable/disable zombie shield. " ) ;
2019-06-10 17:13:55 +02:00
CreateTimer ( 20.0 , Timer_MessageTestRound , _ , TIMER_REPEAT ) ;
2020-08-06 23:56:06 +02:00
CreateTimer ( 5.0 , Timer_UpdateHintMessage , _ , TIMER_REPEAT ) ;
2020-08-05 17:49:59 +02:00
CreateTimer ( 0.2 , Timer_HandleHPShield , _ , TIMER_REPEAT ) ; // health_regen_interval = 0.2
2019-06-10 17:13:55 +02:00
HookEvent ( " round_start " , OnRoundStart ) ;
HookEvent ( " player_spawn " , OnClientSpawn ) ;
2020-08-05 17:49:59 +02:00
HookEvent ( " player_hurt " , OnPlayerHurt ) ;
2019-09-20 13:59:27 +02:00
ConVar cvar ;
2019-10-13 21:41:41 +02:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_player_afk_time " , " 120 " , " AFK Time in seconds after which a player won't turn into a motherzombie " ) ) , Cvar_AFKTime ) ;
2019-09-20 13:59:27 +02:00
g_iAFKTime = cvar . IntValue ;
2020-08-06 02:59:14 +02:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_zombieshield " , " 1 " , " 1 = Zombie Shield activated, 0 = Zombie Shield deactivated " , FCVAR_NONE , true , 0.0 , true , 1.0 ) ) , Cvar_ZombieShield ) ;
2020-08-05 18:29:35 +02:00
g_bShield = cvar . BoolValue ;
2019-09-20 13:59:27 +02:00
delete cvar ;
2020-08-08 21:56:59 +02:00
/ * RegConsoleCmd ( " sm_zhp " , OnToggleZHP , " Toggle blocking Zombie HP and Shield display " ) ;
2020-08-05 17:49:59 +02:00
g_hCookieZHP = RegClientCookie ( " zhp_blocked " , " are zombie hp and shield display blocked " , CookieAccess_Protected ) ;
2020-08-08 21:56:59 +02:00
SetCookieMenuItem ( MenuHandler_CookieMenu , 0 , " Zombie HP Shield Display " ) ; * /
2020-08-05 17:49:59 +02:00
2019-10-13 21:41:41 +02:00
AutoExecConfig ( true , " plugin.ZombieManager " ) ;
2019-06-10 17:13:55 +02:00
AddMultiTargetFilter ( " @mzombie " , Filter_Motherzombies , " Mother Zombies " , false ) ;
RegConsoleCmd ( " sm_mzombie " , Command_DisplayMotherzombies , " Current Mother Zombies " ) ;
2019-10-29 13:37:19 +01:00
RegConsoleCmd ( " sm_mzombies " , Command_DisplayMotherzombies , " Current Mother Zombies " ) ;
2019-06-10 17:13:55 +02:00
}
2019-11-23 14:25:04 +01:00
public void OnAllPluginsLoaded ( )
{
g_Plugin_entWatch = LibraryExists ( " entWatch-core " ) ;
}
public void OnLibraryAdded ( const char [ ] name )
{
if ( StrEqual ( name , " entWatch-core " ) )
g_Plugin_entWatch = true ;
}
public void OnLibraryRemoved ( const char [ ] name )
{
if ( StrEqual ( name , " entWatch-core " ) )
g_Plugin_entWatch = false ;
}
2019-06-10 17:13:55 +02:00
public void OnPluginEnd ( )
{
RemoveMultiTargetFilter ( " @mzombie " , Filter_Motherzombies ) ;
}
2020-08-06 16:55:34 +02:00
public void OnMapStart ( )
{
g_bShield = GetConVarBool ( FindConVar ( " sm_zombieshield " ) ) ;
}
2020-08-08 21:56:59 +02:00
/ * public Action OnToggleZHP ( int client , int args )
2020-08-05 17:49:59 +02:00
{
ToggleZHP ( client ) ;
return Plugin_Handled ;
}
public void ToggleZHP ( int client )
{
g_bZHP [ client ] = ! g_bZHP [ client ] ;
SetClientCookie ( client , g_hCookieZHP , g_bZHP [ client ] ? " 1 " : " " ) ;
2020-08-06 16:55:34 +02:00
CPrintToChat ( client , " {green}[ZR] {yellow}%s " , g_bZHP [ client ] ? " Zombie HP and Shield display disabled. " : " Zombie HP and Shield display enabled. " ) ;
2020-08-08 21:56:59 +02:00
} * /
2020-08-05 17:49:59 +02:00
2020-08-08 21:56:59 +02:00
/ * public void OnClientCookiesCached ( int client )
2020-08-05 17:49:59 +02:00
{
char sBuffer [ 2 ] ;
GetClientCookie ( client , g_hCookieZHP , sBuffer , sizeof ( sBuffer ) ) ;
if ( sBuffer [ 0 ] ! = '\0' )
g_bZHP [ client ] = true ;
else
g_bZHP [ client ] = false ;
2020-08-08 21:56:59 +02:00
} * /
2020-08-05 17:49:59 +02:00
public void OnClientDisconnect ( int client )
{
2020-08-08 21:56:59 +02:00
//g_bZHP[client] = false;
2020-08-05 17:49:59 +02:00
g_iZHPMax [ client ] = 0 ;
g_iZShield [ client ] = 0 ;
2020-08-13 00:00:04 +02:00
g_bMotherZM [ client ] = false ;
2020-08-05 17:49:59 +02:00
}
2020-08-08 21:56:59 +02:00
/ * public void ShowSettingsMenu ( int client )
2020-08-05 17:49:59 +02:00
{
Menu menu = new Menu ( MenuHandler_MainMenu ) ;
menu . SetTitle ( " Zombie HP Shield Display Settings " , client ) ;
char sBuffer [ 128 ] ;
Format ( sBuffer , sizeof ( sBuffer ) , " Zombie HP and Shield Display: %s " , g_bZHP [ client ] ? " Disabled " : " Enabled " ) ;
menu . AddItem ( " 0 " , sBuffer ) ;
menu . ExitBackButton = true ;
menu . Display ( client , MENU_TIME_FOREVER ) ;
}
public void MenuHandler_CookieMenu ( int client , CookieMenuAction action , any info , char [ ] buffer , int maxlen )
{
switch ( action )
{
case ( CookieMenuAction_DisplayOption ) :
{
Format ( buffer , maxlen , " Zombie HP Shield Display " , client ) ;
}
case ( CookieMenuAction_SelectOption ) :
{
ShowSettingsMenu ( client ) ;
}
}
}
public int MenuHandler_MainMenu ( Menu menu , MenuAction action , int client , int selection )
{
switch ( action )
{
case ( MenuAction_Select ) :
{
switch ( selection )
{
case ( 0 ) : ToggleZHP ( client ) ;
}
ShowSettingsMenu ( client ) ;
}
case ( MenuAction_Cancel ) :
{
ShowCookieMenu ( client ) ;
}
case ( MenuAction_End ) :
{
delete menu ;
}
}
2020-08-08 21:56:59 +02:00
} * /
2020-08-05 17:49:59 +02:00
2019-09-20 13:59:27 +02:00
public void Cvar_AFKTime ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
{
g_iAFKTime = convar . IntValue ;
}
2020-08-05 18:29:35 +02:00
public void Cvar_ZombieShield ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
{
g_bShield = convar . BoolValue ;
}
2019-06-10 17:13:55 +02:00
public void OnRoundStart ( Event hEvent , const char [ ] sName , bool bDontBroadcast )
{
g_bTestRound = false ;
g_bAdminTestRound = false ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
g_bMotherZM [ i ] = false ;
2020-08-05 17:49:59 +02:00
g_iZHPMax [ i ] = 0 ;
g_iZShield [ i ] = 0 ;
2019-06-10 17:13:55 +02:00
}
}
2019-07-24 10:10:38 +02:00
public Action ZR_OnClientInfect ( int & client , int & attacker , bool & motherInfect , bool & respawnOverride , bool & respawn )
{
2019-10-04 14:39:42 +02:00
if ( g_bTestRound )
return Plugin_Handled ;
return Plugin_Continue ;
}
public Action ZR_OnClientMotherZombieEligible ( int client )
{
2019-11-23 14:25:04 +01:00
bool bHasItem ;
# if defined entWatch_core_included
if ( g_Plugin_entWatch )
bHasItem = EW_ClientHasItem ( client ) ;
# endif
2019-07-24 10:10:38 +02:00
2020-05-24 14:12:33 +02:00
char sAuthID [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ; //autism bot
if ( GetClientIdleTime ( client ) > g_iAFKTime | | IsFakeClient ( client ) | | bHasItem | | StrEqual ( sAuthID , " STEAM_0:1:60189040 " ) )
2019-11-23 14:25:04 +01:00
return Plugin_Handled ;
2020-05-24 14:12:33 +02:00
return Plugin_Continue ;
2019-07-24 10:10:38 +02:00
}
2019-06-10 17:13:55 +02:00
public void ZR_OnClientInfected ( int client , int attacker , bool motherInfect , bool respawnOverride , bool respawn )
{
2020-08-05 17:49:59 +02:00
g_iZHPMax [ client ] = GetClientHealth ( client ) ;
2020-08-07 19:30:56 +02:00
if ( g_bMotherZM [ client ] ) //Motherzombies that die and respawn
{
g_bMotherZM [ client ] = true ;
return ;
}
g_bMotherZM [ client ] = motherInfect ;
2019-06-10 17:13:55 +02:00
}
2019-07-24 10:10:38 +02:00
public Action ZR_OnInfectCountdown ( )
{
if ( g_bTestRound )
return Plugin_Handled ;
return Plugin_Continue ;
}
2019-06-10 17:13:55 +02:00
public void OnClientSpawn ( Event hEvent , const char [ ] sName , bool bDontBroadcast )
{
int client = GetClientOfUserId ( hEvent . GetInt ( " userid " ) ) ;
2020-08-05 17:49:59 +02:00
g_iZShield [ client ] = 0 ;
2019-06-10 17:13:55 +02:00
}
2020-08-05 17:49:59 +02:00
public Action OnPlayerHurt ( Event event , const char [ ] name , bool dontBroadcast )
{
int client = GetClientOfUserId ( GetEventInt ( event , " userid " ) ) ;
2020-08-06 02:59:14 +02:00
int attacker = GetClientOfUserId ( GetEventInt ( event , " attacker " ) ) ;
2020-08-05 17:49:59 +02:00
int damage = GetEventInt ( event , " dmg_health " ) ;
2020-08-06 04:35:25 +02:00
if ( ! IsClientInGame ( client ) | | ! IsPlayerAlive ( client ) | | ! ZR_IsClientZombie ( client ) )
2020-08-05 17:49:59 +02:00
return Plugin_Continue ;
2020-08-06 02:59:14 +02:00
if ( g_iZShield [ client ] > 0 & & attacker ! = 0 )
2020-08-05 17:49:59 +02:00
{
g_iZShield [ client ] = g_iZShield [ client ] - damage ;
SetEntityHealth ( client , g_iZHPMax [ client ] ) ;
}
return Plugin_Continue ;
}
2019-06-10 17:13:55 +02:00
public bool Filter_Motherzombies ( const char [ ] sPattern , Handle hClients , int client )
{
for ( int i = 1 ; i < = MaxClients ; i + + )
{
2020-08-08 21:56:59 +02:00
if ( IsClientInGame ( i ) & & ! IsFakeClient ( i ) & & GetClientTeam ( i ) = = CS_TEAM_T )
2019-06-10 17:13:55 +02:00
{
if ( g_bMotherZM [ i ] )
PushArrayCell ( hClients , i ) ;
}
}
return true ;
}
public Action Command_DisplayMotherzombies ( int client , int args )
{
2020-08-08 18:58:25 +02:00
if ( client = = 0 )
{
ReplyToCommand ( client , " [SM] Cannot use this from console. " ) ;
return Plugin_Handled ;
}
2019-06-10 17:13:55 +02:00
char aBuf [ 1024 ] ;
char aBuf2 [ MAX_NAME_LENGTH ] ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
2020-08-08 21:56:59 +02:00
if ( IsClientInGame ( i ) & & ! IsFakeClient ( i ) & & GetClientTeam ( i ) = = CS_TEAM_T )
2019-06-10 17:13:55 +02:00
{
if ( g_bMotherZM [ i ] )
{
GetClientName ( i , aBuf2 , sizeof ( aBuf2 ) ) ;
StrCat ( aBuf , sizeof ( aBuf ) , aBuf2 ) ;
StrCat ( aBuf , sizeof ( aBuf ) , " , " ) ;
}
}
}
if ( strlen ( aBuf ) )
{
aBuf [ strlen ( aBuf ) - 2 ] = 0 ;
ReplyToCommand ( client , " [SM] Current Mother Zombies: %s " , aBuf ) ;
}
else
ReplyToCommand ( client , " [SM] Current Mother Zombies: none " ) ;
return Plugin_Handled ;
}
public Action Command_Testround ( int client , int args )
{
2019-07-24 10:10:38 +02:00
/ * if ( GetClientTeam ( client ) = = CS_TEAM_SPECTATOR )
2019-06-10 17:59:23 +02:00
{
ReplyToCommand ( client , " [SM] Please join a Team first. " ) ;
return Plugin_Handled ;
}
if ( ! IsPlayerAlive ( client ) )
{
ReplyToCommand ( client , " [SM] Please respawn yourself first. " ) ;
return Plugin_Handled ;
2019-07-24 10:10:38 +02:00
} * /
2019-06-10 17:59:23 +02:00
2019-06-10 17:13:55 +02:00
ToggleTestRound ( client ) ;
return Plugin_Handled ;
}
2020-08-06 16:55:34 +02:00
public Action Command_ZShield ( int client , int args )
{
char sNemesis [ 32 ] ;
GetConVarString ( FindConVar ( " sm_info_message_file " ) , sNemesis , sizeof ( sNemesis ) ) ;
bool bNemesis = StrEqual ( sNemesis , " nemesis " ) ;
if ( bNemesis )
{
ReplyToCommand ( client , " [SM] Can't modify zombie shields on nemesis maps! " ) ;
return Plugin_Handled ;
}
if ( g_bShield )
{
g_bShield = false ;
ReplyToCommand ( client , " [SM] Deactivated zombie shields. " ) ;
CPrintToChatAll ( " [SM] %N deactivated zombie shields! " , client ) ;
LogAction ( client , - 1 , " \" %L \" deactivated zombie shields. " , client ) ;
}
else
{
g_bShield = true ;
ReplyToCommand ( client , " [SM] Activated zombie shields. " ) ;
CPrintToChatAll ( " [SM] %N activated zombie shields! " , client ) ;
LogAction ( client , - 1 , " \" %L \" activated zombie shields. " , client ) ;
}
return Plugin_Handled ;
}
2019-06-10 17:13:55 +02:00
public void ToggleTestRound ( int client )
{
g_bAdminTestRound = ! g_bAdminTestRound ;
if ( g_bTestRound )
{
g_bTestRound = false ;
ReplyToCommand ( client , " [SM] Deactivated this Test Round. " ) ;
CPrintToChatAll ( " [SM] %N deactivated this Test Round! " , client ) ;
LogAction ( client , - 1 , " \" %L \" deactivated this Test Round. " , client ) ;
}
else
{
g_bTestRound = true ;
ReplyToCommand ( client , " [SM] Activated a Test Round. " ) ;
CPrintToChatAll ( " [SM] %N activated a Test Round! " , client ) ;
LogAction ( client , - 1 , " \" %L \" activated a Test Round. " , client ) ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
2020-07-23 03:34:27 +02:00
if ( IsClientInGame ( i ) & & IsPlayerAlive ( i ) & & ZR_IsClientZombie ( i ) )
2019-06-10 17:13:55 +02:00
{
ZR_HumanClient ( i , false , false ) ;
}
}
}
}
2019-07-24 10:10:38 +02:00
public Action CS_OnTerminateRound ( float & delay , CSRoundEndReason & reason )
{
if ( g_bTestRound )
return Plugin_Handled ;
return Plugin_Continue ;
}
2019-06-10 17:13:55 +02:00
public Action ZR_OnClientRespawn ( int & client , ZR_RespawnCondition & condition )
{
if ( g_bTestRound )
condition = ZR_Respawn_Human ;
return Plugin_Changed ;
}
public Action Timer_MessageTestRound ( Handle timer )
{
if ( g_bTestRound )
{
CPrintToChatAll ( " {cyan}[UNLOZE] {red}This is a Test Round! " ) ;
CPrintToChatAll ( " {cyan}[UNLOZE] {red}This is a Test Round! " ) ;
CPrintToChatAll ( " {cyan}[UNLOZE] {red}This is a Test Round! " ) ;
}
return Plugin_Continue ;
2020-08-05 17:49:59 +02:00
}
public Action Timer_HandleHPShield ( Handle timer )
{
char sNemesis [ 32 ] ;
GetConVarString ( FindConVar ( " sm_info_message_file " ) , sNemesis , sizeof ( sNemesis ) ) ;
bool bNemesis = StrEqual ( sNemesis , " nemesis " ) ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( ! IsClientInGame ( i ) | | ! IsPlayerAlive ( i ) | | ! ZR_IsClientZombie ( i ) )
continue ;
2020-08-06 16:55:34 +02:00
if ( GetClientHealth ( i ) > g_iZHPMax [ i ] )
g_iZHPMax [ i ] = GetClientHealth ( i ) ;
2020-08-05 17:49:59 +02:00
bool bHasItem ;
# if defined entWatch_core_included
if ( g_Plugin_entWatch )
bHasItem = EW_ClientHasItem ( i ) ;
# endif
2020-08-05 18:29:35 +02:00
if ( ! g_bShield )
g_iZShield [ i ] = 0 ; //disabled by convar
else if ( bHasItem )
2020-08-05 17:49:59 +02:00
g_iZShield [ i ] = 0 ; //zombies with items
2020-08-06 04:35:25 +02:00
else if ( GetClientHealth ( i ) < g_iZHPMax [ i ] ) //zombies with no max hp
g_iZShield [ i ] = 0 ;
2020-08-05 17:49:59 +02:00
else if ( GetClientHealth ( i ) > = g_iZHPMax [ i ] & & bNemesis )
2020-08-05 18:29:35 +02:00
g_iZShield [ i ] = 0 ; //disabled for now on nemesis
2020-08-05 17:49:59 +02:00
//g_iZShield[i] = g_iZShield[i] + 12; // health_regen_amount = 12
else if ( GetClientHealth ( i ) > = g_iZHPMax [ i ] & & ! bNemesis )
g_iZShield [ i ] = g_iZShield [ i ] + 6 ; // health_regen_amount = 6
}
return Plugin_Continue ;
}
2020-08-06 23:56:06 +02:00
public Action Timer_UpdateHintMessage ( Handle timer )
2020-08-05 17:49:59 +02:00
{
2020-08-06 23:56:06 +02:00
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( ! IsClientInGame ( i ) | | ! IsPlayerAlive ( i ) | | ! ZR_IsClientZombie ( i ) )
continue ;
2020-08-05 17:49:59 +02:00
2020-08-06 23:56:06 +02:00
bool bVote = IsVoteInProgress ( ) ;
2020-08-05 17:49:59 +02:00
2020-08-08 21:56:59 +02:00
if ( /*g_bZHP[i] || */ bVote )
2020-08-06 23:56:06 +02:00
continue ;
if ( g_iZShield [ i ] < = 0 )
PrintHintText ( i , " HP: %d " , GetClientHealth ( i ) ) ;
else
PrintHintText ( i , " HP: %d - Shield: %d " , GetClientHealth ( i ) , g_iZShield [ i ] ) ;
}
return Plugin_Continue ;
2019-06-10 17:13:55 +02:00
}