Raised This Month: $32 Target: $400
 8% 

Using cvars with read_flags()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
happy_2012
Senior Member
Join Date: Aug 2012
Old 04-01-2023 , 13:30   Using cvars with read_flags()
Reply With Quote #1

Hello,

I am trying to make a weapon system to strip weapons according to flags, and I am trying to do that through cvars

Here is my problem:
PHP Code:
enum
{
    
WEAPON_NONE 0,
    
WEAPON_PRIMARY,
    
WEAPON_SECONDARY,
    
WEAPON_GRENADE
};

#define BITSUM_WEAPON_NONE        ( 1 << WEAPON_NONE )        // -- 1
#define BITSUM_WEAPON_PRIMARY    ( 1 << WEAPON_PRIMARY )        // -- 2
#define BITSUM_WEAPON_SECONDARY    ( 1 << WEAPON_SECONDARY )    // -- 4
#define BITSUM_WEAPON_GRENADE    ( 1 << WEAPON_GRENADE )        // -- 8 
Using client print in the server to trace the problem, I got these:
PHP Code:
    /*
        Prints [should be fixed]:
        -- [ZP] BITSUM_WEAPON_NONE = 1
        -- [ZP] BITSUM_WEAPON_PRIMARY = 2
        -- [ZP] BITSUM_WEAPON_SECONDARY = 4
        -- [ZP] BITSUM_WEAPON_GRENADE = 8

        -- [ZP] g_szWeaponsDropZombie = ab - i_Drop = 3
        -- [ZP] Drop - BITSUM_WEAPON_PRIMARY = 2

        -- [ZP] g_szWeaponsStripZombie = c - i_Strip = 4
        -- [ZP] Strip - BITSUM_WEAPON_SECONDARY = 4
    */ 
Look at the attached SMA for the full code, it will soon be on GitHub, how can I fix it?
Attached Files
File Type: sma Get Plugin or Get Source (zp_menu_weapons.sma - 52 views - 26.1 KB)
__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!
happy_2012 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-01-2023 , 14:15   Re: Using cvars with read_flags()
Reply With Quote #2

Not sure that I fully understand what you're trying to resolve but I'll take a stab.

Are you expecting g_szWeaponsDropZombie, which holds flags "ab" to result in a 2 to match BITSUM_WEAPON_PRIMARY?
PHP Code:
        -- [ZPg_szWeaponsDropZombie ab i_Drop 3
        
-- [ZPDrop BITSUM_WEAPON_PRIMARY 
If so it's because flags a and b combined give you a resulting integer of 3 (1 << 0 | 1 << 2)
PHP Code:
#define ADMIN_IMMUNITY      (1<<0)  /* flag "a" */
#define ADMIN_RESERVATION   (1<<1)  /* flag "b" */
#define ADMIN_KICK          (1<<2)  /* flag "c" */ 
You can do this to get you to 3
PHP Code:
#define BITSUM_WEAPON_PRIMARY    ( 1 << WEAPON_PRIMARY ) |  ( 1 << WEAPON_NONE ) 
If what I said above is correct, then this is working?
PHP Code:
        -- [ZPg_szWeaponsStripZombie i_Strip 4
        
-- [ZPStrip BITSUM_WEAPON_SECONDARY 
__________________

Last edited by Bugsy; 04-01-2023 at 14:19.
Bugsy is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 04-01-2023 , 14:59   Re: Using cvars with read_flags()
Reply With Quote #3

Well, I think I am doing flags all wrong, because BITSUM_WEAPON_NONE = 1 which is basically flag a, and I want flag a to be BITSUM_WEAPON_PRIMARY

so it would be like this: BITSUM_WEAPON_PRIMARY is flag "a", BITSUM_WEAPON_SECONDARY is flag "b", and BITSUM_WEAPON_GRENADES is flag "c", and I want to keep BITSUM_WEAPON_NONE as zero or whatever since I am using it for other purposes

EDIT:
Not sure this is idea, but it worked:
PHP Code:
enum
{
    
WEAPON_PRIMARY 0,
    
WEAPON_SECONDARY,
    
WEAPON_GRENADE,
    
WEAPON_NONE
};

#define BITSUM_WEAPON_PRIMARY    ( 1 << WEAPON_PRIMARY )        // -- 1; flag "a"
#define BITSUM_WEAPON_SECONDARY    ( 1 << WEAPON_SECONDARY )    // -- 2; flag "b"
#define BITSUM_WEAPON_GRENADE    ( 1 << WEAPON_GRENADE )        // -- 4; flag "c"
#define BITSUM_WEAPON_NONE        ( 1 << WEAPON_NONE )        // -- 8; flag "d" 
__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!

Last edited by happy_2012; 04-01-2023 at 15:06.
happy_2012 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-01-2023 , 18:37   Re: Using cvars with read_flags()
Reply With Quote #4

You can get rid of the separate #defines with this

PHP Code:
enum WeaponStuff (<<=1)
{
    
WEAPON_PRIMARY 1//1
    
WEAPON_SECONDARY//2
    
WEAPON_GRENADE//4
    
WEAPON_NONE //8

__________________

Last edited by Bugsy; 04-02-2023 at 01:04.
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-02-2023 , 00:54   Re: Using cvars with read_flags()
Reply With Quote #5

Already been done check out the one made by Conner.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
happy_2012
Senior Member
Join Date: Aug 2012
Old 04-02-2023 , 05:57   Re: Using cvars with read_flags()
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
You can get rid of the separate #defines with this

PHP Code:
enum WeaponStuff (<<=1)
{
    
WEAPON_PRIMARY 1//1
    
WEAPON_SECONDARY//2
    
WEAPON_GRENADE//4
    
WEAPON_NONE //8

Hey,

If you checked the code, I am using the other non-bitsums for other purposes, so I think (for now?) it is better (for me?) to keep them

Quote:
Originally Posted by Natsheh View Post
Already been done check out the one made by Conner.
Hey,

What is? I don't follow
__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!
happy_2012 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-02-2023 , 16:32   Re: Using cvars with read_flags()
Reply With Quote #7

It's no issue to keep it as you have it, given the point you made.

If you want to have a BITSUM_WEAPON_NONE while allowing PRIMARY to be 1, SECONDARY 2, etc. , do the below. It does not appear that you are doing any bit-wise logic on BITSUM_WEAPON_NONE, it's more of just a constant so it if has a -1 value it should not cause issues.
PHP Code:
enum
{
    
WEAPON_NONE = -1,  // -1
    
WEAPON_PRIMARY// 0
    
WEAPON_SECONDARY// 1
    
WEAPON_GRENADE // 2
};

#define BITSUM_WEAPON_NONE        WEAPON_NONE        // -- -1
#define BITSUM_WEAPON_PRIMARY    ( 1 << WEAPON_PRIMARY )        // -- 1
#define BITSUM_WEAPON_SECONDARY    ( 1 << WEAPON_SECONDARY )    // -- 2
#define BITSUM_WEAPON_GRENADE    ( 1 << WEAPON_GRENADE )        // -- 4 
__________________

Last edited by Bugsy; 04-02-2023 at 16:32.
Bugsy is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 04-02-2023 , 17:02   Re: Using cvars with read_flags()
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
It's no issue to keep it as you have it, given the point you made.

If you want to have a BITSUM_WEAPON_NONE while allowing PRIMARY to be 1, SECONDARY 2, etc. , do the below. It does not appear that you are doing any bit-wise logic on BITSUM_WEAPON_NONE, it's more of just a constant so it if has a -1 value it should not cause issues.
PHP Code:
enum
{
    
WEAPON_NONE = -1,  // -1
    
WEAPON_PRIMARY// 0
    
WEAPON_SECONDARY// 1
    
WEAPON_GRENADE // 2
};

#define BITSUM_WEAPON_NONE        WEAPON_NONE        // -- -1
#define BITSUM_WEAPON_PRIMARY    ( 1 << WEAPON_PRIMARY )        // -- 1
#define BITSUM_WEAPON_SECONDARY    ( 1 << WEAPON_SECONDARY )    // -- 2
#define BITSUM_WEAPON_GRENADE    ( 1 << WEAPON_GRENADE )        // -- 4 
Thank you very much, I will try it and test it!
__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!
happy_2012 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 21:28.


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