From 80228760c518ac178e13eac5a18679ccfed96f63 Mon Sep 17 00:00:00 2001 From: BotoX Date: Mon, 18 Nov 2019 22:35:14 +0100 Subject: [PATCH] add zr_knockback_maxvel --- src/zr/cvars.inc | 7 +++++++ src/zr/knockback.inc | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index 19bf8ae..d65540f 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -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. diff --git a/src/zr/knockback.inc b/src/zr/knockback.inc index 5cf2632..875f0e3 100644 --- a/src/zr/knockback.inc +++ b/src/zr/knockback.inc @@ -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); } } }