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

Float Cvar Tag mismatch Warning


Post New Thread Reply   
 
Thread Tools Display Modes
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
101
Member
Join Date: Nov 2023
Old 12-18-2023 , 09:59   Re: Float Cvar Tag mismatch Warning
Reply With Quote #12

Quote:
Originally Posted by HamletEagle View Post
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.
The logic tells me to close the door from the beginning without having to bring a guard .
BTW , Thank You Mr Eagle , I may had gone wild .

Last edited by 101; 12-18-2023 at 10:00.
101 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-18-2023 , 10:17   Re: Float Cvar Tag mismatch Warning
Reply With Quote #13

Quote:
Originally Posted by 101 View Post
The logic tells me to close the door from the beginning without having to bring a guard .
BTW , Thank You Mr Eagle , I may had gone wild .
Sure, but in 1.8.2 you don't have a way of doing it without orpheu/okapi so if you don't know how to use them or don't want to, guarding against the input when getting the cvar value is the alternative.
__________________

Last edited by HamletEagle; 12-18-2023 at 10:18.
HamletEagle is offline
101
Member
Join Date: Nov 2023
Old 12-18-2023 , 14:39   Re: Float Cvar Tag mismatch Warning
Reply With Quote #14

Quote:
Originally Posted by HamletEagle View Post
guarding against the input when getting the cvar value is the alternative.
I got it . thx a lot , So according to this topic we have to say that :

if u create a cvar and u wouldn't/couldn't set a limit (min,max) by using this function : create_cvar

Then u can use this alternative clamp floatclamp function to protect the Extracted value for any exsisting cvar . Examples :

PHP Code:
new Float:valueget_pcvar_float(RespawnDelay); // Extract the float value that RespawnDelay was pointing at (FASTER)
new Float:clampedValue floatclamp(value5.030.0);
set_task(clampedValue"ReviveIt" Victim); 
Or
PHP Code:
new Float:valueget_cvar_float("respawn_delay");  // Extract the float value that Match This String (SLOWER) 
set_taskfloatclamp(value 5.0 30.0) ,   "ReviveIt" ,   Victim); 
The value is guaranteed to be either 5, 30, or something in between . Even if RespawnDelay pointer was pointing to -1.0 .

For Advanced usage , u can create a custum function Safe_Float like this :
PHP Code:
Round_Start()
{
    
set_taskSafe_Floatget_cvar_pointer("mp_buytime") , 1.0 300.0) ,  "Hint_Buy_Time_Expired" ,  101);
}

Death_Event(Victim)
{
    
set_taskSafe_Float(RespawnDelay 3.0 5.0) ,  "ReviveIt" ,  Victim);
}

stock FloatSafe_Float(CVAR_Pointer , const FloatMin , const FloatMax )
{
    
// This function Does Both : Change The Actual Cvar Value , then return it Within The desired Range  
    
new Float:floatclampget_pcvar_float(CVAR_Pointer) , Min Max );
    
set_pcvar_floatCVAR_Pointer X);
    return 
;

Is This right Mr Eagle ?
-I hope it wasn't an overstatement -
101 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-20-2023 , 03:09   Re: Float Cvar Tag mismatch Warning
Reply With Quote #15

Most of what you said is correct. I do not necessarily see the point of Safe_Float because the admin can do amx_cvar right after and change the value.

Also, the same clamping logic (using clamp) can apply to integer cvars (get_pcvar_num), if minimum and maximum values are desired.
__________________

Last edited by HamletEagle; 12-20-2023 at 03:20.
HamletEagle 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 17:21.


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