KnifeMadness: Supress suicide event.

This commit is contained in:
zaCade 2019-03-03 12:42:51 +01:00
parent e99df271cd
commit b0b028e511

View File

@ -10,7 +10,9 @@
ConVar g_hCVar_Delay; ConVar g_hCVar_Delay;
/* BOOLS */ /* BOOLS */
bool g_bZMwasKnifed[MAXPLAYERS+1]; bool g_bClientKnifed[MAXPLAYERS+1];
bool g_bSupressDeath[MAXPLAYERS+1];
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -30,8 +32,9 @@ 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); g_hCVar_Delay = CreateConVar("sm_knife_madness_kill_delay", "3", "Delay before ZMs die after being knifed by a human.", 0, true, 0.0);
HookEvent("player_spawn", OnClientSpawn); HookEvent("player_spawn", OnClientSpawn, EventHookMode_Post);
HookEvent("player_hurt", OnClientHurt); HookEvent("player_death", OnClientDeath, EventHookMode_Pre);
HookEvent("player_hurt", OnClientHurt, EventHookMode_Post);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -40,7 +43,25 @@ public void OnPluginStart()
public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast) public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{ {
int client = GetClientOfUserId(hEvent.GetInt("userid")); int client = GetClientOfUserId(hEvent.GetInt("userid"));
g_bZMwasKnifed[client] = false;
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;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -63,7 +84,7 @@ public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast)
if(!StrEqual(sWeapon, "knife", false)) if(!StrEqual(sWeapon, "knife", false))
return; return;
g_bZMwasKnifed[victim] = true; g_bClientKnifed[victim] = true;
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(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); 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);
@ -76,7 +97,6 @@ public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast)
pack.WriteCell(GetClientUserId(victim)); pack.WriteCell(GetClientUserId(victim));
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -85,9 +105,9 @@ public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, boo
if (!IsValidClient(attacker)) if (!IsValidClient(attacker))
return; return;
if(g_bZMwasKnifed[attacker]) if(g_bClientKnifed[attacker])
{ {
g_bZMwasKnifed[attacker] = false; g_bClientKnifed[attacker] = false;
SetEntProp(attacker, Prop_Send, "m_iProgressBarDuration", 0); SetEntProp(attacker, Prop_Send, "m_iProgressBarDuration", 0);
CPrintToChat(attacker, "{unique}[Knife Madness] {white}You have successfully infected a human and prevented your death."); CPrintToChat(attacker, "{unique}[Knife Madness] {white}You have successfully infected a human and prevented your death.");
} }
@ -108,9 +128,10 @@ public Action KillZM(Handle timer, DataPack pack)
if (client == 0) if (client == 0)
return; return;
if (!(IsValidClient(client, false) && IsPlayerAlive(client) && ZR_IsClientZombie(client) && g_bZMwasKnifed[client])) if (!(IsValidClient(client, false) && IsPlayerAlive(client) && ZR_IsClientZombie(client) && g_bClientKnifed[client]))
return; return;
g_bSupressDeath[client] = true;
ForcePlayerSuicide(client); ForcePlayerSuicide(client);
if (!(IsValidClient(attacker, false))) if (!(IsValidClient(attacker, false)))