Raised This Month: $52 Target: $400
 13% 

Solved [HELP] Emit Sound on Coordinates


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 10-01-2019 , 14:38   [HELP] Emit Sound on Coordinates
Reply With Quote #1

So far emit_sound needs an entity to produce the sound from. I'm wondering if you can emit a sound in 3D space using just coordinates. Is there a separate function for this? Or module of sorts I don't know of?...
__________________

Last edited by hellmonja; 10-06-2019 at 05:48.
hellmonja is offline
thEsp
Veteran Member
Join Date: Aug 2017
Location: Albania
Old 10-01-2019 , 15:41   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #2

Not sure if it can be done with any module, but it's most likely impossible via raw AMXX. If I may ask, then why don't you normally emit sound throughout an entity?

Edit:
This might help. https://wiki.alliedmods.net/Half-Lif...AWNSTATICSOUND
__________________
Inactive on this forum due to work and busy personal life. Will definitely miss most of y'all, farewell!

Last edited by thEsp; 10-01-2019 at 15:46.
thEsp is offline
Smilex_Gamer
Member
Join Date: Apr 2017
Location: Portugal
Old 10-01-2019 , 15:41   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #3

I think what you want is something like this: https://forums.alliedmods.net/showthread.php?t=238457
(btw this is a module)

Quote:
Originally Posted by slLent View Post
/*
* id - Player index which play the sound.
* receiver - Player index which receives the sound.
* channel - Channel
* sample - Sample sound
* volume - Volume sound
* attn - Attenuation
* pitch - Pitch sound
* origin - Coordinates play the sound if "id" equal 0 (worldspawn)
*/

native emit_sound2(id,receiver,channel,const sample[],Float:volume,Float:attn,flags,pitch,Float: origin[3] = {0.0,0.0,0.0});
If the first argument is 0 (worldspawn), it will use coordinates that you insert in the last argument.
For example:
PHP Code:
#include <amxmodx>

native emit_sound2(idreceiverchannel, const sample[], Float:volumeFloat:attnflagspitchFloat:origin[3] = {0.0,0.0,0.0});

public 
plugin_init()
{
    
register_clcmd("say /emit2","cmdSound");
}

public 
cmdSound(id)
{
    new 
Float:Origin[3] = { 1.01.01.0 };
    
emit_sound2(00CHAN_AUTO"yoursound.wav"VOL_NORMATTN_NORM0PITCH_NORMOrigin);

Hope it helps you ;)

Last edited by Smilex_Gamer; 10-01-2019 at 15:50.
Smilex_Gamer is offline
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 10-01-2019 , 15:48   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #4

or a simple stock : ( not sure if it's most efficient way )
Code:
#include <amxmodx> #include <engine> public plugin_precache() {     precache_sound("test.wav") } public plugin_init() {     register_clcmd("say /play" , "play_sound") } public play_sound() {     emit_sound_2("test.wav" , 1.0 , -1087.9 , -155.9) } stock emit_sound_2(const szSound[] , Float:fOrigin0 , Float:fOrigin1 , Float:fOrigin2) {     new Float:fOrigin[3]     fOrigin[0] = fOrigin0     fOrigin[1] = fOrigin1     fOrigin[2] = fOrigin2     new ent = create_entity("info_target")     entity_set_origin(ent , fOrigin)     emit_sound(ent, CHAN_AUTO, szSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)     remove_entity(ent) }
LearninG is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 10-01-2019 , 15:50   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #5

Quote:
Originally Posted by Smilex_Gamer View Post
I think what you want is something like this: https://forums.alliedmods.net/showthread.php?t=238457
(btw this is a module)
Ah! Thank you! I've searched high and low but somehow still missed this one. I will try this first.

Quote:
Originally Posted by thEsp View Post
Not sure if it can be done with any module, but it's most likely impossible via raw AMXX. If I may ask, then why don't you normally emit sound throughout an entity?
I am going to attempt making a distant sounds for CS. When a player fires a weapon I will set coordinates in four directions (perhaps more, I don't know) relative to the player with fixed distances and heights then play the distant sound. Most modern shooters have this now, I wanna see if it's possible for grandpa GoldSrc...

EDIT:
Quote:
Originally Posted by LearninG View Post
or a simple stock : ( not sure if it's most efficient way )
Thank you, thank you! The more help the better. Even if I don't ultimately use the method I always learn a thing or two from them...
__________________

Last edited by hellmonja; 10-01-2019 at 15:52.
hellmonja is offline
Smilex_Gamer
Member
Join Date: Apr 2017
Location: Portugal
Old 10-01-2019 , 15:59   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #6

Quote:
Originally Posted by LearninG View Post
or a simple stock : ( not sure if it's most efficient way )
Code:
#include <amxmodx> #include <engine> public plugin_precache() {     precache_sound("test.wav") } public plugin_init() {     register_clcmd("say /play" , "play_sound") } public play_sound() {     emit_sound_2("test.wav" , 1.0 , -1087.9 , -155.9) } stock emit_sound_2(const szSound[] , Float:fOrigin0 , Float:fOrigin1 , Float:fOrigin2) {     new Float:fOrigin[3]     fOrigin[0] = fOrigin0     fOrigin[1] = fOrigin1     fOrigin[2] = fOrigin2     new ent = create_entity("info_target")     entity_set_origin(ent , fOrigin)     emit_sound(ent, CHAN_AUTO, szSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)     remove_entity(ent) }
Or maybe using this stock:
Quote:
Originally Posted by Arkshine View Post
PHP Code:
#include <amxmodx>
#include <fakemeta>

new const Sound[] = "ambience/Opera.wav";
new 
SoundIndex;

#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_precache()
{
    
SoundIndex precache_soundSound );
}

public 
plugin_init()
{
    
register_clcmd"say /test""ClientCommand_Test" );
}

public 
ClientCommand_Test( const client )
{
    new 
Float:origin[3];
    
pevclientpev_originorigin );
    
    
// Played from client, the music will follow the player
    // spawnStaticSound( client, null_vector, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0 );
    
    // Played from origin, the music won't stop when you are out of range.
    
spawnStaticSound0originSoundIndexVOL_NORMATTN_NORMPITCH_NORM, .flags );
}

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();

Smilex_Gamer is offline
DJEarthQuake
Senior Member
Join Date: Jan 2014
Location: Midwest
Old 10-03-2019 , 00:42   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #7

Quote:
Originally Posted by hellmonja View Post
I am going to attempt making a distant sounds for CS. When a player fires a weapon I will set coordinates in four directions (perhaps more, I don't know) relative to the player with fixed distances and heights then play the distant sound. Most modern shooters have this now

The Bullet Whizz plugin sounds very similar.
https://forums.alliedmods.net/showthread.php?p=255370
__________________
"It's not the actual programming that's interesting. But it's what you can accomplish with the end results that are important." -Dennis Ritchie
"Mathematics, rightly viewed, possesses not only truth, but supreme beauty a beauty cold and austere, like that of sculpture..." -Bertrand Russell
DJEarthQuake is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 10-04-2019 , 04:28   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #8

Quote:
Originally Posted by DJEarthQuake View Post
The Bullet Whizz plugin sounds very similar.
https://forums.alliedmods.net/showthread.php?p=255370
Bullet Whizz uses client_cmd unfortunately, so only the client itself will hear it. The sound must be heard in 3D space...
__________________
hellmonja is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 10-04-2019 , 04:34   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #9

Hello again, guys! After much fiddling, I've decided to go with Arkshines codes since it seems most convenient. So what's left is establishing the coordinates where the sounds will be emitted, which I've done as well with a test plugin. The problem is I'm not sure if my method is the most efficient way of doing this.

What I intend to do is when a player fires a gun, 4 points forming a cross relative to his coordinates will be the origin of the emitted sound. Height is fixed by the way, just +100.0 of the players coord. All I did was duplicate the code four times with 4 different combinations of coordinates:
PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta> 

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

#define DIST         300.0
#define SND_DIST     1230.0
#define SND_HEIGHT     100.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;
    
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(0.5"remove_ent"ent);
///////////////////////////////////////////////////////////////////////////////////

///////////////////////////// 2 ///////////////////////////////////////////////////    
    
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0] - DIST;
    
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(0.5"remove_ent"ent);
///////////////////////////////////////////////////////////////////////////////////

///////////////////////////// 3 ///////////////////////////////////////////////////    
    
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0];
    
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(0.5"remove_ent"ent);
///////////////////////////////////////////////////////////////////////////////////

///////////////////////////// 4 ///////////////////////////////////////////////////    
    
pev(userpev_originpl_origin); 
    
    
snd_origin[0] = pl_origin[0];
    
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(0.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();

Please don't mind the set_task function. It's just there so I have time to see where the chickens appear...
__________________
hellmonja is offline
DJEarthQuake
Senior Member
Join Date: Jan 2014
Location: Midwest
Old 10-04-2019 , 06:55   Re: [HELP] Emit Sound on Coordinates
Reply With Quote #10

Quote:
Originally Posted by hellmonja View Post
What I intend to do is when a player fires a gun, 4 points forming a cross relative to his coordinates will be the origin of the emitted sound. Height is fixed by the way, just +100.0 of the players coord. All I did was duplicate the code four times with 4 different combinations of coordinates:
Name:  sinister0009.jpg
Views: 47
Size:  95.4 KB

So you want a sound to match muzzle blast? In other words the opposite of Bullet Whizz which is on the receiving end.

Quote:
Originally Posted by hellmonja View Post
So far emit_sound needs an entity to produce the sound from. I'm wondering if you can emit a sound in 3D space using just coordinates. Is there a separate function for this? Or module of sorts I don't know of?...
The sound doesn't need 4 more ents when you already have 1, the player there firing the weapon.

These 2 figures show what 50 looks like from the abstract from either using pev_origin or get_user_origin. Former is standing over the head while other is piggy back ride at 50.

Name:  crossfire-mdl0013.jpg
Views: 46
Size:  87.0 KB
Code:
        new Float:origin[3];         pev(id,pev_origin,origin);         new Float:mins[3], Float:maxs[3]         mins[0] = origin[0] - 15.0         mins[1] = origin[1] - 15.0         mins[2] = origin[2] + 25.0         maxs[0] = origin[0] + 15.0         maxs[1] = origin[1] + 15.0         maxs[2] = origin[2] + 2.0         message_begin(0,23);         write_byte(TE_BOX);         write_coord(floatround(mins[0]));         write_coord(floatround(mins[1]));         write_coord(floatround(mins[2]));         write_coord(floatround(maxs[0]));         write_coord(floatround(maxs[1]));         write_coord(floatround(maxs[2]));         write_short(random_num(500,1000));   //(life in 0.1's)         write_byte(random_num(50,255));     //(red)         write_byte(random_num(50,255));   //(green)         write_byte(random_num(0,255));   //(blue)         message_end();
Name:  op4ctf_dam0029.jpg
Views: 46
Size:  15.3 KB

By the way 5 sounds being fired off per round may cause performance issues. Emit already emits. Quit while you are ahead. The code you are using accomplishes the same as emit_sound but it is a while lot more complex and easier to crash sending messages instead of simply using emit_sound. You are over-complicating not using emit_sound just to reinvent the wheel with this. The sound still passes through the player just a few coordinates away. So then, it is here, instead of there. The oth dimension {0,0,0} is what you see 99.9% of the code around the world over. Just a dot. Moving outside the box is not that complicated. You have your chickens to help you do that now.

Use MSG_PAS as it will use least resources. MSG_ONE sends it to people on other side of map who can't hear it anyway as well as increase crash likelihood down the line.
__________________
"It's not the actual programming that's interesting. But it's what you can accomplish with the end results that are important." -Dennis Ritchie
"Mathematics, rightly viewed, possesses not only truth, but supreme beauty a beauty cold and austere, like that of sculpture..." -Bertrand Russell

Last edited by DJEarthQuake; 10-04-2019 at 06:57.
DJEarthQuake 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 23:28.


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