AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   call a function when certain cvar changes its value? (https://forums.alliedmods.net/showthread.php?t=324941)

supertrio17 06-01-2020 13:18

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?

shauli 06-01-2020 13:27

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.

OciXCrom 06-01-2020 13:36

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.

supertrio17 06-01-2020 14:01

Re: call a function when certain cvar changes its value?
 
Quote:

Originally Posted by OciXCrom (Post 2703520)
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?

gabuch2 06-01-2020 14:08

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.

HamletEagle 06-01-2020 16:30

Re: call a function when certain cvar changes its value?
 
The proper way for amxx < 1.9 is orpheu/okapi.

Bugsy 06-01-2020 17:16

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).

supertrio17 06-01-2020 17:51

Re: call a function when certain cvar changes its value?
 
It's not that critical, but I was wondering if it is possible?

Bugsy 06-01-2020 18:34

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.

CrazY. 06-02-2020 11:02

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.