Quote:
Originally Posted by Bugsy
You can also consider using floatclamp(), to ensure the cvar is between a min/max.
PHP Code:
//This will ensure the value is between 5.0 and 30.0
RespawnDelay = floatclamp( get_pcvar_float( RespawnDelay ) , 5.0 , 30.0 );
|
floatclamp :
This function doesn't work as desire , it seems like
get_pcvar_float( RespawnDelay ) return a fake value or a copy of the original value so
<floatclamp>won't be able to restrict the actual float value of the given cvar between
5.0 and
30.0 .
BTW , I think that RespawnDelay is a pointer while floatclamp return a float value that shouldn't be stored in a pointer .
After many retries , I now realized that
floatclamp(Float:X , min , max) does't change the actual value of X , it just checks :
* if X in between mix and max THEN return X .
* if X > max THEN return max .
* if X < min THEN return min .
PHP Code:
#include <amxmodx>
new RespawnDelay;
public plugin_init()
{
RespawnDelay = register_cvar("respawn_delay", "1.5");
set_task(3.0,"Print_Test",100);
}
public Print_Test()
{
set_pcvar_float( RespawnDelay , 50.0 );
log_amx("Clamped Cvar Value=%f",floatclamp( get_pcvar_float( RespawnDelay ) ,5.0 , 30.0)); // result 30.0
set_pcvar_float( RespawnDelay , 10.0 );
log_amx("Clamped Cvar Value=%f",floatclamp( get_pcvar_float( RespawnDelay ) ,5.0 , 30.0));// result 10.0
set_pcvar_float( RespawnDelay , -1.0 );
log_amx("Clamped Cvar Value=%f",floatclamp( get_pcvar_float( RespawnDelay ) ,5.0 , 30.0));// result 5.0
log_amx("Actual Cvar Value=%f",get_pcvar_float( RespawnDelay));// result -1.0 (the last modified value)
}
So how can we restrict a cvar value between Min and Max with/without using this function :
PHP Code:
create_cvar(const name[], const string[], flags = FCVAR_NONE, const description[] = "", bool:has_min = false, Float:min_val = 0.0, bool:has_max = false, Float:max_val = 0.0);
It throws an error while compiling :
undefined symbol "create_cvar"
Regrads