Raised This Month: $12 Target: $400
 3% 

Solved [ H3LP ] Detecting available player classes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 12-25-2018 , 08:29   [ H3LP ] Detecting available player classes
Reply With Quote #1

Merry Christmas ! I don't know if anyone got any ideas about how it can be done, but I'm still asking it anyways. So, in TFC (Team Fortress Classic) there are up to 4 teams: blue, red, yellow and green. Most maps have 2 maps and fun maps usually only 1 team. Some maps like hunted have 3 teams. So each of these teams can have either some or all classes enabled. On KeyValue it reads the keys and values. The corresponding keys for class limitation from info_tfdetect entity are maxammo_shells, maxammo_nails, maxammo_rockets and maxammo_cells. For example, the flag for disabling scout is 1, 2 for sniper and 4 for soldier. If, for example, maxammo_shells is set to 7, that means that the 3 classes that I listed are not selectable from the class selection menu, only the rest of the classes. maxammo_shells corresponds to blue team by the way. What I need to know is how I can detect if 7 contains 1, 2 and 4 using PAWN AMXX, because it looks like the way u disable classes is by gathering the flags.
Here are the flags just in case:
Code:
enum {     FLAG_ONLY_CIVI = -1,     FLAG_NO_SCOUT = 1,     FLAG_NO_SNIPER = 2,     FLAG_NO_SOLDIER = 4,     FLAG_NO_DEMOMAN = 8,     FLAG_NO_MEDIC = 16,     FLAG_NO_HWGUY = 32,     FLAG_NO_PYRO = 64,     FLAG_NO_RCLASS = 128,     FLAG_NO_SPY = 256,     FLAG_NO_ENGINEER = 512 };

As you can see, each value is a multiple of 2.
Thanks !

Last edited by DarthMan; 12-25-2018 at 12:09. Reason: Solved
DarthMan is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-25-2018 , 11:03   Re: [ H3LP ] Detecting available player classes
Reply With Quote #2

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.
    
}

__________________

Last edited by Bugsy; 12-25-2018 at 11:12.
Bugsy is offline
Old 12-25-2018, 11:04
Bugsy
This message has been deleted by Bugsy. Reason: Double 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
Reply


Thread Tools
Display Modes

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 04:02.


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