View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-16-2023 , 09:46   Re: Float Cvar Tag mismatch Warning
Reply With Quote #11

@101, you missed the point of what Bugsy suggested. floatclamp is not supposed to change the value of the cvar, just the variable that stores the cvar value.

Maybe this makes it easier to see:
PHP Code:
new Float:valueget_pcvar_float(RespawnDelay);
new 
Float:clampedValue floatclamp(value5.030.0);

//Now clampedValue is between 5.0 and 30.0, but the cvar RespawnDelay is unchanged 
With this approach, a user will still be able to set the cvar value outside the desired range, but when you want to read the value of the cvar and use it, you will use clampedValue that is within the required interval. This is useful if you have some logic that only works if the values are within an interval and it is a form of sanitizing user input. This way you make sure that even if the user doesn't follow the rules and sets a wrong value, your code will still work because you have the floatclamp guard in place.

create_cvar is a new native in AmxModX 1.9 (just ignore 1.8.3 completely). As you correctly noticed, it will allow you to define a valid range for the cvar itself and users won't be able to set the cvar to a value outside the range. The effect of create_cvar can be replicated in 1.8.2 by hooking Cvar_DirectSet with Orpheu/Okapi. This game engine is called when any cvar is changed. Inside it, you can check if the new value is outside the desired range, and if so, block the call (which will prevent the cvar from being changed).
__________________

Last edited by HamletEagle; 12-16-2023 at 09:50.
HamletEagle is offline