Raised This Month: $ Target: $400
 0% 

Enum bits for menu options


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2019 , 17:28   Re: Enum bits for menu options
Reply With Quote #1

I don't see a benefit in using bit-sums here, unless I am missing something. The only exception would be is if you did not need to associate an item with it's string name; in this case bitsums can save you a bit of coding. The below will be much easier to understand if you are just starting.

PHP Code:

#include <amxmodx>

enum Options
{
    
Option1,
    
Option2,
    
Option3
}

new const 
OptionNamesOptions ][] =
{
    
"Option 1",
    
"Option 2",
    
"Option 3"
};

new 
bool:g_bPlayerOptionsMAX_PLAYERS ][ Options ];

public 
plugin_init()
{
    
register_clcmd"say addopt1" "AddOpt1" );
    
register_clcmd"say addopt2" "AddOpt2" );
    
register_clcmd"say addopt3" "AddOpt3" );
    
    
register_clcmd"say delopt1" "DelOpt1" );
    
register_clcmd"say delopt2" "DelOpt2" );
    
register_clcmd"say delopt3" "DelOpt3" );
    
    
register_clcmd"say options" "ShowPlayerOptions" );
}

//The below 3 function's code can be inserted into your code directly, having functions for 1 line of code is overkill. These
//can also be accomplished using macros.
public AddOptionid Options:oOption )
{
    
g_bPlayerOptionsid ][ oOption ] = true;
}

public 
RemoveOptionid Options:oOption )
{
    
g_bPlayerOptionsid ][ oOption ] = false;
}

public 
bool:PlayerHasOptionid Options:oOption )
{
    return 
g_bPlayerOptionsid ][ oOption ];
}

public 
ShowPlayerOptionsid )
{
    new 
szOptions48 ] , iPos;
    
    for ( new 
Options:oOpt Option1 oOpt Options oOpt++ )
    {
        if ( 
PlayerHasOptionid oOpt ) == true )
        {
            
iPos += formatexszOptionsiPos ] , charsmaxszOptions ) - iPos "%s, " OptionNamesoOpt ] );
        }
    }
    
    if ( 
iPos == )
        
copyszOptions charsmaxszOptions ) , "(none)" );
    else    
        
szOptionsiPos ] = EOS;
    
    
client_printid print_chat "You have options: %s" szOptions );
}

public 
AddOpt1(idAddOptionid Option1 );
public 
AddOpt2(idAddOptionid Option2 );
public 
AddOpt3(idAddOptionid Option3 );

public 
DelOpt1(idRemoveOptionid Option1 );
public 
DelOpt2(idRemoveOptionid Option2 );
public 
DelOpt3(idRemoveOptionid Option3 ); 
__________________

Last edited by Bugsy; 09-08-2019 at 18:42.
Bugsy is offline
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 17:29.


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