2018-11-13 18:45:25 +01:00
# include <sourcemod>
# include <sdktools>
# include <multicolors>
# include <zombiereloaded>
# pragma semicolon 1
# pragma newdecls required
/* CONVARS */
ConVar g_hCVar_Delay ;
/* BOOLS */
2019-03-03 12:42:51 +01:00
bool g_bClientKnifed [ MAXPLAYERS + 1 ] ;
bool g_bSupressDeath [ MAXPLAYERS + 1 ] ;
2018-11-13 18:45:25 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = " UNLOZE Knife Madness " ,
author = " Neon " ,
description = " UNLOZE Knife Madness " ,
2019-02-27 16:37:28 +01:00
version = " 1.1 " ,
2018-11-13 18:45:25 +01:00
url = " https://steamcommunity.com/id/n3ontm "
} ;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart ( )
{
g_hCVar_Delay = CreateConVar ( " sm_knife_madness_kill_delay " , " 3 " , " Delay before ZMs die after being knifed by a human. " , 0 , true , 0.0 ) ;
2019-03-03 12:42:51 +01:00
HookEvent ( " player_spawn " , OnClientSpawn , EventHookMode_Post ) ;
HookEvent ( " player_death " , OnClientDeath , EventHookMode_Pre ) ;
HookEvent ( " player_hurt " , OnClientHurt , EventHookMode_Post ) ;
2018-11-13 18:45:25 +01:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientSpawn ( Event hEvent , const char [ ] sEvent , bool bDontBroadcast )
{
int client = GetClientOfUserId ( hEvent . GetInt ( " userid " ) ) ;
2019-03-03 12:42:51 +01:00
g_bClientKnifed [ client ] = false ;
g_bSupressDeath [ client ] = false ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnClientDeath ( Event hEvent , const char [ ] sEvent , bool bDontBroadcast )
{
int client = GetClientOfUserId ( hEvent . GetInt ( " userid " ) ) ;
if ( g_bSupressDeath [ client ] )
{
g_bSupressDeath [ client ] = false ;
return Plugin_Handled ;
}
return Plugin_Continue ;
2018-11-13 18:45:25 +01:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientHurt ( Event hEvent , const char [ ] sEvent , bool bDontBroadcast )
{
int attacker = GetClientOfUserId ( hEvent . GetInt ( " attacker " ) ) ;
int victim = GetClientOfUserId ( hEvent . GetInt ( " userid " ) ) ;
if ( ! IsValidClient ( attacker , false ) )
return ;
if ( ! ( IsPlayerAlive ( attacker ) & & IsPlayerAlive ( victim ) & & ZR_IsClientHuman ( attacker ) & & ZR_IsClientZombie ( victim ) ) )
return ;
char sWeapon [ 32 ] ;
GetEventString ( hEvent , " weapon " , sWeapon , sizeof ( sWeapon ) ) ;
if ( ! StrEqual ( sWeapon , " knife " , false ) )
return ;
2019-03-03 12:42:51 +01:00
g_bClientKnifed [ victim ] = true ;
2018-11-13 18:45:25 +01:00
CPrintToChat ( attacker , " {unique}[Knife Madness] {white}You have knifed {lime}%N{white}. He will die in %ds if he doesnt infect a human. " , victim , g_hCVar_Delay . IntValue ) ;
CPrintToChat ( victim , " {unique}[Knife Madness] {white}You have been knifed by {lime}%N{white}. You will die in %ds if you do not infect a human. " , attacker , g_hCVar_Delay . IntValue ) ;
SetEntPropFloat ( victim , Prop_Send , " m_flProgressBarStartTime " , GetGameTime ( ) ) ;
SetEntProp ( victim , Prop_Send , " m_iProgressBarDuration " , g_hCVar_Delay . IntValue ) ;
DataPack pack ;
CreateDataTimer ( g_hCVar_Delay . FloatValue , KillZM , pack , TIMER_FLAG_NO_MAPCHANGE ) ;
pack . WriteCell ( GetClientUserId ( attacker ) ) ;
pack . WriteCell ( GetClientUserId ( victim ) ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ZR_OnClientInfected ( int client , int attacker , bool motherInfect , bool respawnOverride , bool respawn )
{
if ( ! IsValidClient ( attacker ) )
return ;
2019-03-03 12:42:51 +01:00
if ( g_bClientKnifed [ attacker ] )
2018-11-13 18:45:25 +01:00
{
2019-03-03 12:42:51 +01:00
g_bClientKnifed [ attacker ] = false ;
2018-11-13 18:45:25 +01:00
SetEntProp ( attacker , Prop_Send , " m_iProgressBarDuration " , 0 ) ;
CPrintToChat ( attacker , " {unique}[Knife Madness] {white}You have successfully infected a human and prevented your death. " ) ;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action KillZM ( Handle timer , DataPack pack )
{
int attacker = 0 ;
int client = 0 ;
pack . Reset ( ) ;
attacker = GetClientOfUserId ( pack . ReadCell ( ) ) ;
client = GetClientOfUserId ( pack . ReadCell ( ) ) ;
if ( client = = 0 )
return ;
2019-03-03 12:42:51 +01:00
if ( ! ( IsValidClient ( client , false ) & & IsPlayerAlive ( client ) & & ZR_IsClientZombie ( client ) & & g_bClientKnifed [ client ] ) )
2018-11-13 18:45:25 +01:00
return ;
2019-03-03 12:42:51 +01:00
g_bSupressDeath [ client ] = true ;
2018-11-13 18:45:25 +01:00
ForcePlayerSuicide ( client ) ;
if ( ! ( IsValidClient ( attacker , false ) ) )
return ;
Event hEvent = CreateEvent ( " player_death " ) ;
if ( hEvent = = null )
return ;
hEvent . SetInt ( " userid " , GetClientUserId ( client ) ) ;
hEvent . SetInt ( " attacker " , GetClientUserId ( attacker ) ) ;
hEvent . SetString ( " weapon " , " knife " ) ;
hEvent . SetBool ( " headshot " , false ) ;
hEvent . SetInt ( " dominated " , 0 ) ;
hEvent . SetInt ( " revenge " , 0 ) ;
hEvent . Fire ( ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock int IsValidClient ( int client , bool nobots = true )
{
if ( client < = 0 | | client > MaxClients | | ! IsClientConnected ( client ) | | ( nobots & & IsFakeClient ( client ) ) )
return false ;
return IsClientInGame ( client ) ;
}