call a function when certain cvar changes its value?
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? |
Re: call a function when certain cvar changes its value?
In newer amxx versions you can use hook_cvar_change, or alternatively bind_pcvar_* for certain purposes.
|
Re: call a function when certain cvar changes its value?
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. |
Re: call a function when certain cvar changes its value?
Quote:
|
Re: call a function when certain cvar changes its value?
Yes, updating to 1.9, unless you want to constantly querying the cvar for a possible change.
|
Re: call a function when certain cvar changes its value?
The proper way for amxx < 1.9 is orpheu/okapi.
|
Re: call a function when certain cvar changes its value?
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).
|
Re: call a function when certain cvar changes its value?
It's not that critical, but I was wondering if it is possible?
|
Re: call a function when certain cvar changes its value?
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. |
Re: call a function when certain cvar changes its value?
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. |
| All times are GMT -4. The time now is 16:55. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.