AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [HELP] Emit Sound on Coordinates (https://forums.alliedmods.net/showthread.php?t=318943)

hellmonja 10-01-2019 13:38

[HELP] Emit Sound on Coordinates
 
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?...

thEsp 10-01-2019 14:41

Re: [HELP] Emit Sound on Coordinates
 
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

Smilex_Gamer 10-01-2019 14:41

Re: [HELP] Emit Sound on Coordinates
 
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 (Post 2123125)
/*
* 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 ;)

LearninG 10-01-2019 14:48

Re: [HELP] Emit Sound on Coordinates
 
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) }

hellmonja 10-01-2019 14:50

Re: [HELP] Emit Sound on Coordinates
 
Quote:

Originally Posted by Smilex_Gamer (Post 2668518)
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 (Post 2668517)
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 (Post 2668519)
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...

Smilex_Gamer 10-01-2019 14:59

Re: [HELP] Emit Sound on Coordinates
 
Quote:

Originally Posted by LearninG (Post 2668519)
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 (Post 1414981)
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();




DJEarthQuake 10-02-2019 23:42

Re: [HELP] Emit Sound on Coordinates
 
Quote:

Originally Posted by hellmonja (Post 2668520)
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

hellmonja 10-04-2019 03:28

Re: [HELP] Emit Sound on Coordinates
 
Quote:

Originally Posted by DJEarthQuake (Post 2668641)
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 10-04-2019 03:34

Re: [HELP] Emit Sound on Coordinates
 
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...

DJEarthQuake 10-04-2019 05:55

Re: [HELP] Emit Sound on Coordinates
 
3 Attachment(s)
Quote:

Originally Posted by hellmonja (Post 2668748)
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:


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 (Post 2668510)
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.

Attachment 177620
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();
Attachment 177622

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.


All times are GMT -4. The time now is 02:49.

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