Add "Minimum Velocity" style

This commit is contained in:
Unknown 2017-07-17 22:58:37 +02:00
parent f4ab9937e3
commit c69508700a
3 changed files with 35 additions and 0 deletions

View File

@ -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

View File

@ -95,6 +95,7 @@ enum
fSpeedMultiplier,
bHalftime,
fVelocity,
fMinVelocity,
bBlockW,
bBlockA,
bBlockS,

View File

@ -710,6 +710,11 @@ public void Player_Jump(Event event, const char[] name, bool dontBroadcast)
{
RequestFrame(ApplyNewVelocity, GetClientSerial(client));
}
if(view_as<float>(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<float>(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);