Raised This Month: $ Target: $400
 0% 

(Cvar Utilities) Hooking cvar question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 04-12-2011 , 17:19   (Cvar Utilities) Hooking cvar question
Reply With Quote #1

Ok, I've tried these ways:

PHP Code:
new advanced_menu_chicken_sound

in init
:

advanced_menu_chicken_sound register_cvar("advanced_menu_chicken_sound""1")
CvarHookChange(advanced_menu_chicken_sound register_cvar("advanced_menu_chicken_sound""1"), "OnCvarChange"
And I am checking this with
PHP Code:
get_pcvar_num 
. Is this a good way at all? I also tried todo this:

PHP Code:
in init:

new 
advanced_menu_chicken_sound_register CvarRegister("advanced_menu_chicken_sound""1""Enable/Disable Chicken sound"
This didn't work.
bibu is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-12-2011 , 17:29   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #2

You can do directly either :

Code:
CvarHookChange( register_cvar( "advanced_menu_chicken_sound", "1" ), "OnChange" );

or :

Code:
new handleCvar = register_cvar( "advanced_menu_chicken_sound", "1" ); CvarHookChange( handleCvar, "OnChange" );

or using CvarRegister :

Code:
new handleCvar = CvarRegister( "advanced_menu_chicken_sound", "1", "Enable/Disable Chicken sound" ); CvarHookChange( handleCvar, "OnChange" );

Now, you say it doesn't work. It doesn't help.

- Show the whole code
- Check the console output if you see errors
- You can also check the return value of CvarHookChange
__________________
Arkshine is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 04-13-2011 , 14:58   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #3

But how can I use get_pcvar_num then?
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-13-2011 , 15:12   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #4

With handleCvar variable from his example.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 04-13-2011 , 15:14   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #5

Can't I hook the change of the cvars together, but still having support for multiple cvars for sure.
bibu is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-13-2011 , 16:03   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #6

You can use a same callback with different cvars, no problem.
__________________
Arkshine is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 04-13-2011 , 16:18   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #7

How can I do that?
bibu is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-13-2011 , 16:21   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #8

Just use CvarHookChange() for all your cvars with the cvar handle from register_cvar or CvarRegister, and write the same callback as second argument, for example "OnChange".

Like :

Code:
CvarHookChange( register_cvar( "MyCvar1", "1" ), "OnChange" ); CvarHookChange( register_cvar( "MyCvar2", "1" ), "OnChange" ); ...

or :

Code:
CvarHookChange( CvarRegister( "MyCvar1", "1" ), "OnChange" ); CvarHookChange( CvarRegister( "MyCvar2", "1" ), "OnChange" ); ...

or :

Code:
handleCvar1 = register_cvar( "MyCvar1", "1" ); handleCvar2 = register_cvar( "MyCvar2", "1" ); CvarHookChange( handleCvar1, "OnChange" ); CvarHookChange( handleCvar2, "OnChange" ); ...

or :

Code:
handleCvar1 = CvarRegister( "MyCvar1", "1" ); handleCvar2 = CvarRegister( "MyCvar2", "1" ); CvarHookChange( handleCvar1, "OnChange" ); CvarHookChange( handleCvar2, "OnChange" ); ...

Code:
public OnChange( handleCvar, const oldValue[], const newValue[], const cvarName[] ) {     // Called for all your cvars. }

Simple, isn't it ?
__________________

Last edited by Arkshine; 04-13-2011 at 16:35.
Arkshine is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 04-13-2011 , 17:44   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #9

Yes it is, I understood it before you edited. And I am using your first method.

I've got this now:

PHP Code:
/*Line 1774*/ if(get_pcvar_num(am_lightning_sound))
        {
                    
code
        

Quote:
L 04/13/2011 - 23:40:53: [AMXX] Run time error 10: native error (native "get_pcvar_num")
L 04/13/2011 - 23:40:53: [AMXX] [0] advanced_menu.sma::menu_handler_lightning (line 1774)
Rest:

PHP Code:
new am_lightning_sound

//in precache (using this since precache is loaded before init and I need it for precaching / playing the sounds:

CvarHookChange(register_cvar("am_lightning_sound""1"), "OnCvarChange"
bibu is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-13-2011 , 17:57   Re: (Cvar Utilities) Hooking cvar question
Reply With Quote #10

Bibu, please, when you have a problem :

- Give the full error
- Give the full code (at least a part where we can fully understand).

What is am_lightning_sound ? Where it's set ?

You don't show enough code to see what you have done exactly, nor the full error to see what happens.
__________________
Arkshine 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 19:49.


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