I want to play random sound in each different conditions, but it constantly calls for new RandomSound[64], I don't know if that was a proper way to call each of them
Making each audio groups for each condition, one condition play random sound within its group
PHP Code:
new g_WhizSounds[][] =
{
"misc/whizz1.wav",
"misc/whizz2.wav",
"misc/whizz3.wav",
"misc/whizz4.wav"
}
new g_SnapSounds[][] =
{
"misc/snap1.wav",
"misc/snap2.wav",
"misc/snap3.wav",
"misc/snap4.wav"
}
new g_ThudSounds[][] =
{
"misc/thud.wav"
}
Not sure if it's possible to pre-cache all of them at once with just a single 'for'
PHP Code:
public plugin_precache()
{
for (new i = 0; i < sizeof(g_WhizSounds); ++i)
{
precache_sound(g_WhizSounds[i]);
}
for (new i = 0; i < sizeof(g_SnapSounds); ++i)
{
precache_sound(g_SnapSounds[i]);
}
for (new i = 0; i < sizeof(g_ThudSounds); ++i)
{
precache_sound(g_ThudSounds[i]);
}
}
This is where it gets messy
PHP Code:
if (flDistance < get_pcvar_float(gs_thuddist) || !fm_is_ent_visible(id, target))
{
if (flDistance < get_pcvar_float(gs_snapdist) || !fm_is_ent_visible(id, target))
{
new RandomSound[64]
formatex(RandomSound, charsmax(RandomSound), "%s", g_SnapSounds[random(sizeof(g_SnapSounds))])
client_cmd(target, "spk %s", RandomSound)
continue;
}
new RandomSound[64]
formatex(RandomSound, charsmax(RandomSound), "%s", g_ThudSounds[random(sizeof(g_ThudSounds))])
client_cmd(target, "spk %s", RandomSound)
continue;
}
else if (flDistance < get_pcvar_float(gs_whizdist) || !fm_is_ent_visible(id, target))
{
continue;
}
new RandomSound[64]
formatex(RandomSound, charsmax(RandomSound), "%s", g_WhizSounds[random(sizeof(g_WhizSounds))])
client_cmd(target, "spk %s", RandomSound)
Notice the constant use of "new RandomSound[64]" and "formatex()", it looks un-optimizing to me, but I don't know how do I make it simpler, not even sure if calling them on each condition really helps
I tried putting "RandomSound[64]" before the conditional operators, but I fear I'll have some issues with "formatex()"
Is there another way of using 'spk' each audio group in an optimized way?