Raised This Month: $ Target: $400
 0% 

How do I use client_cmd(spk) properly?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Agent3554
Junior Member
Join Date: Aug 2020
Old 05-28-2021 , 09:00   How do I use client_cmd(spk) properly?
Reply With Quote #1

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 
0sizeof(g_WhizSounds); ++i)
    {    
        
precache_sound(g_WhizSounds[i]);
    }
    for (new 
0sizeof(g_SnapSounds); ++i)
    {    
        
precache_sound(g_SnapSounds[i]);
    }
    for (new 
0sizeof(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(idtarget))
{
    if (
flDistance get_pcvar_float(gs_snapdist) || !fm_is_ent_visible(idtarget))
    {
        new 
RandomSound[64]
        
formatex(RandomSoundcharsmax(RandomSound), "%s"g_SnapSounds[random(sizeof(g_SnapSounds))]) 
        
client_cmd(target"spk %s"RandomSound)
        continue;
    }
    new 
RandomSound[64]
    
formatex(RandomSoundcharsmax(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(idtarget))
{
    continue;
}
new 
RandomSound[64]
formatex(RandomSoundcharsmax(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?

Last edited by Agent3554; 05-28-2021 at 09:06.
Agent3554 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-28-2021 , 09:28   Re: How do I use client_cmd(spk) properly?
Reply With Quote #2

You don't need formatex.
Code:
new RandomSound[64]
        formatex(RandomSound, charsmax(RandomSound), "%s", g_SnapSounds[random(sizeof(g_SnapSounds))]) 
        client_cmd(target, "spk %s", RandomSound)

Code:
        client_cmd(target, "spk %s", g_SnapSounds[random(sizeof(g_SnapSounds))])
As for the loop, you did right. There is no workaround.
__________________








CrazY. is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 05-28-2021 , 09:31   Re: How do I use client_cmd(spk) properly?
Reply With Quote #3

Code:
client_cmd(target, "spk %s", g_SnapSounds[random(sizeof(g_SnapSounds)-1)])

no idea why you're using formatex to copy the string in the first place

Last edited by jimaway; 05-28-2021 at 09:44.
jimaway is offline
Agent3554
Junior Member
Join Date: Aug 2020
Old 05-28-2021 , 09:42   Re: How do I use client_cmd(spk) properly?
Reply With Quote #4

Quote:
Originally Posted by CrazY. View Post
You don't need formatex.
Code:
new RandomSound[64]
        formatex(RandomSound, charsmax(RandomSound), "%s", g_SnapSounds[random(sizeof(g_SnapSounds))]) 
        client_cmd(target, "spk %s", RandomSound)

Code:
        client_cmd(target, "spk %s", g_SnapSounds[random(sizeof(g_SnapSounds))])
As for the loop, you did right. There is no workaround.
Quote:
Originally Posted by jimaway View Post
Code:
client_cmd(target, "spk %s", random(sizeof(g_SnapSounds)-1))

no idea why you're using formatex to copy the string in the first place
Thank you very much!
Agent3554 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 02:35.


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