AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_cvar_num in menus help (https://forums.alliedmods.net/showthread.php?t=192246)

Infinity 08-08-2012 01:40

get_cvar_num in menus help
 
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)
        } 


nikhilgupta345 08-08-2012 02:28

Re: get_cvar_num in menus help
 
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)
                }
            }
        }
    } 


OvidiuS 08-08-2012 11:27

Re: get_cvar_num in menus help
 
@nikhilgupta345
You could also change set_cvar_num to set_pcvar_num :)

nikhilgupta345 08-08-2012 19:47

Re: get_cvar_num in menus help
 
Quote:

Originally Posted by OvidiuS (Post 1767047)
@nikhilgupta345
You could also change set_cvar_num to set_pcvar_num :)

Oops, didn't even see that in the code. Thanks


All times are GMT -4. The time now is 05:52.

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