Raised This Month: $12 Target: $400
 3% 

How to know which side is the sound coming from


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-26-2021 , 14:17   How to know which side is the sound coming from
Reply With Quote #1

When someone is firing at me, how can I know which side are the bullets coming from?

Like, if i'm aiming anywhere and someone shoot me, I wanna return LEFT, RIGHT, BEHIND or IN FRONT information as origin, how can I?
__________________
• 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 15:15.
EFFx is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-26-2021 , 14:34   Re: How to know which side are the sound coming from
Reply With Quote #2

You mean you want to show a HUD shooting indictor on the screen ?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-26-2021 at 14:34.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-26-2021 , 14:37   Re: How to know which side are the sound coming from
Reply With Quote #3

This is pretty much what I've done so far, pretty hard coded but just an example:

PHP Code:
    new Float:fFireAngle[3]
    
pev(iPlayerpev_anglesfFireAngle)
    
    new 
iPlayers[32], iNum
    get_players
(iPlayersiNum"a")
    for(new 
iPlayerAroundFloat:fPlayerAngle[3], i;iNum;i++)
    {
        
iPlayerAround iPlayers[i// iPlayerAround is the ID of all players around me, I'm checking which side they are from my perspective.
        
        
pev(iPlayerAroundpev_anglesfPlayerAngle)
        
        if(
40.0 <= (fPlayerAngle[1] - fFireAngle[1]) <= 105.0)
        {
            
log_amx("Player is on my left"
        }
        else if(
120.0 <= (fPlayerAngle[1] - fFireAngle[1]) > -147.0)
        {
            
log_amx("Player is behind me")
        }
        else 
log_amx("Player is on my right")
        
console_print(iPlayer"%f %f %f"fPlayerAngle[0] - fFireAngle[0], fPlayerAngle[1] - fFireAngle[1], fPlayerAngle[2] - fFireAngle[2])
    } 

If I shot at you, I wanna know first if it's behind you, your left or right or in front of you, then create an entity based on that information.

If I shot at behind you, I wanna get an origin behind you and then spawn an entity there.
__________________
• 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 14:38.
EFFx is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-26-2021 , 14:45   Re: How to know which side are the sound coming from
Reply With Quote #4

let me get this correct you want to spawn an entity if you have shot behind the player the entity will spawn over there ? am i correct? and if you shot infront of the player the entity will spawn infront of him ?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-27-2021 , 03:16   Re: How to know which side is the sound coming from
Reply With Quote #6

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>
#include <xs>

#define PLUGIN "Check players position"
#define VERSION "1.0"
#define AUTHOR "Natsheh"

#define FOV 45.0

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /test""clcmd_test");
}


public 
clcmd_test(id)
{
    new 
Float:fPlayerView[3], Float:fPitchFloat:fStart[3];
    
pev(idpev_originfStart); fStart[2] = 0.0;
    
pev(idpev_v_anglefPlayerView);
    
    
// we only care about the pitch angle.
    
fPitch fPlayerView[1];
    
// fix the angle.
    
if(fPitch 0.0fPitch += 360.0;
    
    new 
players[32], pnumFloat:fOrigin[3];
    
get_players(playerspnum"a");
    
    for(new 
iszName[32], Float:fDirection[3], Float:fTargetPitchplayerpnumi++)
    {
        
player players[i];
        if(
player == id) continue;
        
pev(playerpev_originfOrigin);
        
fOrigin[2] = 0.0;
        
xs_vec_sub(fStart,fOrigin fDirection);
        
xs_vec_normalize(fDirectionfDirection);
        
vector_to_angle(fDirectionfDirection);
        
        
fTargetPitch fDirection[1];
        
// fix the angle.
        
if(fTargetPitch 0.0fTargetPitch += 360.0;
        
        if( 
isAngleBetween(fPitch FOVfPitch FOVfTargetPitch) )
        {
            
get_user_name(playerszName31);
            
client_print(idprint_chat"%s is behind!"szName);
        }
        else if( 
isAngleBetween(fPitch FOV 90.0fPitch FOV 90.0fTargetPitch) )
        {
            
get_user_name(playerszName31);
            
client_print(idprint_chat"%s is on your left!"szName);
        }
        else if( 
isAngleBetween(fPitch FOV 90.0fPitch FOV 90.0fTargetPitch) )
        {
            
get_user_name(playerszName31);
            
client_print(idprint_chat"%s is on your right!"szName);
        }
        else if( 
isAngleBetween(fPitch FOV 180.0fPitch FOV 180.0fTargetPitch) )
        {
            
get_user_name(playerszName31);
            
client_print(idprint_chat"%s is up ahead!"szName);
        }
    }
    
}

bool:isAngleBetween(Float:startFloat:endFloat:mid)
{
    if(
start 0.0start += 360.0;
    if(
end 0.0end += 360.0;
    
end = (end start) < 0.0 end start 360.0 end start;
    
mid = (mid start) < 0.0 mid start 360.0 mid start;
    return (
mid end); 

here i just made out this, it will tell you where're the players are depending on their position, hopefully it will help in somehow, i'm sure this is what you've wanted.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-27-2021 at 05:10.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-01-2021 , 16:09   Re: How to know which side is the sound coming from
Reply With Quote #7

Yeah it is, the main point is to create an entity where the information is coming (left, right, etc) and then emit an sound with it. Your code gets the information, all what is left is getting an origin to spawn an entity and then emit the sound there, so the player will know which side the sound is coming from, instead of just the message, y'know?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Reply


Thread Tools
Display Modes

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 12:28.


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