Raised This Month: $ Target: $400
 0% 

Switch CSW_WEAPON


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-11-2016 , 10:06   Switch CSW_WEAPON
Reply With Quote #1

I registered multiple primary attacks into one function like this:

PHP Code:
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_famas""eventPrimaryAttack"1)
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_ak47""eventPrimaryAttack"1)
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_m4a1""eventPrimaryAttack"1
And in the function I'm trying to play a different sound for each one:

PHP Code:
public eventPrimaryAttack(iWeapon)
{
    new 
szSound[128], iClipiAmmoid pev(iWeaponpev_owner)
    
get_user_weapon(idiClipiAmmo)
    
    if(
iClip)
    {
        switch(
iWeapon)
        {
            case 
CSW_FAMASformatex(szSoundcharsmax(szSound), "%s"SOUND_FAMAS)
        }
    }
    
    
emit_sound(idCHAN_WEAPONszSound1.0ATTN_NORM0PITCH_HIGH)

The switch code doesn't work. iWeapon doesn't seem to respond with CSW_ constants. How do I check the weapon from this code and is this a good way to do it? I know there isn't a 100% efficient way to do this.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
xxxperts
Senior Member
Join Date: Oct 2013
Location: India
Old 04-11-2016 , 10:27   Re: Switch CSW_WEAPON
Reply With Quote #2

Are you trying to play some different sound with different guns ?

EDIT: If yes then please check out this post and if you got time then see whole theard you will find something useful
__________________
All my work is here

Last edited by xxxperts; 04-11-2016 at 10:28. Reason: update
xxxperts is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-11-2016 , 11:46   Re: Switch CSW_WEAPON
Reply With Quote #3

What you get from the forward is the weapon entity index, not the CSW_* index. You have to use cs_get_weapon_id to get what you want.
__________________

Last edited by HamletEagle; 04-11-2016 at 11:46.
HamletEagle is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 04-11-2016 , 12:22   Re: Switch CSW_WEAPON
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
What you get from the forward is the weapon entity index, not the CSW_* index. You have to use cs_get_weapon_id to get what you want.
Yes, but in his case (he is using get_user_weapon to get clip and ammo) he doesn't need to use cs_get_weapon_id because cs_get_user_weapon returns weapon id in CSW_* format.
And you would better use copy instead of formatex because you are not formating string , just copying.

But i don't understand why you are creating new string, then copying the sound to it and then using emit sound.

Just use emit sound directly with your sound.

Here's the code:

PHP Code:
public eventPrimaryAttack(iWeapon)
{
    new 
iClipiAmmoid pev(iWeaponpev_owner)
    
// You can add here:  if(!is_user_connected(id) || !is_user_alive(id)) return HAM_IGNORED;
   // But i don't know if it's necessary.
  
    
iWeapon get_user_weapon(idiClipiAmmo)
    
    if(
iClip)
    {
        switch(
iWeapon)
        {
            case 
CSW_FAMASemit_sound(idCHAN_WEAPONSOUND_FAMAS1.0ATTN_NORM0PITCH_HIGH)
            case 
CSW_M4A1emit_sound(idCHAN_WEAPONSOUND_M4A11.0ATTN_NORM0PITCH_HIGH)
            case 
CSW_AK47emit_sound(idCHAN_WEAPONSOUND_M4A11.0ATTN_NORM0PITCH_HIGH)
        }
    }
    
    


Last edited by siriusmd99; 04-11-2016 at 12:42.
siriusmd99 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-11-2016 , 15:02   Re: Switch CSW_WEAPON
Reply With Quote #5

@xxxperts: I went over a bunch of threads like that, thank you for that one as well.
@siriusmd99: Works like a charm. Thank you!
OciXCrom is offline
Send a message via Skype™ to OciXCrom
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 04-11-2016 , 15:43   Re: Switch CSW_WEAPON
Reply With Quote #6

Ham_Weapon_PrimaryAttack is called by the entity, not weaponID as stated above.

Last edited by SpeeDeeR; 04-11-2016 at 15:45.
SpeeDeeR is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-13-2016 , 07:01   Re: Switch CSW_WEAPON
Reply With Quote #7

I'm using siriusmd99's code and I have a little issue with it. When I hold down the attack button on a pistol (deagle, fiveseven etc), it spams the sound repeatedly. The other weapons work fine. How to I prevent this from happening?
OciXCrom is offline
Send a message via Skype™ to OciXCrom
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-05-2016 , 14:24   Re: Switch CSW_WEAPON
Reply With Quote #8

Up. I'm still haven't found a solution for the problem in my last post.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 06:17.


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