2019-10-05 23:25:12 +02:00
# pragma semicolon 1
# include <sourcemod>
# include <cstrike>
# include <sdktools>
# include <zombiereloaded>
2019-10-13 20:57:17 +02:00
bool g_bKnifeRevert ;
2019-10-06 01:33:50 +02:00
bool g_bSlayKnifer ;
2019-10-05 23:25:12 +02:00
float g_fMaxTime ;
int g_iClientIndexKnifer ;
int g_iClientIndexKnifedZombie ;
bool g_bKnife ;
2020-07-06 14:32:53 +02:00
bool g_bInfectedByKnifeForward [ MAXPLAYERS + 1 ] ;
Handle KnifeRevertTimer ;
2019-10-05 23:25:12 +02:00
public Plugin myinfo =
{
2019-10-06 01:33:50 +02:00
name = " KnifeRevert " ,
2019-10-05 23:25:12 +02:00
author = " Dogan " ,
description = " Tool for Admins to prevent teamkilling cause of zombie knifing (ZE) " ,
2020-07-06 14:32:53 +02:00
version = " 2.0.0 " ,
2019-10-05 23:25:12 +02:00
url = " "
}
public void OnPluginStart ( )
{
ConVar cvar ;
2020-07-06 14:32:53 +02:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_kr_enabled " , " 1 " , " 1 = sm_kniferevert is available, 0 = sm_kniferevert is not available " , FCVAR_NONE , true , 0.0 , true , 1.0 ) ) , g_cvKnifeRevert ) ;
2019-10-13 20:57:17 +02:00
g_bKnifeRevert = cvar . BoolValue ;
2020-01-19 22:39:50 +01:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_kr_slay " , " 0 " , " 1 = slays the knifer automatically when sm_kniferevert is used, 0 = don't do anything to the knifer " , FCVAR_NONE , true , 0.0 , true , 1.0 ) ) , g_cvSlayKnifer ) ;
2019-10-06 01:33:50 +02:00
g_bSlayKnifer = cvar . BoolValue ;
2020-01-19 22:39:50 +01:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_kr_time " , " 6.0 " , " max time until sm_kniferevert is available after a knife " ) ) , g_cvMaxTime ) ;
2019-10-05 23:25:12 +02:00
g_fMaxTime = cvar . FloatValue ;
delete cvar ;
HookEvent ( " player_hurt " , OnPlayerHurt ) ;
2019-10-13 20:57:17 +02:00
RegAdminCmd ( " sm_kr " , Command_KnifeRevert , ADMFLAG_GENERIC , " Undoes the damage caused by a zombie after being knifed forward " ) ;
RegAdminCmd ( " sm_kniferevert " , Command_KnifeRevert , ADMFLAG_GENERIC , " Undoes the damage caused by a zombie after being knifed forward " ) ;
2019-10-05 23:25:12 +02:00
2019-10-06 01:36:14 +02:00
AutoExecConfig ( true , " plugin.KnifeRevert " ) ;
2019-10-05 23:25:12 +02:00
g_iClientIndexKnifer = - 1 ;
g_iClientIndexKnifedZombie = - 1 ;
}
2020-07-06 14:32:53 +02:00
public void g_cvKnifeRevert ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
2019-10-05 23:25:12 +02:00
{
2019-10-13 20:57:17 +02:00
g_bKnifeRevert = convar . BoolValue ;
2019-10-05 23:25:12 +02:00
}
public void g_cvSlayKnifer ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
{
2019-10-06 01:33:50 +02:00
g_bSlayKnifer = convar . BoolValue ;
2019-10-05 23:25:12 +02:00
}
public void g_cvMaxTime ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
{
g_fMaxTime = convar . FloatValue ;
}
public void OnPlayerHurt ( Handle hEvent , const char [ ] name , bool dontBroadcast )
{
2020-07-06 14:32:53 +02:00
if ( ! g_bKnifeRevert | | g_bKnife )
2019-10-05 23:25:12 +02:00
return ;
int attacker ;
int victim ;
char sWepName [ 64 ] ;
GetEventString ( hEvent , " weapon " , sWepName , sizeof ( sWepName ) ) ;
if ( ( attacker = GetClientOfUserId ( GetEventInt ( hEvent , " attacker " ) ) ) = = 0 )
return ;
if ( ( victim = GetClientOfUserId ( GetEventInt ( hEvent , " userid " ) ) ) = = 0 )
return ;
if ( ! IsClientInGame ( attacker ) | | ! IsPlayerAlive ( attacker ) )
return ;
if ( ! IsClientInGame ( victim ) | | ! IsPlayerAlive ( victim ) )
return ;
if ( victim ! = attacker & & GetClientTeam ( victim ) = = CS_TEAM_T & & GetClientTeam ( attacker ) = = CS_TEAM_CT )
{
if ( StrEqual ( sWepName , " knife " ) )
{
int damage = GetEventInt ( hEvent , " dmg_health " ) ;
if ( damage < 35 )
return ;
g_iClientIndexKnifer = attacker ;
g_iClientIndexKnifedZombie = victim ;
g_bKnife = true ;
2020-07-06 14:32:53 +02:00
KnifeRevertTimer = CreateTimer ( g_fMaxTime , OnClientKnife , _ , TIMER_FLAG_NO_MAPCHANGE ) ;
2019-10-05 23:25:12 +02:00
}
}
}
public Action OnClientKnife ( Handle timer )
{
g_bKnife = false ;
g_iClientIndexKnifer = - 1 ;
g_iClientIndexKnifedZombie = - 1 ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
2020-07-06 14:32:53 +02:00
if ( g_bInfectedByKnifeForward [ i ] )
g_bInfectedByKnifeForward [ i ] = false ;
2019-10-05 23:25:12 +02:00
}
}
public void ZR_OnClientInfected ( int client , int attacker , bool motherInfect , bool respawnOverride , bool respawn )
{
2019-10-13 20:57:17 +02:00
if ( ! g_bKnifeRevert | | ! g_bKnife )
2019-10-05 23:25:12 +02:00
return ;
2020-07-06 14:32:53 +02:00
if ( g_iClientIndexKnifedZombie = = attacker ) //originally knifed forward zombies kills ppl
g_bInfectedByKnifeForward [ client ] = true ;
2019-10-05 23:25:12 +02:00
2020-07-06 14:32:53 +02:00
if ( g_bInfectedByKnifeForward [ attacker ] ) //follow the infection chain
g_bInfectedByKnifeForward [ client ] = true ;
2019-10-05 23:25:12 +02:00
}
2019-10-13 20:57:17 +02:00
public Action Command_KnifeRevert ( int client , int argc )
2019-10-05 23:25:12 +02:00
{
2019-10-13 20:57:17 +02:00
if ( ! g_bKnifeRevert )
2019-10-05 23:25:12 +02:00
{
ReplyToCommand ( client , " [SM] Disabled on this Map. " ) ;
return Plugin_Handled ;
}
if ( ! g_bKnife )
{
ReplyToCommand ( client , " [SM] Not available right now because there was no active Zombie Knifing the past %d Seconds. " , RoundFloat ( g_fMaxTime ) ) ;
return Plugin_Handled ;
}
ReplyToCommand ( client , " [SM] You undid the damage from the previous Knife! " ) ;
PrintToChatAll ( " [SM] %N undid the damage from the previous Zombie Knife. " , client ) ;
LogAction ( client , - 1 , " \" %L \" undid the damage from the previous Zombie Knife. " , client ) ;
2019-10-06 01:33:50 +02:00
if ( g_bSlayKnifer )
2019-10-05 23:25:12 +02:00
{
2020-07-06 14:32:53 +02:00
if ( IsClientInGame ( g_iClientIndexKnifer ) & & IsPlayerAlive ( g_iClientIndexKnifer ) )
{
ForcePlayerSuicide ( g_iClientIndexKnifer ) ;
PrintToChat ( g_iClientIndexKnifer , " [SM] You got slayed for knifing a Zombie forward! " ) ;
}
2019-10-05 23:25:12 +02:00
}
2020-07-06 14:32:53 +02:00
if ( IsClientInGame ( g_iClientIndexKnifedZombie ) & & IsPlayerAlive ( g_iClientIndexKnifedZombie ) )
{
int IdKnifedZombie = GetClientUserId ( g_iClientIndexKnifedZombie ) ;
ServerCommand ( " zr_ztele_force #%d " , IdKnifedZombie ) ;
PrintToChat ( g_iClientIndexKnifedZombie , " [SM] You got teleported back because you were knifed forward. " ) ;
}
2019-10-05 23:25:12 +02:00
for ( int i = 1 ; i < = MaxClients ; i + + )
{
2020-07-06 14:32:53 +02:00
if ( IsClientInGame ( i ) & & IsPlayerAlive ( i ) & & g_bInfectedByKnifeForward [ i ] )
2019-10-05 23:25:12 +02:00
{
ZR_HumanClient ( i , false , false ) ;
PrintToChat ( i , " [SM] You were rezurrected because you died after a Zombie was knifed forward. " ) ;
}
}
2020-07-06 14:32:53 +02:00
g_iClientIndexKnifer = - 1 ;
g_iClientIndexKnifedZombie = - 1 ;
g_bKnife = false ;
KillTimer ( KnifeRevertTimer ) ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( g_bInfectedByKnifeForward [ i ] )
g_bInfectedByKnifeForward [ i ] = false ;
}
2019-10-05 23:25:12 +02:00
return Plugin_Handled ;
}