Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
|
02-26-2021
, 14:46
Re: How to know which side are the sound coming from
|
#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_distsndx, cvar_distsndy, cvar_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(PLUGIN, VERSION, "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_sound( Sound ); precache_model("models/chick.mdl"); }
public Debug(user) { new Float:pl_origin[3]; new Float:snd_origin[3]; new ent ///////////////////////////// 1 /////////////////////////////////////////////////// pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(5.5, "remove_ent", ent); ///////////////////////////////////////////////////////////////////////////////////
///////////////////////////// 2 /////////////////////////////////////////////////// pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(5.5, "remove_ent", ent); ///////////////////////////////////////////////////////////////////////////////////
///////////////////////////// 3 /////////////////////////////////////////////////// pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(5.5, "remove_ent", ent); ///////////////////////////////////////////////////////////////////////////////////
///////////////////////////// 4 /////////////////////////////////////////////////// pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(5.5, "remove_ent", ent); /////////////////////////////////////////////////////////////////////////////////// pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(5.5, "remove_ent", ent);/////// pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(5.5, "remove_ent", ent); // pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(5.5, "remove_ent", ent); //// pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_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_begin( index ? MSG_ONE : MSG_ALL, SVC_SPAWNSTATICSOUND, .player = index ); { write_coord_f( origin[0] ); write_coord_f( origin[1] ); write_coord_f( origin[2] ); write_short( soundIndex ); write_byte( clamp_byte( floatround( vol * 255 ) ) ); write_byte( clamp_byte( floatround( atten * 64 ) ) ); write_short( index ); write_byte( pitch ); write_byte( flags ); } 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.
__________________
Last edited by EFFx; 02-26-2021 at 23:17.
|
|