Raised This Month: $ Target: $400
 0% 

Solved Detecting If A Weapon Is Silenced


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 12-12-2015 , 11:39   Detecting If A Weapon Is Silenced
Reply With Quote #1

Well, like the title says, is there a way to detect if a weapon is silenced? or has the silencer attached to it?...

Last edited by hellmonja; 06-25-2017 at 04:25. Reason: Solved...
hellmonja is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 12-12-2015 , 11:54   Re: [HELP] Detecting If A Weapon Is Silenced
Reply With Quote #2

Quote:
Originally Posted by hellmonja View Post
Well, like the title says, is there a way to detect if a weapon is silenced? or has the silencer attached to it?...
https://forums.alliedmods.net/showthread.php?p=891661

Are u banned on google search ?
siriusmd99 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-12-2015 , 11:58   Re: [HELP] Detecting If A Weapon Is Silenced
Reply With Quote #3

http://amxmodx.org/api/cstrike/cs_get_weapon_silen
__________________
HamletEagle is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 12-13-2015 , 01:41   Re: [HELP] Detecting If A Weapon Is Silenced
Reply With Quote #4

Hey thanks! I'm doing this:

PHP Code:
    if (cs_get_weapon_silen(CSW_MAKAROV))
    {
        
set_weapon_anim(invokerSHOOT_SILEN)
        
emit_sound(invokerCHAN_WEAPONFIRE_SOUNDVOL_NORMATTN_NORM0PITCH_NORM)
    }
    else
    {
        
set_weapon_anim(invokerSHOOT_ANIM)
        
emit_sound(invokerCHAN_WEAPONFIRE_SOUNDVOL_NORMATTN_NORM0PITCH_NORM)
    } 
but it doesn't seem to work. I'm trying to replace the shooting anim and sound on an extra weapon when it's silenced. but what happens with this is, the both anim and sound just don't work...
hellmonja is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-13-2015 , 11:38   Re: [HELP] Detecting If A Weapon Is Silenced
Reply With Quote #5

You are using it incorrectly. You must pass the weapon entity to the cs_get/set_weapon_silen() function.

PHP Code:
const m_pActiveItem 373;

if ( 
cs_get_weapon_silenget_pdata_cbaseinvoker m_pActiveItem ) ) ) 
You should also review the function details to make sure it will work as you want. Specifically, are you checking this condition only when it is the M4A1 or USP? You should also see an error in your log based on the code you posted.
Code:
Note Only the USP and M4A1 can return 1 as they are the only guns in the game that have a silenced fire mode. Note This native does not check that the provided entity is actually a weapon entity. It will return incorrect values for non-weapon entities. Return 1 if the weapon is in silenced mode, 0 otherwise Error If an invalid entity index or a client index is provided, an error will be thrown.

Here you can see it will only work for those two weapons.
PHP Code:
static cell AMX_NATIVE_CALL cs_get_weapon_silenced(AMX *amxcell *params// cs_get_weapon_silenced(index); = 1 param
{
    
// Is weapon silenced? Does only work on M4A1 and USP.
    // params[1] = weapon index

    // Valid entity should be within range
    
CHECK_NONPLAYER(params[1]);

    
// Make into edict pointer
    
edict_t *pWeapon INDEXENT(params[1]);

    
int weapontype = *((int *)pWeapon->pvPrivateData OFFSET_WEAPONTYPE);
    
int *silencemode = ((int *)pWeapon->pvPrivateData OFFSET_SILENCER_FIREMODE);
    switch (
weapontype) {
        case 
CSW_M4A1:
            if (*
silencemode M4A1_SILENCED)
                return 
1;
        case 
CSW_USP:
            if (*
silencemode USP_SILENCED)
                return 
1;
    }

    
// All else return 0.
    
return 0;

__________________

Last edited by Bugsy; 12-13-2015 at 11:50.
Bugsy 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 18:15.


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