You do things wrongly.
Please take your time by reading the examples provided in the module thread.
Like this one :
https://forums.alliedmods.net/showth...okSpecificCvar
You see clearly how the header of the callback should be.
How I would do :
Code:
public plugin_init()
{
CvarHookChange( register_cvar( "amx_semiclip_enabled", "1" ), "SemiclipCvar" );
}
public SemiclipCvar( const handleCvar, const oldValue[], const newValue[], const cvarName[] )
{
switch( newValue[ 0 ] )
{
case '1' :
{
Prethink = register_forward( FM_PlayerPreThink, "PreThink" );
Postthink = register_forward( FM_PlayerPostThink, "PostThink" );
Fullpack = register_forward( FM_AddToFullPack, "Fullpack_Post", 1 );
client_print( 0, print_chat, "DEBUG: FORWARD STARTED" );
}
case '0' :
{
unregister_forward( FM_PlayerPreThink, Prethink );
unregister_forward( FM_PlayerPostThink, Postthink );
unregister_forward( FM_AddToFullPack, Fullpack, 1 );
client_print( 0, print_chat,"DEBUG: FORWARD STOPPED" );
}
}
}
You could have used
str_to_num( newValue ) or
get_pcvar_num( handleCvar ), but here we can avoid the use of natives.
Actually, I would use a code more safer, because people could have written wrong things.
So, I would recommendend something like to be sure :
Code:
if( clamp( str_to_num( newValue ), 0, 1 ) )
{
}
else
{
}
EDIT :
I've just noticed something, if you use register_cvar() then CvarHookChange(), you won't be noticed the first time.
I will fix it, but I would like to encourage you to use CVarRegister() instead, where the bug doesn't exist, also, you can provide directly a description and a bound (so no need to check manually).
EDIT2:
Actually, CvarRegister may have the same problem. Just check anyway and you will see. If so, enable forwards manually like you have done in plugin_init(). It will be fixed for the next version.
So, at the end, I would do :
Code:
#include <amxmodx>
#include <cvar_util>
public plugin_init()
{
new handleCvar = CvarRegister( "amx_semiclip_enabled", "1", "My description", .hasMin = true, .minValue = 0.0, .hasMax = true, .maxValue = 1.0 );
CvarHookChange( handleCvar, "SemiclipCvar" );
}
public SemiclipCvar( const handleCvar, const oldValue[], const newValue[], const cvarName[] )
{
switch( newValue[ 0 ] )
{
case '1' :
{
Prethink = register_forward( FM_PlayerPreThink, "PreThink" );
Postthink = register_forward( FM_PlayerPostThink, "PostThink" );
Fullpack = register_forward( FM_AddToFullPack, "Fullpack_Post", 1 );
client_print( 0, print_chat, "DEBUG: FORWARD STARTED" );
}
case '0' :
{
unregister_forward( FM_PlayerPreThink, Prethink );
unregister_forward( FM_PlayerPostThink, Postthink );
unregister_forward( FM_AddToFullPack, Fullpack, 1 );
client_print( 0, print_chat,"DEBUG: FORWARD STOPPED" );
}
}
}
EDIT 3: Sorry for my answers. Actually, it's fine as it is, I mean about what i've said in my first edit. I would prefer to not change to avoid further problem.
So I would suggest finaly something like :p :
Code:
#include <amxmodx>
#include <cvar_util>
public plugin_init()
{
new handleCvar = CvarRegister( "amx_semiclip_enabled", "1", "My description", .hasMin = true, .minValue = 0.0, .hasMax = true, .maxValue = 1.0 );
CvarHookChange( handleCvar, "SemiclipCvar" );
toggleForward( .enable = true );
}
public SemiclipCvar( const handleCvar, const oldValue[], const newValue[], const cvarName[] )
{
toggleForward( .enable = newValue[ 0 ] == '1' );
}
toggleForward( const bool:enable )
{
if( enable)
{
Prethink = register_forward( FM_PlayerPreThink, "PreThink" );
Postthink = register_forward( FM_PlayerPostThink, "PostThink" );
Fullpack = register_forward( FM_AddToFullPack, "Fullpack_Post", 1 );
client_print( 0, print_chat, "DEBUG: FORWARD STARTED" );
}
else
{
unregister_forward( FM_PlayerPreThink, Prethink );
unregister_forward( FM_PlayerPostThink, Postthink );
unregister_forward( FM_AddToFullPack, Fullpack, 1 );
client_print( 0, print_chat,"DEBUG: FORWARD STOPPED" );
}
}
__________________