Raised This Month: $ Target: $400
 0% 

get_pcvar_num returning different number?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Elusive138
Senior Member
Join Date: Dec 2010
Old 10-27-2011 , 03:37   get_pcvar_num returning different number?
Reply With Quote #1

I needed a way to detect when people are armed. To do this, and have a cvar for easier customisation, I used a sum of bits shifted using CSW_* constants. For some reason, this doesn't work for HE grenades. It works as expected for knife, smoke, flash.

PHP Code:
#define DEFAULT_SKIPWEAPONS (1 << CSW_KNIFE) | (1 << CSW_C4) | (1 << CSW_FLASHBANG) | (1 << CSW_SMOKEGRENADE) | (1 << CSW_HEGRENADE)

---------------------------------

new 
bitsum[16];
num_to_str(DEFAULT_SKIPWEAPONSbitsumcharsmax(bitsum));
cvarSkipWeapons register_cvar("jb_rebel_skipweapons"bitsum);

---------------------------------

stock PlayerIsArmed(id) {
    new 
weapons[32];
    new 
weaponsnum;
    
get_user_weapons(idweaponsweaponsnum);
    new 
isArmed;
    for (new 
iweaponsnumi++) {
        
// Ignore these weapons
        
if (!((<< weapons[i]) & get_pcvar_num(cvarSkipWeapons))) {
            
client_print(0print_chat"Armed: %i, Skip: %i"weapons[i], get_pcvar_num(cvarSkipWeapons));
            
isArmed 1;
            break;
        }
    }
    return 
isArmed;

Code:
Armed: 4, Skip: 570425920
] amx_cvar jb_rebel_skipweapons
[AMXX] Cvar "jb_rebel_skipweapons" is "570425936"
Manually calculating the sum (Windows Calculator) gives me 570425936, as expected. Why is the number get_pcvar_num is giving me missing (1 << 4) (16)? If I only have a knife, it passes fine. With any gun, e.g. scout:
Code:
Armed: 3, Skip: 570425920
Which is also fine. The problem is HE grenades still pass the check when they shouldn't.

Is there any reason get_pcvar_num is giving me a different number from expected, and checked with amx_cvar and through the server console?

Thanks.

Last edited by Elusive138; 10-27-2011 at 06:51.
Elusive138 is offline
 



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 14:22.


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