Raised This Month: $32 Target: $400
 8% 

call a function when certain cvar changes its value?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-01-2020 , 13:18   call a function when certain cvar changes its value?
Reply With Quote #1

So, I want to detect when certain cvar changes its value, and than execute some function.
Currently I'm using client_PreThink to detect when cvar changes, but I was wondering if there is any more reliable way to do this?
supertrio17 is offline
shauli
Member
Join Date: Jun 2018
Old 06-01-2020 , 13:27   Re: call a function when certain cvar changes its value?
Reply With Quote #2

In newer amxx versions you can use hook_cvar_change, or alternatively bind_pcvar_* for certain purposes.

Last edited by shauli; 06-01-2020 at 13:29.
shauli is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-01-2020 , 13:36   Re: call a function when certain cvar changes its value?
Reply With Quote #3

client_PreThink is officialy THE WORST way you can do that. That function is called 100 times each second. The least you can do is use a 1 second task or longer.

For versions prior to 1.9, you need this module - https://forums.alliedmods.net/showthread.php?t=154642
The easier/better solution is of course updating to 1.9 IMO.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-01-2020 , 14:01   Re: call a function when certain cvar changes its value?
Reply With Quote #4

Quote:
Originally Posted by OciXCrom View Post
client_PreThink is officialy THE WORST way you can do that. That function is called 100 times each second. The least you can do is use a 1 second task or longer.

For versions prior to 1.9, you need this module - https://forums.alliedmods.net/showthread.php?t=154642
The easier/better solution is of course updating to 1.9 IMO.
I was hoping to do it without that module, is there any way to do it without it?
supertrio17 is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 06-01-2020 , 14:08   Re: call a function when certain cvar changes its value?
Reply With Quote #5

Yes, updating to 1.9, unless you want to constantly querying the cvar for a possible change.
__________________

Last edited by gabuch2; 06-01-2020 at 14:09.
gabuch2 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-01-2020 , 16:30   Re: call a function when certain cvar changes its value?
Reply With Quote #6

The proper way for amxx < 1.9 is orpheu/okapi.
__________________

Last edited by HamletEagle; 06-01-2020 at 16:30.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-01-2020 , 17:16   Re: call a function when certain cvar changes its value?
Reply With Quote #7

How critical is it that the change in cvar is detected immediately? You can always hook a game event and then react there (round start or end, or on each kill).
__________________
Bugsy is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-01-2020 , 17:51   Re: call a function when certain cvar changes its value?
Reply With Quote #8

It's not that critical, but I was wondering if it is possible?
supertrio17 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-01-2020 , 18:34   Re: call a function when certain cvar changes its value?
Reply With Quote #9

Upgrade to 1.9 and it's super easy: http://amxmodx.org/api/cvars/hook_cvar_change

Otherwise I'd stick with hooking a game event, not prethink.
__________________
Bugsy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-02-2020 , 11:02   Re: call a function when certain cvar changes its value?
Reply With Quote #10

Store the cvar value in a global variable, set_task, compare the current cvar value with the one you saved in the global variable, if the value is different, execute the function you want - easy.

Hook cvar change with orpheu - medium.

Or just upgrade to 1.9 and do what they told you above - very easy/recommended.
__________________









Last edited by CrazY.; 06-02-2020 at 11:08.
CrazY. 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 21:36.


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