UptimeRestarts + KnifeRevert

minor fixes
This commit is contained in:
dogan 2020-07-06 14:32:53 +02:00
parent dc04b21eb4
commit eff26eba30
2 changed files with 39 additions and 34 deletions

View File

@ -7,32 +7,31 @@
bool g_bKnifeRevert; bool g_bKnifeRevert;
bool g_bSlayKnifer; bool g_bSlayKnifer;
float g_fMaxDistance;
float g_fMaxTime; float g_fMaxTime;
int g_iClientIndexKnifer; int g_iClientIndexKnifer;
int g_iClientIndexKnifedZombie; int g_iClientIndexKnifedZombie;
bool g_bKnife; bool g_bKnife;
bool g_bInfectedInRadius[MAXPLAYERS + 1]; bool g_bInfectedByKnifeForward[MAXPLAYERS + 1];
Handle KnifeRevertTimer;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "KnifeRevert", name = "KnifeRevert",
author = "Dogan", author = "Dogan",
description = "Tool for Admins to prevent teamkilling cause of zombie knifing (ZE)", description = "Tool for Admins to prevent teamkilling cause of zombie knifing (ZE)",
version = "1.1.0", version = "2.0.0",
url = "" url = ""
} }
public void OnPluginStart() public void OnPluginStart()
{ {
ConVar cvar; ConVar cvar;
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_cvZAbuse); 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);
g_bKnifeRevert = cvar.BoolValue; g_bKnifeRevert = cvar.BoolValue;
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); 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);
g_bSlayKnifer = cvar.BoolValue; g_bSlayKnifer = cvar.BoolValue;
HookConVarChange((cvar = CreateConVar("sm_kr_maxdistance", "200.0", "max distance from the zombie that got knifed forward where infected humans will be rezurrected")), g_cvMaxDistance);
g_fMaxDistance = cvar.FloatValue;
HookConVarChange((cvar = CreateConVar("sm_kr_time", "6.0", "max time until sm_kniferevert is available after a knife")), g_cvMaxTime); HookConVarChange((cvar = CreateConVar("sm_kr_time", "6.0", "max time until sm_kniferevert is available after a knife")), g_cvMaxTime);
g_fMaxTime = cvar.FloatValue; g_fMaxTime = cvar.FloatValue;
delete cvar; delete cvar;
@ -48,7 +47,7 @@ public void OnPluginStart()
g_iClientIndexKnifedZombie = -1; g_iClientIndexKnifedZombie = -1;
} }
public void g_cvZAbuse(ConVar convar, const char[] oldValue, const char[] newValue) public void g_cvKnifeRevert(ConVar convar, const char[] oldValue, const char[] newValue)
{ {
g_bKnifeRevert = convar.BoolValue; g_bKnifeRevert = convar.BoolValue;
} }
@ -58,11 +57,6 @@ public void g_cvSlayKnifer(ConVar convar, const char[] oldValue, const char[] ne
g_bSlayKnifer = convar.BoolValue; g_bSlayKnifer = convar.BoolValue;
} }
public void g_cvMaxDistance(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_fMaxDistance = convar.FloatValue;
}
public void g_cvMaxTime(ConVar convar, const char[] oldValue, const char[] newValue) public void g_cvMaxTime(ConVar convar, const char[] oldValue, const char[] newValue)
{ {
g_fMaxTime = convar.FloatValue; g_fMaxTime = convar.FloatValue;
@ -70,7 +64,7 @@ public void g_cvMaxTime(ConVar convar, const char[] oldValue, const char[] newVa
public void OnPlayerHurt(Handle hEvent, const char[] name, bool dontBroadcast) public void OnPlayerHurt(Handle hEvent, const char[] name, bool dontBroadcast)
{ {
if(!g_bKnifeRevert) if(!g_bKnifeRevert || g_bKnife)
return; return;
int attacker; int attacker;
@ -103,7 +97,7 @@ public void OnPlayerHurt(Handle hEvent, const char[] name, bool dontBroadcast)
g_iClientIndexKnifedZombie = victim; g_iClientIndexKnifedZombie = victim;
g_bKnife = true; g_bKnife = true;
CreateTimer(g_fMaxTime, OnClientKnife, _, TIMER_FLAG_NO_MAPCHANGE); KnifeRevertTimer = CreateTimer(g_fMaxTime, OnClientKnife, _, TIMER_FLAG_NO_MAPCHANGE);
} }
} }
} }
@ -116,10 +110,8 @@ public Action OnClientKnife(Handle timer)
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(g_bInfectedInRadius[i]) if(g_bInfectedByKnifeForward[i])
{ g_bInfectedByKnifeForward[i] = false;
g_bInfectedInRadius[i] = false;
}
} }
} }
@ -128,15 +120,11 @@ public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, boo
if(!g_bKnifeRevert || !g_bKnife) if(!g_bKnifeRevert || !g_bKnife)
return; return;
static float fVec1[3]; if(g_iClientIndexKnifedZombie == attacker)//originally knifed forward zombies kills ppl
static float fVec2[3]; g_bInfectedByKnifeForward[client] = true;
GetClientAbsOrigin(g_iClientIndexKnifedZombie, fVec1);
GetClientAbsOrigin(client, fVec2);
float fDistance = GetVectorDistance(fVec1, fVec2, false); if(g_bInfectedByKnifeForward[attacker])//follow the infection chain
g_bInfectedByKnifeForward[client] = true;
if(fDistance <= g_fMaxDistance)
g_bInfectedInRadius[client] = true;
} }
public Action Command_KnifeRevert(int client, int argc) public Action Command_KnifeRevert(int client, int argc)
@ -158,23 +146,40 @@ public Action Command_KnifeRevert(int client, int argc)
LogAction(client, -1, "\"%L\" undid the damage from the previous Zombie Knife.", client); LogAction(client, -1, "\"%L\" undid the damage from the previous Zombie Knife.", client);
if(g_bSlayKnifer) if(g_bSlayKnifer)
{
if(IsClientInGame(g_iClientIndexKnifer) && IsPlayerAlive(g_iClientIndexKnifer))
{ {
ForcePlayerSuicide(g_iClientIndexKnifer); ForcePlayerSuicide(g_iClientIndexKnifer);
PrintToChat(g_iClientIndexKnifer, "[SM] You got slayed for knifing a Zombie forward!"); PrintToChat(g_iClientIndexKnifer, "[SM] You got slayed for knifing a Zombie forward!");
} }
}
if(IsClientInGame(g_iClientIndexKnifedZombie) && IsPlayerAlive(g_iClientIndexKnifedZombie))
{
int IdKnifedZombie = GetClientUserId(g_iClientIndexKnifedZombie); int IdKnifedZombie = GetClientUserId(g_iClientIndexKnifedZombie);
ServerCommand("zr_ztele_force #%d", IdKnifedZombie); ServerCommand("zr_ztele_force #%d", IdKnifedZombie);
PrintToChat(g_iClientIndexKnifedZombie, "[SM] You got teleported back because you were knifed forward."); PrintToChat(g_iClientIndexKnifedZombie, "[SM] You got teleported back because you were knifed forward.");
}
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(IsClientInGame(i) && IsPlayerAlive(i) && g_bInfectedInRadius[i]) if(IsClientInGame(i) && IsPlayerAlive(i) && g_bInfectedByKnifeForward[i])
{ {
ZR_HumanClient(i, false, false); ZR_HumanClient(i, false, false);
PrintToChat(i, "[SM] You were rezurrected because you died after a Zombie was knifed forward."); PrintToChat(i, "[SM] You were rezurrected because you died after a Zombie was knifed forward.");
} }
} }
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;
}
return Plugin_Handled; return Plugin_Handled;
} }

View File

@ -147,7 +147,7 @@ public Action CheckRestart(Handle timer)
int iPlayers = GetClientCount(false); int iPlayers = GetClientCount(false);
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(IsClientConnected(i) && IsFakeClient(i)) if(IsFakeClient(i))
iPlayers--; iPlayers--;
} }
@ -157,7 +157,7 @@ public Action CheckRestart(Handle timer)
return Plugin_Continue; return Plugin_Continue;
} }
if(!IsItRestartTime()) if(!IsItRestartTime() || GetEngineTime() < 57500)
return Plugin_Continue; return Plugin_Continue;
if(iPlayers > g_cvarMaxPlayersForControlledRestart.IntValue) //jenz's autism bot if(iPlayers > g_cvarMaxPlayersForControlledRestart.IntValue) //jenz's autism bot