Raised This Month: $ Target: $400
 0% 

Optomize


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-28-2012 , 21:27   Optomize
Reply With Quote #1

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.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 06-29-2012 at 02:32. Reason: updated to latest optimization
Liverwiz is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 06-28-2012 , 21:34   Re: Optomize
Reply With Quote #2

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.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-28-2012 , 21:40   Re: Optomize
Reply With Quote #3

Quote:
Originally Posted by YamiKaitou View Post
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?
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 06-28-2012 at 21:51.
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-29-2012 , 00:55   Re: Optomize
Reply With Quote #4

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-29-2012 , 01:00   Re: Optomize
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-29-2012 , 01:03   Re: Optomize
Reply With Quote #6

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-29-2012 , 01:14   Re: Optomize
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-29-2012 , 01:20   Re: Optomize
Reply With Quote #8

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 ;)
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-29-2012 , 01:47   Re: Optomize
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
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.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 06-29-2012 at 01:50.
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-29-2012 , 02:22   Re: Optomize
Reply With Quote #10

There is a site where all default sounds are listed.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



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 15:03.


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