Raised This Month: $32 Target: $400
 8% 

Solved Weapon Knockback Power


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ghost95v
Senior Member
Join Date: Apr 2014
Location: somewhere in universe
Old 09-15-2017 , 19:10   Weapon Knockback Power
Reply With Quote #1

Hello, i'm wondering how can i set properly the knockback power, for each weapon ent, in this way here...

Is this correct ?


PHP Code:


new g_currentweapon[33// player  current weapon id
new  cvar_knockbackpower;
new 
Float:kb_weapon_power[31] = { -1.0, ... };

// Weapon entity names
new const WEAPONENTNAMES[][] = { """weapon_p228""""weapon_scout",  "weapon_hegrenade""weapon_xm1014""weapon_c4""weapon_mac10",
            
"weapon_aug""weapon_smokegrenade""weapon_elite""weapon_fiveseven""weapon_ump45""weapon_sg550",
            
"weapon_galil""weapon_famas""weapon_usp""weapon_glock18""weapon_awp""weapon_mp5navy""weapon_m249",
            
"weapon_m3""weapon_m4a1""weapon_tmp""weapon_g3sg1""weapon_flashbang""weapon_deagle""weapon_sg552",
            
"weapon_ak47""weapon_knife""weapon_p90" }



new 
g_WeaponEnts[24][] =
{
    
"weapon_p228",
    
"weapon_scout",
    
"weapon_xm1014",
    
"weapon_mac10",
    
"weapon_aug",
    
"weapon_elite"
    "weapon_fiveseven"
,
    
"weapon_ump45",
    
"weapon_sg550",
    
"weapon_famas",
    
"weapon_galil",
    
"weapon_usp",
    
"weapon_glock18",
    
"weapon_awp",    
    
"weapon_mp5navy",
    
"weapon_m294",    
    
"weapon_m3",
    
"weapon_m4a1",
    
"weapon_tmp",
    
"weapon_g3sg1",
    
"weapon_deagle",
    
"weapon_sg552",
    
"weapon_ak47",
    
"weapon_p90"    
};
new 
g_Value[24][] =
{
    
"2.4",
    
"6.5",                  
    
"8.0",
    
"2.3",
    
"5.0",
    
"2.4"
    "2.0"
,
    
"2.4",
    
"5.3",
    
"5.5",
    
"5.5",
    
"2.2",
    
"2.0",
    
"10.0",    
    
"2.5",
    
"5.2",    
    
"8.0",
    
"5.0",
    
"2.4",
    
"6.5",
    
"5.3",
    
"5.0",
    
"6.0",
    
"2.0"    
};

public 
plugin_init()
{
        
cvar_knockbackpower register_cvar("weapon_knockback""1")
        
        new 
akey[64], values[64]

        for (
0sizeof(g_WeaponEnts); a++)
    {
        
formatex(keycharsmax(key), g_WeaponEnts[a])
        
    }

        for (
0sizeof(g_Values); a++)
    {
        
formatex(valuescharsmax(values), g_Values[a])
        
kb_weapon_power[cs_weapon_name_to_id(key)] = str_to_float(value)
    }
}

// Ham Trace Attack Forward
public fw_TraceAttack(victimattackerFloat:damageFloat:direction[3], tracehandledamage_type)
{
    
// Non-player damage or self damage
    
if (victim == attacker || !is_user_valid_connected(attacker))
        return 
HAM_IGNORED;


    
// Use weapon power on knockback calculation
    
if (get_pcvar_num(cvar_knockbackpower) && kb_weapon_power[g_currentweapon[attacker]] > 0.0)
        
xs_vec_mul_scalar(directionkb_weapon_power[g_currentweapon[attacker]], direction)

}

// Ham Weapon Deploy Forward
public fw_Item_Deploy_Post(weapon_ent)
{
    
// Get weapon's owner
    
static owner
    owner 
fm_cs_get_weapon_ent_owner(weapon_ent)
    
    
// Get weapon's id
    
static weaponid
    weaponid 
cs_get_weapon_id(weapon_ent)
    
    
// Store current weapon's id for reference
    
g_currentweapon[owner] = weaponid

}


stock cs_weapon_name_to_id(const weapon[])
{
    static 
i
    
for (0sizeof WEAPONENTNAMESi++)
    {
        if (
equal(weaponWEAPONENTNAMES[i]))
            return 
i;
    }
   
    return 
0;


is The code correct to set the weapon knockback power here, in plugin_init?


PHP Code:
public plugin_init() 

    
cvar_knockbackpower register_cvar("weapon_knockback""1"
         
    new 
akey[64], values[64

    for (
0sizeof(g_WeaponEnts); a++) 
    { 
        
formatex(keycharsmax(key), g_WeaponEnts[a]) 
         
    } 

    for (
0sizeof(g_Values); a++) 
    { 
        
formatex(valuescharsmax(values), g_Values[a]) 
        
kb_weapon_power[cs_weapon_name_to_id(key)] = str_to_float(value
    } 

__________________

Last edited by ghost95v; 09-16-2017 at 16:41.
ghost95v is offline
Send a message via Skype™ to ghost95v
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-15-2017 , 21:36   Re: Weapon Knockback Power
Reply With Quote #2

PHP Code:
/* Test this idk if it works correctly*/

new const Float:weapons_knockback[] = 
{
    
0.0,
    
2.4
    
6.5,                   
    
8.0
    
2.3
    
5.0
    
2.4
    
2.0
    
2.4
    
5.3
    
5.5
    
5.5
    
2.2
    
2.0
    
10.0,     
    
2.5
    
5.2,     
    
8.0
    
5.0
    
2.4
    
6.5
    
5.3
    
5.0
    
6.0
    
2.0
};

public 
plugin_init()
{
       
RegisterHam(Ham_TraceAttack"player""fw_TraceAttack"1)
}

// Ham Trace Attack Forward 
public fw_TraceAttack(victimattackerFloat:damageFloat:direction[3], tracehandledamage_type

    
// Non-player damage or self damage 
    
if (victim == attacker || !(32 >= victim >= 1) || !attacker
        return 
HAM_IGNORED;
    new 
wpnid get_user_weapon(attacker); 
    if(!(
24>= wpnid >= 1)) return HAM_IGNORED;
    new 
Float:vicVelocity[3];
    
pev(victimpev_velocity)
    
xs_vec_mul_scalar(directionweapons_knockback[wpnid], direction
    
xs_vec_add(vicVelocitydirectionvicVelocity)
    
set_pev(victimpev_velocityvecVelocity)
    return 
HAM_IGNORED;

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 09-18-2017 at 02:02.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
ghost95v
Senior Member
Join Date: Apr 2014
Location: somewhere in universe
Old 09-16-2017 , 16:41   Re: Weapon Knockback Power
Reply With Quote #3

Yes, works, Thank you!
__________________
ghost95v is offline
Send a message via Skype™ to ghost95v
kaya gaming
New Member
Join Date: Jan 2019
Old 01-14-2019 , 05:54   Re: Weapon Knockback Power
Reply With Quote #4

Quote:
Originally Posted by ghost95v View Post
Yes, works, Thank you!
how do you add the includes ?
i have this errors


Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

Error: Undefined symbol "vecVelocity" on line 53
Error: Number of arguments does not match definition on line 53

2 Errors.
Could not locate output file D:\cs 1.6 origin\cstrike\addons\amxmodx\plugins\weapon_ knockback.amx (compile failed).
kaya gaming is offline
Reply



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 15:04.


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