From c69508700a8675e10aa33c089eb0f61fafe6ce67 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 17 Jul 2017 22:58:37 +0200 Subject: [PATCH] Add "Minimum Velocity" style --- configs/shavit-styles.cfg | 1 + scripting/include/shavit.inc | 1 + scripting/shavit-core.sp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/configs/shavit-styles.cfg b/configs/shavit-styles.cfg index 2bac77e5..273f2fcc 100644 --- a/configs/shavit-styles.cfg +++ b/configs/shavit-styles.cfg @@ -27,6 +27,7 @@ "speed" "1.0" // speed multiplier, 1.0 for default. standard for slowmo styles is 0.5 "halftime" "0" // calculation of times will be halved, replays WILL NOT function properly "velocity" "1.0" // % of horizontal velocity to keep per jump. a value 0.9 will make the player lose 10% of their velocity per jump. likewise, values above 1 will result in speed gains. + "min_velocity" "0.0" // minimum amount of horizontal velocity to keep per jump. if set to 600.0 , the player can't have less than 600 velocity per jump // mode settings "block_w" "0" // block +forward diff --git a/scripting/include/shavit.inc b/scripting/include/shavit.inc index 3bf0d911..4e1d493c 100644 --- a/scripting/include/shavit.inc +++ b/scripting/include/shavit.inc @@ -95,6 +95,7 @@ enum fSpeedMultiplier, bHalftime, fVelocity, + fMinVelocity, bBlockW, bBlockA, bBlockS, diff --git a/scripting/shavit-core.sp b/scripting/shavit-core.sp index 219a6efd..d4671837 100644 --- a/scripting/shavit-core.sp +++ b/scripting/shavit-core.sp @@ -710,6 +710,11 @@ public void Player_Jump(Event event, const char[] name, bool dontBroadcast) { RequestFrame(ApplyNewVelocity, GetClientSerial(client)); } + + if(view_as(gA_StyleSettings[gBS_Style[client]][fMinVelocity]) != 0.0) + { + RequestFrame(MinimumVelocity, GetClientSerial(client)); + } } void ApplyNewVelocity(int data) @@ -726,6 +731,33 @@ void ApplyNewVelocity(int data) } } +void MinimumVelocity(int data) +{ + int client = GetClientFromSerial(data); + + if(data != 0) + { + float fAbsVelocity[3]; + GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fAbsVelocity); + + float currentspeed = (SquareRoot(Pow(fAbsVelocity[0], 2.0) + Pow(fAbsVelocity[1], 2.0))); + + if(currentspeed > 0.0) + { + float fMin = view_as(gA_StyleSettings[gBS_Style[client]][fMinVelocity]); + + if(currentspeed < fMin) + { + float x = currentspeed / (fMin); + fAbsVelocity[0] /= x; + fAbsVelocity[1] /= x; + + TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fAbsVelocity); + } + } + } +} + public void Player_Death(Event event, const char[] name, bool dontBroadcast) { int client = GetClientOfUserId(event.GetInt("userid")); @@ -1268,6 +1300,7 @@ bool LoadStyles() gA_StyleSettings[i][fSpeedMultiplier] = dStyle.GetFloat("speed", 1.0); gA_StyleSettings[i][bHalftime] = dStyle.GetBool("halftime", false); gA_StyleSettings[i][fVelocity] = dStyle.GetFloat("velocity", 1.0); + gA_StyleSettings[i][fMinVelocity] = dStyle.GetFloat("min_velocity", 0.0); gA_StyleSettings[i][bBlockW] = dStyle.GetBool("block_w", false); gA_StyleSettings[i][bBlockA] = dStyle.GetBool("block_a", false); gA_StyleSettings[i][bBlockS] = dStyle.GetBool("block_s", false);