AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved hide cvar no notification in chat (https://forums.alliedmods.net/showthread.php?t=305383)

indraraj striker 02-18-2018 00:22

hide cvar no notification in chat
 
hide cvar no notification in chat
i want to hide this only cvar whether admin trying to change or server or from another plugin
cmd : amx_cvar the_notification "0"
I don't want to hide all cvars by doing this amx_show_activity 0

check below screenshot
https://image.ibb.co/iqSuWS/hide_cvar.png

Main plugin :
PHP Code:


#include amxmodx 

new TEST_CVAR;

public 
plugin_init()
{
    
TEST_CVAR register_cvar("the_notification","1"
    
// say hello to get msg
    
register_clcmd("say /hello","allied_welcome");
}

public 
allied_welcome(id)
{
   if(
get_pcvar_num(TEST_CVAR))
     {
        
client_print(id,print_chat,"Welcome to ALLIEDMODDERS");
     }
    else
    {
        
client_print(id,print_chat,"the cvar is off");
    }


from another plugin

PHP Code:


#include amxmodx

public plugin_init()
{
    
register_clcmd("say /disable","disable_cvar");
    
register_clcmd("say /enable","enable_cvar");
}

public 
disable_cvar(id)
{
      
server_cmd("amx_cvar the_notification 0");
      
client_print(id,print_chat,"off off off");
}

public 
enable_cvar(id)
{
    
server_cmd("amx_cvar the_notification 1");
    
client_print(id,print_chat,"on on on");


Thanks

Relaxing 02-18-2018 02:28

Re: hide cvar no notification in chat
 
Have you tried using return PLUGIN_HANDLED?

indraraj striker 02-18-2018 03:21

Re: hide cvar no notification in chat
 
thanks for reply,

return PLUGIN_HANDLED is for chat that will not work for cvar

fysiks 02-18-2018 04:43

Re: hide cvar no notification in chat
 
You shouldn't be using the amx_cvar command when setting a cvar from within a plugin. Simply use set_cvar_num().

indraraj striker 02-18-2018 05:35

Re: hide cvar no notification in chat
 
Quote:

Originally Posted by fysiks (Post 2578801)
You shouldn't be using the amx_cvar command when setting a cvar from within a plugin. Simply use set_cvar_num().

thanks for reply,
i know set_cvar_num() will not give you notification when you change cvar
but i want to change that cvar from another plugin

klippy 02-18-2018 05:37

Re: hide cvar no notification in chat
 
Quote:

Originally Posted by indraraj striker (Post 2578805)
thanks for reply,
i know set_cvar_num() will not give you notification when you change cvar
but i want to change that cvar from another plugin

And that's exactly why you should use set_cvar_num(). What's the issue?

indraraj striker 02-18-2018 05:48

Re: hide cvar no notification in chat
 
Quote:

Originally Posted by KliPPy (Post 2578806)
And that's exactly why you should use set_cvar_num(). What's the issue?

set_pcvar_num() will work when you change cvar from within plugin
i want to change cvar from another plugin
Please refer my first post

klippy 02-18-2018 06:31

Re: hide cvar no notification in chat
 
Quote:

Originally Posted by indraraj striker (Post 2578808)
set_pcvar_num() will work when you change cvar from within plugin

That's not true, plugins don't own cvars. Did you even try it?

indraraj striker 02-18-2018 06:39

Re: hide cvar no notification in chat
 
Quote:

Originally Posted by KliPPy (Post 2578811)
That's not true, plugins don't own cvars. Did you even try it?

here is the example
full plugin set_pcvar_num will work if i change cvar within plugin we won't get any notification

PHP Code:


#include amxmodx 

new TEST_CVAR;

public 
plugin_init()
{
    
TEST_CVAR register_cvar("the_notification","1"
    
// say hello to get msg
    
register_clcmd("say /hello","allied_welcome");
    
register_clcmd("say /disable","disable_cvar");
    
register_clcmd("say /enable","enable_cvar");
}

public 
allied_welcome(id)
{
   if(
get_pcvar_num(TEST_CVAR))
     {
        
client_print(id,print_chat,"Welcome to ALLIEDMODDERS");
     }
    else
    {
        
client_print(id,print_chat,"the cvar is off");
    }
}

public 
disable_cvar(id)
{
      
set_pcvar_num(TEST_CVAR,0)
      
client_print(id,print_chat,"off off off");
}

public 
enable_cvar(id)
{
    
set_pcvar_num(TEST_CVAR1)
    
client_print(id,print_chat,"on on on");


but but but
i want to change above cvar from another plugin and i am getting undefined symbol
this is another plugin :

PHP Code:

#include amxmodx

public plugin_init()
{
    
register_clcmd("say /disable","disable_cvar");
    
register_clcmd("say /enable","enable_cvar");
}

public 
disable_cvar(id)
{
      
//server_cmd("amx_cvar the_notification 0");
      
set_pcvar_num(the_notification,0)
      
client_print(id,print_chat,"off off off");
}

public 
enable_cvar(id)
{
    
//server_cmd("amx_cvar the_notification 1");
    
set_pcvar_num(the_notification1)
    
client_print(id,print_chat,"on on on");



HamletEagle 02-18-2018 06:57

Re: hide cvar no notification in chat
 
:facepalm:

Of course you get an undefined symbol, the_notification variable is not defined in your second plugin. Look at set_pcvar_num function prototype. The first argument is:
Quote:

pcvar
Pointer to cvar to set value of
It's a pointer to your cvar, this means you need a way to retrieve the pointer from the cvar name. If you simply search the api page for pointer you will get get_cvar_pointer function. It's argument is:
Quote:

cvar
Cvar name to find
Go figure from here what you should do.


All times are GMT -4. The time now is 11:47.

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