Raised This Month: $12 Target: $400
 3% 

Knife hit knockback


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SaraAki
Member
Join Date: Nov 2022
Old 04-24-2024 , 10:21   Knife hit knockback
Reply With Quote #1

This plugin activate knockback on knife damage.What i want is that knockback work only when damage is done with right mouse click.Also,maybe there is a better way to create knockback than using event_damage?

PHP Code:
#include <amxmodx>
#include <engine>

#define PLUGIN    "Knife Knockback (when shot by one)"
#define VERSION    "1.0"
#define AUTHOR    "v3x & Chronic"

new cvar_pump_active cvar_pump_force;

public 
plugin_init()
{
    
register_plugin(PLUGIN VERSION AUTHOR);

    
register_event("Damage" "event_Damage" "b" "2>0");

    
cvar_pump_active   register_cvar("knife_knockback" "1");
    
cvar_pump_force       register_cvar("knife_force"     "10");
}

public 
event_Damage(id)
{
    if(!
get_pcvar_num(cvar_pump_active))
        return 
PLUGIN_CONTINUE;

    if(!
is_user_alive(id))
        return 
PLUGIN_CONTINUE;

    new 
weapon attacker get_user_attacker(id weapon);

    if(!
is_user_alive(attacker))
        return 
PLUGIN_CONTINUE;

    if(
weapon == CSW_KNIFE)
    {
        new 
Float:vec[3];
        new 
Float:oldvelo[3];
        
get_user_velocity(idoldvelo);
        
create_velocity_vector(id attacker vec);
        
vec[0] += oldvelo[0];
        
vec[1] += oldvelo[1];
        
set_user_velocity(id vec);
    }

    return 
PLUGIN_CONTINUE;
}

// 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])>largestnumlargestnum floatabs(origin2[0]);
    if(
floatabs(origin2[1])>largestnumlargestnum floatabs(origin2[1]);

    
origin2[0] /= largestnum;
    
origin2[1] /= largestnum;

    
velocity[0] = ( origin2[0] * (get_pcvar_float(cvar_pump_force) * 3000) ) / get_entity_distance(victim attacker);
    
velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_pump_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;


Last edited by SaraAki; 04-24-2024 at 10:24.
SaraAki is offline
Tote
Senior Member
Join Date: Jul 2023
Old 04-24-2024 , 11:17   Re: Knife hit knockback
Reply With Quote #2

Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

#define PLUGIN    "Knife Knockback (when shot by one)"
#define VERSION    "1.0"
#define AUTHOR    "v3x & Chronic"

new cvar_pump_active , cvar_pump_force;

public plugin_init()
{
	register_plugin(PLUGIN , VERSION , AUTHOR);
	
	register_event("Damage" , "event_Damage" , "b" , "2>0");
	
	cvar_pump_active   = register_cvar("knife_knockback" , "1");
	cvar_pump_force       = register_cvar("knife_force"     , "10");
}

public event_Damage(id)
{
	static btn; btn = pev(id, pev_button)
	
	if(!get_pcvar_num(cvar_pump_active))
		return PLUGIN_CONTINUE;
	
	if(!is_user_alive(id))
		return PLUGIN_CONTINUE;
	
	new weapon , attacker = get_user_attacker(id , weapon);
	
	if(!is_user_alive(attacker))
		return PLUGIN_CONTINUE;
	
	if(weapon == CSW_KNIFE && btn & IN_ATTACK2)
	{
		new Float:vec[3];
		new Float:oldvelo[3];
		get_user_velocity(id, oldvelo);
		create_velocity_vector(id , attacker , vec);
		vec[0] += oldvelo[0];
		vec[1] += oldvelo[1];
		set_user_velocity(id , vec);
	}
	
	return PLUGIN_CONTINUE;
}

// 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_pump_force) * 3000) ) / get_entity_distance(victim , attacker);
	velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_pump_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;
}
u can use Ham Traceattack

Code:
#include <amxmodx>
#include <engine>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN    "Knife Knockback (when shot by one)"
#define VERSION    "1.0"
#define AUTHOR    "v3x & Chronic"

new cvar_pump_active , cvar_pump_force;

public plugin_init()
{
	register_plugin(PLUGIN , VERSION , AUTHOR);
	
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Post", 1)
	
	cvar_pump_active   = register_cvar("knife_knockback" , "1");
	cvar_pump_force       = register_cvar("knife_force"     , "10");
}

public fw_TraceAttack_Post(id, attacker)
{
	
	if(!get_pcvar_num(cvar_pump_active))
		return PLUGIN_CONTINUE;
	
	if(is_user_connected(attacker) && is_user_connected(id) && is_user_alive(id) && is_user_alive(attacker))
	{
		static btn; btn = pev(id, pev_button)
		new weapon; weapon = get_user_weapon(id)
		
		if(weapon == CSW_KNIFE && btn & IN_ATTACK2)
		{
			new Float:vec[3];
			new Float:oldvelo[3];
			get_user_velocity(id, oldvelo);
			create_velocity_vector(id , attacker , vec);
			vec[0] += oldvelo[0];
			vec[1] += oldvelo[1];
			set_user_velocity(id , vec);
		}
	}
	
	return PLUGIN_CONTINUE;
}

// 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_pump_force) * 3000) ) / get_entity_distance(victim , attacker);
	velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_pump_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;
}
Tote is offline
SaraAki
Member
Join Date: Nov 2022
Old 04-24-2024 , 12:24   Re: Knife hit knockback
Reply With Quote #3

I tested both versions and neither works.Thanks for helping me anyway.Any idea what to change?
SaraAki is offline
Tote
Senior Member
Join Date: Jul 2023
Old 04-24-2024 , 12:41   Re: Knife hit knockback
Reply With Quote #4

did i misunderstood?
u want it when hit with right mouse then let the knockback work?
Tote is offline
Tote
Senior Member
Join Date: Jul 2023
Old 04-24-2024 , 12:47   Re: Knife hit knockback
Reply With Quote #5

Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

#define PLUGIN    "Knife Knockback (when shot by one)"
#define VERSION    "1.0"
#define AUTHOR    "v3x & Chronic"

new cvar_pump_active , cvar_pump_force;

public plugin_init()
{
	register_plugin(PLUGIN , VERSION , AUTHOR);
	
	register_event("Damage" , "event_Damage" , "b" , "2>0");
	
	cvar_pump_active   = register_cvar("knife_knockback" , "1");
	cvar_pump_force       = register_cvar("knife_force"     , "10");
}

public event_Damage(id)
{
	static btn
	btn = pev(id, pev_button)
	
	if(!get_pcvar_num(cvar_pump_active))
		return PLUGIN_CONTINUE;
	
	if(!is_user_alive(id))
		return PLUGIN_CONTINUE;
	
	new weapon , attacker = get_user_attacker(id , weapon);
	
	if(!is_user_alive(attacker))
		return PLUGIN_CONTINUE;
	
	if(btn & IN_ATTACK2)
	{
		if(weapon == CSW_KNIFE)
		{
			new Float:vec[3];
			new Float:oldvelo[3];
			get_user_velocity(id, oldvelo);
			create_velocity_vector(id , attacker , vec);
			vec[0] += oldvelo[0];
			vec[1] += oldvelo[1];
			set_user_velocity(id , vec);
		}
	}
	
	return PLUGIN_CONTINUE;
}

// 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_pump_force) * 3000) ) / get_entity_distance(victim , attacker);
	velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_pump_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;
}
maybe this
also enable debug and check for errors on logs

Last edited by Tote; 04-24-2024 at 12:48.
Tote is offline
SaraAki
Member
Join Date: Nov 2022
Old 04-24-2024 , 13:59   Re: Knife hit knockback
Reply With Quote #6

Yes when hit with knife but only with right click.Last version also didnt work and no error in logs.
SaraAki is offline
Tote
Senior Member
Join Date: Jul 2023
Old 04-24-2024 , 14:26   Re: Knife hit knockback
Reply With Quote #7

Quote:
Originally Posted by SaraAki View Post
Yes when hit with knife but only with right click.Last version also didnt work and no error in logs.
does the plugin work without my edits?
Tote is offline
SaraAki
Member
Join Date: Nov 2022
Old 04-24-2024 , 15:56   Re: Knife hit knockback
Reply With Quote #8

Yes it work.
SaraAki is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 04-24-2024 , 17:22   Re: Knife hit knockback
Reply With Quote #9

alternative to stock, try...

PHP Code:
user_slap(index01
__________________
mlibre is offline
Ace67
Senior Member
Join Date: Sep 2020
Location: France
Old 04-25-2024 , 06:35   Re: Knife hit knockback
Reply With Quote #10

Quote:
Originally Posted by SaraAki View Post
This plugin activate knockback on knife damage.What i want is that knockback work only when damage is done with right mouse click.Also,maybe there is a better way to create knockback than using event_damage?

PHP Code:
#include <amxmodx>
#include <engine>

#define PLUGIN    "Knife Knockback (when shot by one)"
#define VERSION    "1.0"
#define AUTHOR    "v3x & Chronic"

new cvar_pump_active cvar_pump_force;

public 
plugin_init()
{
    
register_plugin(PLUGIN VERSION AUTHOR);

    
register_event("Damage" "event_Damage" "b" "2>0");

    
cvar_pump_active   register_cvar("knife_knockback" "1");
    
cvar_pump_force       register_cvar("knife_force"     "10");
}

public 
event_Damage(id)
{
    if(!
get_pcvar_num(cvar_pump_active))
        return 
PLUGIN_CONTINUE;

    if(!
is_user_alive(id))
        return 
PLUGIN_CONTINUE;

    new 
weapon attacker get_user_attacker(id weapon);

    if(!
is_user_alive(attacker))
        return 
PLUGIN_CONTINUE;

    if(
weapon == CSW_KNIFE)
    {
        new 
Float:vec[3];
        new 
Float:oldvelo[3];
        
get_user_velocity(idoldvelo);
        
create_velocity_vector(id attacker vec);
        
vec[0] += oldvelo[0];
        
vec[1] += oldvelo[1];
        
set_user_velocity(id vec);
    }

    return 
PLUGIN_CONTINUE;
}

// 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])>largestnumlargestnum floatabs(origin2[0]);
    if(
floatabs(origin2[1])>largestnumlargestnum floatabs(origin2[1]);

    
origin2[0] /= largestnum;
    
origin2[1] /= largestnum;

    
velocity[0] = ( origin2[0] * (get_pcvar_float(cvar_pump_force) * 3000) ) / get_entity_distance(victim attacker);
    
velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_pump_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;

I've added PlayerAttack instead of Damage it will detects both primary and secondary attacks. By checking the boolean parameter bPrimary, so it allows you to determine if the attack was a right-click (secondary attack) or not.

PHP Code:
#include <amxmodx>
#include <engine>

#define PLUGIN      "Knife Knockback (when shot by one)"
#define VERSION     "1.1"
#define AUTHOR      "v3x & Chronic"

new cvar_pump_force;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);

    
register_event("PlayerAttack""event_PlayerAttack""be");
    
    
cvar_pump_force    register_cvar("knife_force""10");
}

public 
event_PlayerAttack(idbool:bPrimary)
{
    new 
weapon get_user_weapon(id);
    
    
// It checks if the user using the knife and right-clicked 
    
if (weapon == CSW_KNIFE && !bPrimary)
    {
        new 
attacker get_user_attacker(idweapon);
        
        
// It will apply the knockback only if the attacker is alive and not dead.
        
if (is_user_alive(attacker))
        {
            
apply_knockback(idattacker);
        }
    }
}

public 
apply_knockback(victimattacker)
{
    new 
Float:vec[3];
    new 
Float:oldvelo[3];
    
get_user_velocity(victimoldvelo);
    
create_velocity_vector(victimattackervec);
    
vec[0] += oldvelo[0];
    
vec[1] += oldvelo[1];
    
set_user_velocity(victimvec);
}

// Stock by the one and only, Chronic :P
stock create_velocity_vector(victimattackerFloat:velocity[3])
{
    if (!
is_user_alive(victim) || !is_user_alive(attacker))
        return 
0;

    new 
Float:vicorigin[3];
    new 
Float:attorigin[3];
    
entity_get_vector(victimEV_VEC_originvicorigin);
    
entity_get_vector(attackerEV_VEC_originattorigin);

    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]) > largestnumlargestnum floatabs(origin2[0]);
    if (
floatabs(origin2[1]) > largestnumlargestnum floatabs(origin2[1]);

    
origin2[0] /= largestnum;
    
origin2[1] /= largestnum;

    
velocity[0] = (origin2[0] * (get_pcvar_float(cvar_pump_force) * 3000)) / get_entity_distance(victimattacker);
    
velocity[1] = (origin2[1] * (get_pcvar_float(cvar_pump_force) * 3000)) / get_entity_distance(victimattacker);
    if (
velocity[0] <= 20.0 || velocity[1] <= 20.0)
        
velocity[2] = random_float(200.0275.0);

    return 
1;

__________________
CS:CZ > CS 1.6

Last edited by Ace67; 04-25-2024 at 06:37.
Ace67 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:08.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode