I use this knockback code, like of ZR Knockback, but i have a problem on CSGO.
If player has hit from the chin to up, it is throw to the SKYBOX of the map.
I try some ways to fix this, reduce magnitude and cvars commands like:
PHP Code:
sm_cvar mp_tagging_scale 0
and
PHP Code:
sv_clamp_unsafe_velocities 0
and
PHP Code:
https://forums.alliedmods.net/showthread.php?t=274998
But dont work, my code ballow:
PHP Code:
stock void ToolspClientVelocity(int pClient, float vecVelocity[3], bool apply = true, bool stack = true)
{
if(!apply) // If retrieve if true, then get pClient's velocity.
{
for(int x = 0; x < 3; x++) {// x = vector component.
vecVelocity[x] = GetEntDataFloat(pClient, g_iToolsVelocity + (x*4));
}
return; // Stop here.
}
if(stack) // If stack is true, then add pClient's velocity.
{
float vecpClientVelocity[3]; // Get pClient's velocity.
for(int x = 0; x < 3; x++) { // x = vector component.
vecpClientVelocity[x] = GetEntDataFloat(pClient, g_iToolsVelocity + (x*4));
}
AddVectors(vecpClientVelocity, vecVelocity, vecVelocity);
}
TeleportEntity(pClient, NULL_VECTOR, NULL_VECTOR, vecVelocity); // Apply velocity on pClient.
}
void KnockbackOnClientHurt(int pClient, int attacker, const char[] weapon, int dmg_health)
{
if(!attacker) // If attacker is invalid, then stop.
return;
knockback = 1.0;
float pClientloc[3];
float attackerloc[3];
GetClientAbsOrigin(pClient, pClientloc);
if(StrEqual(weapon, "hegrenade")) { // Check if a grenade was thrown.
if(KnockbackFindExplodingGrenade(attackerloc) == -1) // Get the location of the grenade.
return; // If the grenade wasn't found, then stop.
}
else if(StrEqual(weapon, "worldspawn")) {
return;
}
else {
GetClientEyePosition(attacker, attackerloc); // Get attackers eye position.
float attackerang[3];
GetClientEyeAngles(attacker, attackerang); // Get attackers eye angles
TR_TraceRayFilter(attackerloc, attackerang, MASK_ALL, RayType_Infinite, KnockbackTRFilter); // Calculate knockback end-vector.
TR_GetEndPosition(pClientloc);
}
knockback *= float(dmg_health); // Apply damage knockback multiplier
KnockbackSetVelocity(pClient, attackerloc, pClientloc, knockback); // Apply knockback.
}
void KnockbackSetVelocity(int pClient, const float startpoint[3], const float endpoint[3], float magnitude)
{
float vector[3];
MakeVectorFromPoints(startpoint, endpoint, vector); // Create vector from the given starting and ending points.
NormalizeVector(vector, vector); // Normalize the vector (equal magnitude at varying distances).
ScaleVector(vector, magnitude); // Apply the magnitude by scaling the vector (multiplying each of its components).
ToolspClientVelocity(pClient, vector); // ADD the given vector to the pClient's current velocity.
}
public bool KnockbackTRFilter(int entity, int contentsMask)
{
if(entity > 0 && entity < MAXPLAYERS) { // If entity is a player, continue tracing.
return false;
}
return true; // Allow hit.
}
public int KnockbackFindExplodingGrenade(float heLoc[3])
{
char classname[64];
int maxentities = GetMaxEntities(); // Find max entities and loop through all of them.
for(int x = MaxClients; x <= maxentities; x++)
{
if(!IsValidEdict(x)) // If entity is invalid, then stop.
continue;
GetEdictClassname(x, classname, sizeof(classname));
if(!StrEqual(classname, "hegrenade_projectile", false)) // If entity isn't a grenade, then stop.
continue;
int takedamage = GetEntProp(x, Prop_Data, "m_takedamage"); // If m_takedamage is set to 0, we found our grenade.
if(takedamage == 0)
{
GetEntPropVector(x, Prop_Send, "m_vecOrigin", heLoc); // Return its location.
return x; // Return its entity index.
}
}
return -1; // Didn't find the grenade.
}
Any can help me?
__________________