Raised This Month: $51 Target: $400
 12% 

[MODULE] Cvar Hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 08-11-2009 , 19:17   [MODULE] Cvar Hook
Reply With Quote #1

Well I do this more faster than my Amx Version.

Tomorrow I will add more things.

Example:
PHP Code:
#include <amxmodx>

#pragma library cvar_hook

native pcvar_hook_change(pcvar, const handler[]);
native cvar_hook_change( const cvar[], const handler[]);
native disable_hook_changehandler );

new 
pcvar
new example_disable

public plugin_init() 
{
    
register_plugin("Exampler""1.0""ReymonARG")
    
    
pcvar register_cvar("My_New_Cvar""Something")
    
    
example_disable pcvar_hook_change(pcvar"MyHandlerFunc")
    
    
cvar_hook_change("sv_alltalk""AllTalkHandler")
    
    
register_clcmd("say disable""disable")
}

public 
AllTalkHandlerpcvar, const OldValue[], const NewValue[])
{
    
client_print(0print_chat"Now sv_alltalk is %d"str_to_num(NewValue) )
    
server_print"Now sv_alltalk is %d"str_to_num(NewValue) )
    
    return 
0
}

public 
MyHandlerFuncpcvar, const OldValue[], const NewValue[])
{
    
client_print(0print_chat"My_New_Cvar want to change to %s, Reset to Old Value"NewValue)
    
server_print("My_New_Cvar want to change to %s, Reset to Old Value"NewValue)
    
    return 
// With a return != 0 the Cvar Reset to old value
}

public 
disable(id)
{
    
// Dont remove a Cvar Hook in the Handled of the functions.
    
disable_hook_changeexample_disable )

Good Bye.
Attached Files
File Type: zip Cvar_Hook.zip (104.5 KB, 14008 views)
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
P34nut
AMX Mod X Beta Tester
Join Date: Feb 2006
Location: Netherlands
Old 08-11-2009 , 19:27   Re: [MODULE] Cvar Hook
Reply With Quote #2

Why dont you use FN_CVarSetFloat and FN_CVarSetString instead of FN_StartFrame?
__________________
All you need to change the world is one good lie and a river of blood
P34nut is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-11-2009 , 19:39   Re: [MODULE] Cvar Hook
Reply With Quote #3

Quote:
Originally Posted by P34nut View Post
Why dont you use FN_CVarSetFloat and FN_CVarSetString instead of FN_StartFrame?
Are those called even when the cvars are changed from the server's console?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
P34nut
AMX Mod X Beta Tester
Join Date: Feb 2006
Location: Netherlands
Old 08-11-2009 , 19:40   Re: [MODULE] Cvar Hook
Reply With Quote #4

I dont know.. I never tried
__________________
All you need to change the world is one good lie and a river of blood
P34nut is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 08-12-2009 , 11:40   Re: [MODULE] Cvar Hook
Reply With Quote #5

I Test and only are call in some cvars. Like

sv_accelerate and only when the server set. Also in sv_restart 1.
Are only called in that time. But no when I put Example:
sv_maxspeed 900.0
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-13-2009 , 00:21   Re: [MODULE] Cvar Hook
Reply With Quote #6

I think ServerCommand is called in that case, not sure when you use set_cvar_ or set_pcvar_ .
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-13-2009 , 01:39   Re: [MODULE] Cvar Hook
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
I think ServerCommand is called in that case, not sure when you use set_cvar_ or set_pcvar_ .
I would assume those would be called from FN_CVarSet*
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 08-13-2009 , 12:38   Re: [MODULE] Cvar Hook
Reply With Quote #8

Quote:
Originally Posted by Exolent[jNr] View Post
I would assume those would be called from FN_CVarSet*
No, Only the Cvars that change in game create, map change and sv_restart 1.
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Twelve-60
Senior Member
Join Date: Aug 2007
Old 09-02-2009 , 06:57   Re: [MODULE] Cvar Hook
Reply With Quote #9

Hi there, is a linux version of this?

Or any other way to detect the change of sv_restart/round restart?

- Twelve-60
__________________
Twelve-60 is offline
Twelve-60
Senior Member
Join Date: Aug 2007
Old 09-02-2009 , 11:12   Re: [MODULE] Cvar Hook
Reply With Quote #10

Got it:

Code:
register_event("TextMsg", "event_round_restart", "a", "2=#Game_will_restart_in");


- Twelve-60
__________________
Twelve-60 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 05:25.


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