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

Solved no chance for me to understand bits


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 11-15-2022 , 09:22   no chance for me to understand bits
Reply With Quote #1

Hi. Why does this method not work? When I pass any CSW_* constant, it returns me *not* random numbers but they're wrong.
Did I do something wrong?
Testing code:
PHP Code:
#include amxmodx
#include cstrike_const

const CSW_PRIMARY   = (CSW_ALL_SHOTGUNS CSW_ALL_SMGS CSW_ALL_RIFLES CSW_ALL_SNIPERRIFLES CSW_ALL_MACHINEGUNS);
const 
CSW_SECONDARY = (CSW_ALL_PISTOLS);
const 
CSW_GRENADES  = (CSW_ALL_GRENADES);

public 
plugin_init()
{
    new 
slotcachedszWeaponName[32];

    for(new 
wpn CSW_P228wpn <= CSW_P90wpn++)
    {
        
cached wpn;

        if(
get_weaponname(cachedszWeaponNamecharsmax(szWeaponName)))
        {
            
slot get_weapon_slot(cached);
            
console_print(0"%i :: %s :: Slot: %i"cachedszWeaponNameslot);
        }
    }
}

/** I'm asking about this method */
public get_weapon_slot(wpn)
{
    if(
wpn CSW_PRIMARY)   return CS_WEAPONSLOT_PRIMARY;
    if(
wpn CSW_SECONDARY) return CS_WEAPONSLOT_SECONDARY;
    if(
wpn CSW_KNIFE)     return CS_WEAPONSLOT_KNIFE;
    if(
wpn CSW_GRENADES)  return CS_WEAPONSLOT_GRENADE;
    return 
0;

Output:
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 11-15-2022 at 10:39.
kww is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-15-2022 , 10:25   Re: no chance for me to understand bits
Reply With Quote #2

your solution is to shift the wpn depending on the weapon ID

So your function should be as following.

PHP Code:
/** I'm asking about this method */
get_weapon_slot(wpn)
{
    
wpn = (1<<wpn);
    if(
wpn CSW_PRIMARY)   return CS_WEAPONSLOT_PRIMARY;
    if(
wpn CSW_SECONDARY) return CS_WEAPONSLOT_SECONDARY;
    if(
wpn CSW_KNIFE)     return CS_WEAPONSLOT_KNIFE;
    if(
wpn CSW_GRENADES)  return CS_WEAPONSLOT_GRENADE;
    return 
0;

__________________
@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
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 11-15-2022 , 10:39   Re: no chance for me to understand bits
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
your solution is to shift the wpn depending on the weapon ID

So your function should be as following.

PHP Code:
/** I'm asking about this method */
get_weapon_slot(wpn)
{
    
wpn = (1<<wpn);
    if(
wpn CSW_PRIMARY)   return CS_WEAPONSLOT_PRIMARY;
    if(
wpn CSW_SECONDARY) return CS_WEAPONSLOT_SECONDARY;
    if(
wpn CSW_KNIFE)     return CS_WEAPONSLOT_KNIFE;
    if(
wpn CSW_GRENADES)  return CS_WEAPONSLOT_GRENADE;
    return 
0;

bruh... That's it? I forgot it's not shifted. Thank you
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951
kww is offline
Reply



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 17:31.


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