Quote:
Originally Posted by HamletEagle
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:value= get_pcvar_float(RespawnDelay); // Extract the float value that RespawnDelay was pointing at (FASTER)
new Float:clampedValue = floatclamp(value, 5.0, 30.0);
set_task(clampedValue, "ReviveIt" , Victim);
Or
PHP Code:
new Float:value= get_cvar_float("respawn_delay"); // Extract the float value that Match This String (SLOWER)
set_task( floatclamp(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_task( Safe_Float( get_cvar_pointer("mp_buytime") , 1.0 , 300.0) , "Hint_Buy_Time_Expired" , 101);
}
Death_Event(Victim)
{
set_task( Safe_Float(RespawnDelay , 3.0 , 5.0) , "ReviveIt" , Victim);
}
stock Float: Safe_Float(CVAR_Pointer , const Float: Min , const Float: Max )
{
// This function Does Both : Change The Actual Cvar Value , then return it Within The desired Range
new Float:X = floatclamp( get_pcvar_float(CVAR_Pointer) , Min , Max );
set_pcvar_float( CVAR_Pointer , X);
return X ;
}
Is This right Mr Eagle ?
-I hope it wasn't an overstatement -