AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optomize (https://forums.alliedmods.net/showthread.php?t=188650)

Liverwiz 06-28-2012 21:27

Optomize
 
You would know better than me. Is this good code? I've been going back and forth on a few different methods of using a string pcvar as a toggle for a sound. Having the sound path if its on, or 0 if its going to be off. This is what i have....

Code:
new pm_sound[32] public plugin_precache() {     new sound_pcvar = register_cvar("pm_sound", "buttons/blip2.wav")     get_pcvar_string(sound_pcvar, pm_sound, charsmax(pm_sound) )         if(pm_sound[0])         precache_sound(pm_sound) } // using the sound....     if(pm_sound[0])         client_cmd(reciever, "speak ^"sound/%s^"", pm_sound)

Torn between that and using a toggle global var. in such a manner....
Code:
(!is_str_num(pm_sound)) ? sound_toggle = 0 : precache_sound(pm_sound)
initializing sound_toggle = 1

or any other ideas.....I'm open to them.

YamiKaitou 06-28-2012 21:34

Re: Optomize
 
You can only precache during plugin_precache. If you plan on having a toggle for the sound, it is best to always precache the sound and then just use the toggle to determine if you should play it.

Liverwiz 06-28-2012 21:40

Re: Optomize
 
Quote:

Originally Posted by YamiKaitou (Post 1738617)
You can only precache during plugin_precache. If you plan on having a toggle for the sound, it is best to always precache the sound and then just use the toggle to determine if you should play it.

Unless i misunderstood you....i already took that into account. And thus handled all cvar actions within plugin_precache. Checking to see if it is an actual path, or a number. Then precaching it when proper.

I'm mostly asking if i should keep grabbing pm_sound and seeing if its a number. Or set an actual toggle var. Or if there's a better way to do it. If i misunderstood, could you please provide code?

ConnorMcLeod 06-29-2012 00:55

Re: Optomize
 
FYI, you don't have to precache default game sounds such as "buttons/blip2.wav" if you only going to use them with client command spk or speak.
You need to precache if you gonna emit the sound (emit_sound, EngFunc_EmitXXX, EngFunc_BuildSound,..)
Not sure about SendAudio message, i think you also have to precache, but can be easily checked.

Liverwiz 06-29-2012 01:00

Re: Optomize
 
Quote:

Originally Posted by ConnorMcLeod (Post 1738681)
FYI, you don't have to precache default game sounds such as "buttons/blip2.wav" if you only going to use them with client command spk or speak.
You need to precache if you gonna emit the sound (emit_sound, EngFunc_EmitXXX, EngFunc_BuildSound,..)
Not sure about SendAudio message, i think you also have to precache, but can be easily checked.

Thanks! That's a good thing to know, just to ease my life. But, as you can understand, i need to precache that string anyway, in case an admin wishes to change the sound file that will be played.

ConnorMcLeod 06-29-2012 01:03

Re: Optomize
 
Usually i'm using .ini file, using 0 as default and 1 as custom so plugin knows if sound should be precached :

SOUND "buttons/blip2.wav" 0 // won't be precached

cvars are a bit useless since a change can't take effect untill next map (unless sound is a default one and doesn't have to be precache.

Liverwiz 06-29-2012 01:14

Re: Optomize
 
Quote:

Originally Posted by ConnorMcLeod (Post 1738686)
Usually i'm using .ini file, using 0 as default and 1 as custom so plugin knows if sound should be precached :

SOUND "buttons/blip2.wav" 0 // won't be precached

cvars are a bit useless since a change can't take effect untill next map (unless sound is a default one and doesn't have to be precache.

I wrote it under the assumption that admin would want to change it later. But i'm not exactly sure what you're trying to say there....I mean i think i understand it. "you don't have to precache the sound," "thus its stupid to have a cvar for it," "include files rock socks." But that all just seems like a bunch of jumbled information.

ConnorMcLeod 06-29-2012 01:20

Re: Optomize
 
But your 1st post is not clear enough, really wondering what you are trying to check using is_str_num.

Once pm_sound is filled with cvar string, i would just to something like :

if( file_exists( szFullPathSoundFile ) ) // have to include sound/
{
precache_sound(pm_sound)
}
else
{
pm_sound[0] = EOS
}


Then in functions you can only check if( pm_sound[0] )


But what you want/try to do is obscur, that's why it's a pain to give you relevant answers, let's think of it ;)

Liverwiz 06-29-2012 01:47

Re: Optomize
 
Quote:

Originally Posted by ConnorMcLeod (Post 1738696)
But your 1st post is not clear enough, really wondering what you are trying to check using is_str_num.

What i'm trying to check is if the sound is turned off (setting pm_sound cvar to 0) or on (setting pm_sound to "sound/pmSound.wav" or seomthing like that) I'm kinda missing the lapse of communication....Easily, in one cvar, allowing the admin to either turn off, or define what sound they want to play at the action.

As for your code...that would require someone to know that /buttons/blip2.wav is actually contained within the halflife directory (i believe) for it isn't directly in the czero or cstrike.

ConnorMcLeod 06-29-2012 02:22

Re: Optomize
 
There is a site where all default sounds are listed.


All times are GMT -4. The time now is 15:03.

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