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_SKIPWEAPONS, bitsum, charsmax(bitsum));
cvarSkipWeapons = register_cvar("jb_rebel_skipweapons", bitsum);
---------------------------------
stock PlayerIsArmed(id) {
new weapons[32];
new weaponsnum;
get_user_weapons(id, weapons, weaponsnum);
new isArmed;
for (new i; i < weaponsnum; i++) {
// Ignore these weapons
if (!((1 << weapons[i]) & get_pcvar_num(cvarSkipWeapons))) {
client_print(0, print_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.