AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ HELP ] Change weapon primary attack sound? (https://forums.alliedmods.net/showthread.php?t=273842)

CrazY. 10-27-2015 13:19

[ HELP ] Change weapon primary attack sound?
 
How to block the primary attack sound of weapon and add a custom sound?
I searched the forum and found it, just not quite know how to use, for example:

PHP Code:

#include < amxmodx >
#include < hamsandwich >

new const FIRE_SOUND[][] = {"weapons/weapon_fire.wav"}

public 
plugin_init()
{
    
register_plugin("Plugin""Version""Author")
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_name""fw_PrimaryAttack"1)
}

public 
plugin_precache()
{
    for(new 
0sizeof (FIRE_SOUND); i++)
    {
        
precache_sound(FIRE_SOUND[i])
    }
}

public 
fw_PrimaryAttack(weapon)
{
    new 
player get_pdata_cbase(Weapon414)

    if(
g_has_weapon[player])
    {
        
emit_sound(playerCHAN_WEAPONFIRE_SOUND[0], VOL_NORMATTN_NORM0PITCH_NORM)
    }



silentscope 10-27-2015 13:35

Re: [ HELP ] Change weapon primary attack sound?
 
you can't just replace weapon sounds except knife so easily, the only option is to create weapon from scratch, and this would take ages if you are not an experienced coder

Depresie 10-29-2015 10:39

Re: [ HELP ] Change weapon primary attack sound?
 
ahm.. you just have to put up at the FIRE_SOUND the path to your sound...
and at register ham instead of weapon_name you write the weapons name... for example weapon_m4a1
that's all

CrazY. 10-29-2015 10:50

Re: [ HELP ] Change weapon primary attack sound?
 
I know about weapon_name, i dont understand about FIRE_SOUND, give me a example.

redivcram 10-29-2015 14:40

Re: [ HELP ] Change weapon primary attack sound?
 
PHP Code:

#define FIRE_SOUND "sound/blah/blah.wav" //Your folder/sound file replaces blah 


HamletEagle 10-29-2015 15:05

Re: [ HELP ] Change weapon primary attack sound?
 
Quote:

Originally Posted by redivcram (Post 2357804)
PHP Code:

#define FIRE_SOUND "sound/blah/blah.wav" //Your folder/sound file replaces blah 


For wav files you must not add sound/ in path.

CrazY. 10-29-2015 15:09

Re: [ HELP ] Change weapon primary attack sound?
 
Hum, this:

PHP Code:

#include < amxmodx > 
#include < hamsandwich > 

#define FIRE_SOUND "weapons/weapon_fire.wav"

public plugin_init() 

    
register_plugin("Plugin""Version""Author"
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_name""fw_PrimaryAttack"1


public 
plugin_precache() 
{
        
precache_sound(FIRE_SOUND)


public 
fw_PrimaryAttack(weapon

    new 
player get_pdata_cbase(Weapon414

    if(
g_has_weapon[player]) 
    { 
        
emit_sound(playerCHAN_WEAPONFIRE_SOUNDVOL_NORMATTN_NORM0PITCH_NORM
    } 



Bugsy 10-29-2015 22:33

Re: [ HELP ] Change weapon primary attack sound?
 
Ham_PrimaryAttack is not a good way to do this because if you hold down attack, you hear the sound repeat itself before the sound completes and it even does it when you are not actually shooting. I don't think there's a simple way to do this because the sound is produced on the client side.

Using code written by VEN to detect weapon fire, you can play a sound over the normal fire sound. In this example, I used the M4A1 fire sound for all weapons. This can be modified to use a different fire sound for each weapon.

Not thoroughly tested:
PHP Code:


#include <amxmodx>
#include <fakemeta>

new const FireSound[] = "weapons/m4a1-1.wav";

new const 
g_guns_events[][] = 
{
    
"events/awp.sc",
    
"events/g3sg1.sc",
    
"events/ak47.sc",
    
"events/scout.sc",
    
"events/m249.sc",
    
"events/m4a1.sc",
    
"events/sg552.sc",
    
"events/aug.sc",
    
"events/sg550.sc",
    
"events/m3.sc",
    
"events/xm1014.sc",
    
"events/usp.sc",
    
"events/mac10.sc",
    
"events/ump45.sc",
    
"events/fiveseven.sc",
    
"events/p90.sc",
    
"events/deagle.sc",
    
"events/p228.sc",
    
"events/glock18.sc",
    
"events/mp5n.sc",
    
"events/tmp.sc",
    
"events/elite_left.sc",
    
"events/elite_right.sc",
    
"events/galil.sc",
    
"events/famas.sc"
};

new 
g_guns_eventids_bitsum g_fwid g_max_clients;

public 
plugin_precache() 
{
    
precache_soundFireSound );
    
    
g_fwid register_forwardFM_PrecacheEvent "fwPrecacheEvent" );
}

public 
fwPrecacheEventtype , const name[] ) 
{
    for (new 
0sizeof g_guns_events; ++i
    {
        if ( 
equalg_guns_events] , name ) ) 
        {
            
g_guns_eventids_bitsum |= ( << get_orig_retval() );
            return 
FMRES_HANDLED;
        }
    }
    
    return 
FMRES_IGNORED;
}

public 
plugin_init() 
{
    
unregister_forwardFM_PrecacheEvent g_fwid );
    
register_forwardFM_PlaybackEvent "fwPlaybackEvent" );
    
    
g_max_clients global_get(glb_maxClients);
}

public 
fwPlaybackEventflags invoker eventid 
{
    if ( !( 
g_guns_eventids_bitsum & ( << eventid ) ) || !( <= invoker <= g_max_clients ) )
        return 
FMRES_IGNORED;
    
    
emit_soundinvoker CHAN_WEAPON FireSound VOL_NORM ATTN_NORM PITCH_NORM );
    
    return 
FMRES_HANDLED;



CrazY. 10-31-2015 09:57

Re: [ HELP ] Change weapon primary attack sound?
 
Bugsy, this code not worked :nono:.

Bugsy 10-31-2015 10:29

Re: [ HELP ] Change weapon primary attack sound?
 
It does, but inconsistently. I noticed this after the fact. I'll take a look when I have time.


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

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