Raised This Month: $ Target: $400
 0% 

get_cvar_num in menus help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Infinity
Junior Member
Join Date: Sep 2009
Old 08-08-2012 , 01:40   get_cvar_num in menus help
Reply With Quote #1

I'm currently making a menu and I've bumped into a problem where ColorChat isn't sending a message. I'm pretty sure I've used the CVAR functions incorrectly. Any pointers?

No compiling errors are given.

Includes:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>

PHP Code:
        case 1:
        {
        if(
get_cvar_num("mp_friendlyfire") & 1)
        {
        new 
name[32]
        
get_user_name(idname31)
        
ColorChat(0GREEN"^x04%s ^x01 has turned friendlyfire ^x04ON"name)
        
set_cvar_num("mp_friendlyfire",1)
        }
        else if(
get_cvar_num("mp_friendlyfire") & 1)
        {
        new 
name[32]
        
get_user_name(idname31)
        
ColorChat(0GREEN"^x04%s ^x01 has turned friendlyfire ^x04OFF"name)
        
set_cvar_num("mp_friendlyfire",0)
        } 

Last edited by Infinity; 08-08-2012 at 01:41.
Infinity is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-08-2012 , 02:28   Re: get_cvar_num in menus help
Reply With Quote #2

You have two identical if statements, which doesn't make any sense. Explain what you are trying to do.

Also, when dealing with numeric values, you would not use an ampersand (&) to compare values. Instead you would use two equal signs (==).

So you would do

if( get_cvar_num( "mp_friendlyfire" ) == 1 )
{
// code here
}

What I would suggest is getting the pointer to the cvar in plugin_init and then using that pointer instead of getting a cvar num. That would work as such:

PHP Code:

    
new g_pFriendlyFire;
    
    public 
plugin_init()
    {
        
g_pFriendlyFire get_cvar_pointer"mp_friendlyfire" );
    }
    
    public 
yourFunction()
    {
        switch( 
whatever )
        {
            case 
1:
            {
                if(
get_pcvar_num(g_pFriendlyFire) == 1)
                {
                    new 
name[32]
                    
get_user_name(idname31)
                    
ColorChat(0GREEN"^x04%s ^x01 has turned friendlyfire ^x04ON"name)
                    
set_pcvar_num(g_pFriendlyFire,1)
                }
            }
        }
    } 
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 08-08-2012 at 19:48.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 08-08-2012 , 11:27   Re: get_cvar_num in menus help
Reply With Quote #3

@nikhilgupta345
You could also change set_cvar_num to set_pcvar_num

Last edited by OvidiuS; 08-08-2012 at 11:28.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-08-2012 , 19:47   Re: get_cvar_num in menus help
Reply With Quote #4

Quote:
Originally Posted by OvidiuS View Post
@nikhilgupta345
You could also change set_cvar_num to set_pcvar_num
Oops, didn't even see that in the code. Thanks
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
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 05:52.


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