Improve custom knockback API

This commit is contained in:
BotoX 2019-09-28 16:11:01 +02:00
parent bb37965670
commit 197eb861bd
2 changed files with 17 additions and 9 deletions

View File

@ -25,6 +25,10 @@
* ============================================================================
*/
#define ZR_KNOCKBACK_CUSTOM (1<<31)
#define ZR_KNOCKBACK_SCALE (1<<1)
#define ZR_KNOCKBACK_LIMITVEL (1<<2)
/**
* Set a maximum knockback velocity.
*

View File

@ -81,6 +81,7 @@ void KnockbackOnClientDeath(int client)
void KnockbackSetClientMaxVelocity(int client, float fVelocity)
{
if(g_fKnockbackVelLimit[client] >= 0.0)
g_fKnockbackVelLimit[client] = fVelocity;
}
@ -172,8 +173,6 @@ public void KnockbackOnTakeDamageAlivePost(int victim, int attacker, int inflict
ReplaceString(weaponname, sizeof(weaponname), "weapon_", "");
ReplaceString(weaponname, sizeof(weaponname), "_projectile", "");
bool knife = StrEqual(weaponname, "knife");
// Check if a grenade was thrown.
if (StrEqual(weaponname, "hegrenade"))
{
@ -209,11 +208,15 @@ public void KnockbackOnTakeDamageAlivePost(int victim, int attacker, int inflict
}
}
bool custom = view_as<bool>(damagecustom & ZR_KNOCKBACK_CUSTOM);
bool scale = custom && view_as<bool>(damagecustom & ZR_KNOCKBACK_SCALE);
bool limitvel = custom && view_as<bool>(damagecustom & ZR_KNOCKBACK_LIMITVEL);
int hitgroup = HITGROUP_GENERIC;
if (!(damagetype & DMG_BLAST) && !damagecustom)
if (!(damagetype & DMG_BLAST) && !custom)
hitgroup = ToolsGetClientLastHitGroup(victim);
if (damagecustom)
if (custom)
ToolsSetClientLastHitGroup(victim, HITGROUP_GENERIC);
new bool:hitgroups = GetConVarBool(g_hCvarsList[CVAR_HITGROUPS]);
@ -231,11 +234,12 @@ public void KnockbackOnTakeDamageAlivePost(int victim, int attacker, int inflict
knockback *= damage;
// Custom knockback scale.
if (!knife)
if (scale)
knockback *= g_fKnockbackScale[victim];
// Apply knockback.
KnockbackSetVelocity(victim, attackerloc, clientloc, knockback, damagecustom && !knife);
if (knockback)
KnockbackSetVelocity(victim, attackerloc, clientloc, knockback, limitvel);
}
/**
@ -246,7 +250,7 @@ public void KnockbackOnTakeDamageAlivePost(int victim, int attacker, int inflict
* @param endpoint The ending coordinate to push towards.
* @param magnitude Magnitude of the push.
*/
KnockbackSetVelocity(client, const Float:startpoint[3], const Float:endpoint[3], Float:magnitude, int custom)
KnockbackSetVelocity(client, const Float:startpoint[3], const Float:endpoint[3], Float:magnitude, int limitvel)
{
// Create vector from the given starting and ending points.
new Float:vector[3];
@ -258,7 +262,7 @@ KnockbackSetVelocity(client, const Float:startpoint[3], const Float:endpoint[3],
// Apply the magnitude by scaling the vector (multiplying each of its components).
ScaleVector(vector, magnitude);
if (custom && g_fKnockbackVelLimit[client])
if (limitvel && g_fKnockbackVelLimit[client])
{
AddVectors(g_fKnockbackVectors[client], vector, g_fKnockbackVectors[client]);
g_bKnockbackFrame[client] = true;