Quote:
Originally Posted by SaraAki
I tested both versions,from Krtola and Tote last edit.What I noticed is that knockback work every time when i stab player from my team,but when i stab enemy,knockback doesn't always happen.It actually only happens when i kill the enemy player with knife right click,but not always.Is it possible to adjust that the effect does not affect my teammates?And to affect enemy player every time when i stab him?
|
Code:
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
#include <fakemeta>
#include <engine>
#define VERSION "1.0"
new cvar_knock_force
public plugin_init()
{
register_plugin("Knife Stab KB", VERSION, "v3x & chronic/ edit tote")
RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Post", 1)
cvar_knock_force = register_cvar("knife_force", "10");
}
public fw_TraceAttack_Post(victim_id, attacker_id)
{
new victimteam; victimteam = get_user_team(victim_id)
new attackerteam; attackerteam = get_user_team(attacker_id)
if(get_user_weapon(attacker_id) == CSW_KNIFE && victimteam != attackerteam)
{
static buttons
buttons = pev(attacker_id, pev_button)
if(buttons & IN_ATTACK2)
{
new Float:vec[3];
new Float:oldvelo[3];
get_user_velocity(victim_id, oldvelo);
create_velocity_vector(victim_id , attacker_id , vec);
vec[0] += oldvelo[0];
vec[1] += oldvelo[1];
set_user_velocity(victim_id , vec);
}
}
}
// Stock by the one and only, Chronic :P
stock create_velocity_vector(victim,attacker,Float:velocity[3])
{
if(!is_user_alive(victim) || !is_user_alive(attacker))
return 0;
new Float:vicorigin[3];
new Float:attorigin[3];
entity_get_vector(victim , EV_VEC_origin , vicorigin);
entity_get_vector(attacker , EV_VEC_origin , attorigin);
new Float:origin2[3]
origin2[0] = vicorigin[0] - attorigin[0];
origin2[1] = vicorigin[1] - attorigin[1];
new Float:largestnum = 0.0;
if(floatabs(origin2[0])>largestnum) largestnum = floatabs(origin2[0]);
if(floatabs(origin2[1])>largestnum) largestnum = floatabs(origin2[1]);
origin2[0] /= largestnum;
origin2[1] /= largestnum;
velocity[0] = ( origin2[0] * (get_pcvar_float(cvar_knock_force) * 3000) ) / get_entity_distance(victim , attacker);
velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_knock_force) * 3000) ) / get_entity_distance(victim , attacker);
if(velocity[0] <= 20.0 || velocity[1] <= 20.0)
velocity[2] = random_float(200.0 , 275.0);
return 1;
}