View Single Post
DarthMan
Veteran Member
Join Date: Aug 2011
Old 12-25-2018 , 11:43   Re: [ H3LP ] Detecting available player classes
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
I don't fully understand what you're trying to do based on your explanation, but I'm sure it's possible based on the enum you posted. This enumerator is ready to go for bit-wise operations which makes it easy to see if none/one/some/all flags exist. I provided some examples below that may help.

PHP Code:
enum
{
    
FLAG_ONLY_CIVI = -1;    //All bits
    
FLAG_NO_SCOUT 1,    //1 << 0
    
FLAG_NO_SNIPER 2,    //1 << 1
    
FLAG_NO_SOLDIER 4,    //1 << 2
    
FLAG_NO_DEMOMAN 8,    //1 << 3
    
FLAG_NO_MEDIC 16,    //1 << 4
    
FLAG_NO_HWGUY 32,    //1 << 5
    
FLAG_NO_PYRO 64,    //1 << 6
    
FLAG_NO_RCLASS 128,    //1 << 7
    
FLAG_NO_SPY 256,    //1 << 8
    
FLAG_NO_ENGINEER 512    //1 << 9
}; 
You can also write your enumerator like this:
PHP Code:
const FLAG_ONLY_CIVI = -1;    //All bits
enum Classes (<<=1)
{
    
FLAG_NO_SCOUT 1,    //1 << 0
    
FLAG_NO_SNIPER,        //1 << 1
    
FLAG_NO_SOLDIER,    //1 << 2
    
FLAG_NO_DEMOMAN,    //1 << 3
    
FLAG_NO_MEDIC,        //1 << 4
    
FLAG_NO_HWGUY,        //1 << 5
    
FLAG_NO_PYRO,        //1 << 6
    
FLAG_NO_RCLASS,        //1 << 7
    
FLAG_NO_SPY,        //1 << 8
    
FLAG_NO_ENGINEER    //1 << 9
}; 
PHP Code:
public Test() 
{
    new 
Classes:iClasses = ( FLAG_NO_SNIPER FLAG_NO_PYRO );
    
    if ( 
iClasses FLAG_NO_SNIPER )
    {
        
//Player has No Sniper flag, as well as possibly others.
    
}
        
    if ( 
iClasses == FLAG_NO_SNIPER )
    {
        
//Player has only No Sniper flag.
    
}
    
    if ( ( 
iClasses & ( FLAG_NO_SNIPER FLAG_NO_PYRO ) ) == ( FLAG_NO_SNIPER FLAG_NO_PYRO ) )
    {
        
//Player has No Sniper & No Pyro, as well as possibly others.
    
}
    
    if ( 
iClasses == ( FLAG_NO_SNIPER FLAG_NO_PYRO ) )
    {
        
//Player has only No Sniper & No Pyro flags.
    
}

Many thanks man, didn't think about bitwise. Will check it out :-)

Edit: Works perfectly :-)

Last edited by DarthMan; 12-25-2018 at 12:09.
DarthMan is offline