View Single Post
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-26-2021 , 14:46   Re: How to know which side are the sound coming from
Reply With Quote #5

Yes, the entity will spawn depending of the sound origin, not the end point of the bullet.
If the sound is coming from behind, the entity will spawn behind. If the sound is coming from my left side, it'll spawn on my left side.

Edit:

Took this code - https://forums.alliedmods.net/showpo...48&postcount=9
And this is pretty much the closest thing I got:

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

#define PLUGIN "Distant Sounds Test"
#define VERSION "1.0"

#define DIST         50.0
#define SND_DIST     1230.0
#define SND_HEIGHT     15.0

new const Sound[] = "misc/killChicken.wav";
new 
SoundIndex;
new 
cvar_distsndxcvar_distsndycvar_distsndz;

#define clamp_byte(%1)     ( clamp( %1, 0, 255 ) ) 
#define write_coord_f(%1)  ( engfunc( EngFunc_WriteCoord, %1 ) )
#define null_vector        ( Float:{ 0.0, 0.0, 0.0 } )

public plugin_init()
{
    
register_plugin(PLUGINVERSION"Arkshine & hellmonja");
    
    
register_concmd("debug""Debug");
    
    
cvar_distsndx register_cvar("ds_x""0.0");
    
cvar_distsndy register_cvar("ds_y""0.0");
    
cvar_distsndz register_cvar("ds_z""0.0");
}

public 
plugin_precache()
{
    
SoundIndex precache_soundSound );
    
precache_model("models/chick.mdl");
}

public 
Debug(user)
{
    new 
Float:pl_origin[3];
    new 
Float:snd_origin[3];
    new 
ent
    
///////////////////////////// 1 ///////////////////////////////////////////////////    
    
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0] + (DIST 25.0);
    
snd_origin[1] = pl_origin[1];
    
snd_origin[2] = pl_origin[2] + SND_HEIGHT;
    
    
ent create_entity("info_target")
    
entity_set_origin(ent snd_origin)
    
entity_set_model(ent,"models/chick.mdl");
    
    
spawnStaticSound(0snd_originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags 0);

    
set_task(5.5"remove_ent"ent);
///////////////////////////////////////////////////////////////////////////////////

///////////////////////////// 2 ///////////////////////////////////////////////////    
    
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0] - (DIST 25.0);
    
snd_origin[1] = pl_origin[1];
    
snd_origin[2] = pl_origin[2] + SND_HEIGHT;
    
    
ent create_entity("info_target")
    
entity_set_origin(ent snd_origin)
    
entity_set_model(ent,"models/chick.mdl");
    
    
spawnStaticSound(0snd_originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags 0);

    
set_task(5.5"remove_ent"ent);
///////////////////////////////////////////////////////////////////////////////////

///////////////////////////// 3 ///////////////////////////////////////////////////    
    
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0];
    
snd_origin[1] = pl_origin[1] + (DIST 25.0);
    
snd_origin[2] = pl_origin[2] + SND_HEIGHT;
    
    
ent create_entity("info_target")
    
entity_set_origin(ent snd_origin)
    
entity_set_model(ent,"models/chick.mdl");
    
    
spawnStaticSound(0snd_originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags 0);

    
set_task(5.5"remove_ent"ent);
///////////////////////////////////////////////////////////////////////////////////

///////////////////////////// 4 ///////////////////////////////////////////////////    
    
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0];
    
snd_origin[1] = pl_origin[1] - (DIST 25.0);
    
snd_origin[2] = pl_origin[2] + SND_HEIGHT;
    
    
ent create_entity("info_target")
    
entity_set_origin(ent snd_origin)
    
entity_set_model(ent,"models/chick.mdl");
    
    
spawnStaticSound(0snd_originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags 0);

    
set_task(5.5"remove_ent"ent);
///////////////////////////////////////////////////////////////////////////////////
    
    
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0] + DIST;
    
snd_origin[1] = pl_origin[1] + DIST;
    
snd_origin[2] = pl_origin[2] + SND_HEIGHT;
    
    
ent create_entity("info_target")
    
entity_set_origin(ent snd_origin)
    
entity_set_model(ent,"models/chick.mdl");
    
    
spawnStaticSound(0snd_originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags 0);

    
set_task(5.5"remove_ent"ent);///////
    
       
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0] - DIST;
    
snd_origin[1] = pl_origin[1] - DIST;
    
snd_origin[2] = pl_origin[2] + SND_HEIGHT;
    
    
ent create_entity("info_target")
    
entity_set_origin(ent snd_origin)
    
entity_set_model(ent,"models/chick.mdl");
    
    
spawnStaticSound(0snd_originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags 0);

    
set_task(5.5"remove_ent"ent);
    
//
    
       
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0] - DIST;
    
snd_origin[1] = pl_origin[1] + DIST;
    
snd_origin[2] = pl_origin[2] + SND_HEIGHT;
    
    
ent create_entity("info_target")
    
entity_set_origin(ent snd_origin)
    
entity_set_model(ent,"models/chick.mdl");
    
    
spawnStaticSound(0snd_originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags 0);

    
set_task(5.5"remove_ent"ent);
    
////
       
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0] + DIST;
    
snd_origin[1] = pl_origin[1] - DIST;
    
snd_origin[2] = pl_origin[2] + SND_HEIGHT;
    
    
ent create_entity("info_target")
    
entity_set_origin(ent snd_origin)
    
entity_set_model(ent,"models/chick.mdl");
    
    
spawnStaticSound(0snd_originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags 0);

    
set_task(5.5"remove_ent"ent);
    
//    new Float:dist = entity_range(user, ent);
    //    client_print(user, print_chat, "DIST: %f", dist);

}

public 
remove_ent(ent)
{
    
remove_entity(ent);
}

stock spawnStaticSound( const index, const Float:origin[3], const soundIndex, const Float:vol, const Float:atten, const pitch, const flags 

    
message_beginindex MSG_ONE MSG_ALLSVC_SPAWNSTATICSOUND, .player index );
    {
        
write_coord_forigin[0] ); 
        
write_coord_forigin[1] ); 
        
write_coord_forigin[2] );
        
write_shortsoundIndex );
        
write_byteclamp_bytefloatroundvol 255 ) ) );
        
write_byteclamp_bytefloatroundatten 64 ) ) );
        
write_shortindex );        
        
write_bytepitch ); 
        
write_byteflags );   
    }
    
message_end();

This code creates 8 entities on each side of player's ear and gets which entity is the closest to the player that used the command. As soon as the closes entity ID is get, it emits a sound. Although it's not what I was reaching, it is good already.

Sadly, this module is not working for me, dunno why, otherwise it could be used and then only one player could hear the firing sound depending of it's position and angle.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-26-2021 at 23:17.
EFFx is offline