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_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;
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(0.5, "remove_ent", ent);
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////// 2 ///////////////////////////////////////////////////
pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(0.5, "remove_ent", ent);
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////// 3 ///////////////////////////////////////////////////
pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_NORM, .flags = 0);
set_task(0.5, "remove_ent", ent);
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////// 4 ///////////////////////////////////////////////////
pev(user, pev_origin, pl_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(0, snd_origin, SoundIndex, VOL_NORM, ATTN_NORM, PITCH_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_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();
}
Please don't mind the set_task function. It's just there so I have time to see where the chickens appear...
__________________