add zr_knockback_maxvel

This commit is contained in:
BotoX 2019-11-18 22:35:14 +01:00
parent eda8971996
commit 80228760c5
2 changed files with 14 additions and 3 deletions

View File

@ -183,6 +183,7 @@ enum CvarsList
Handle:CVAR_ZSPAWN_TIMELIMIT_ZOMBIE,
Handle:CVAR_ZHP,
Handle:CVAR_ZHP_DEFAULT,
Handle:CVAR_KNOCKBACK_MAXVEL,
}
/**
@ -516,6 +517,12 @@ CvarsCreate()
g_hCvarsList[CVAR_ZHP] = CreateConVar("zr_zhp", "1", "Allow player to toggle real HP display as a zombie.");
g_hCvarsList[CVAR_ZHP_DEFAULT] = CreateConVar("zr_zhp_default", "1", "Default ZHP toggle state set on connecting player. [Dependency: zr_zhp]");
// ===========================
// Knockback (module)
// ===========================
g_hCvarsList[CVAR_KNOCKBACK_MAXVEL] = CreateConVar("zr_knockback_maxvel", "0", "Set maximum velocity zombies can get from knockback ['0' = Off].");
ZTele_OnCvarsCreate();
// Auto-generate config file if it doesn't exist, then execute.

View File

@ -291,8 +291,12 @@ void KnockbackApplyVector(int client, float vector[3], bool limitvel)
AddVectors(vector, velocity, velocity);
// Should we limit their knockback velocity?
if (limitvel && g_fKnockbackVelLimit[client] >= 0.0)
float maxvel = GetConVarFloat(g_hCvarsList[CVAR_KNOCKBACK_MAXVEL]);
if (limitvel && g_fKnockbackVelLimit[client] >= 0.0 || maxvel > 0.0)
{
if(g_fKnockbackVelLimit[client] >= 0.0 && g_fKnockbackVelLimit[client] < maxvel)
maxvel = g_fKnockbackVelLimit[client];
// Calculate their new speed.
float magnitude_post = GetVectorLength(velocity);
@ -300,10 +304,10 @@ void KnockbackApplyVector(int client, float vector[3], bool limitvel)
if (magnitude_post > magnitude_pre)
{
// Would their knockback velocity be higher than wanted?
if(magnitude_post > g_fKnockbackVelLimit[client])
if(magnitude_post > maxvel)
{
// ... then scale it down.
ScaleVector(velocity, g_fKnockbackVelLimit[client] / magnitude_post);
ScaleVector(velocity, maxvel / magnitude_post);
}
}
}