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

ham_get_user_weaponent [CSTRIKE]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-18-2009 , 13:20   ham_get_user_weaponent [CSTRIKE]
Reply With Quote #1

This function returns the weapon entity index by player id weapon type, and optional weapon slot.

Code:
#define SHOTGUNS_BITSUM ((1<<CSW_XM1014)|(1<<CSW_M3)) #define SMGS_BITSUM  ((1<<CSW_MAC10)|(1<<CSW_UMP45)|(1<<CSW_MP5NAVY)|(1<<CSW_TMP)|(1<<CSW_P90)) #define RIFFLES_BITSUM  ((1<<CSW_AUG)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_M249)|(1<<CSW_M4A1)|(1<<CSW_SG552)|(1<<CSW_AK47)) #define SNIPERS_BITSUM  ((1<<CSW_SCOUT)|(1<<CSW_SG550)|(1<<CSW_AWP)|(1<<CSW_G3SG1)) #define PRIMARIES_BITSUM    (SHOTGUNS_BITSUM|SMGS_BITSUM|RIFFLES_BITSUM|SNIPERS_BITSUM) #define GUNS_BITSUM  ((1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)) #define NADES_BITSUM    ((1<<CSW_HEGRENADE)|(1<<CSW_SMOKEGRENADE)|(1<<CSW_FLASHBANG)) #define MAX_ITEM_TYPES 6 // These offsets handle last weapon entity that the player gained // If the player has more than one weapon in the same slot, // other weapons are linked to the last one with offset cbased m_pNext // (weapon A is linked to B, weapon B is linked to C, etc..) new const m_rgpPlayerItems_CBasePlayer[MAX_ITEM_TYPES] = {367,368,...} // added CBasePlayer to offset name because CWeaponBoc class has same offset name // "weapon_..." offsets #define LD_CBasePlayerItem  4 // This offset is used to link a weapon with another one #define m_pNext        42 // This offset handles CSW_... values of the weapons #define m_iId                43  ham_get_user_weaponent(id, iCswId, iSlot = 0) {     new iWeapon     if( !iSlot )     {         if( PRIMARIES_BITSUM & (1<<iCswId) ) iSlot = 1         else if( GUNS_BITSUM & (1<<iCswId) ) iSlot = 2         else if( iCswId == CSW_KNIFE ) iSlot = 3         else if( NADES_BITSUM & (1<<iCswId) ) iSlot = 4         else if( iCswId == CSW_C4 ) iSlot = 5     }     // get the last weapon that the player gained in this slot     iWeapon = get_pdata_cbase(id, m_rgpPlayerItems_CBasePlayer[iSlot])     while( pev_valid(iWeapon) ) // >0 check should be enough, i let pev_valid for the tut     {         // Check if the weapon type (CSW_) is the one we are searching         if( get_pdata_int(iWeapon, m_iId, LD_CBasePlayerItem) == iCswId ) // can use cs_get_weapon_id(iWeapon) instead         {             // return the weapon entity index             return iWeapon         }         // if not, search if another weapon is linked to the previous one         iWeapon = get_pdata_cbase(iWeapon, m_pNext, LD_CBasePlayerItem)     }     // return 0 on failure     return 0 }


You can use this shortest but less efficient code :


PHP Code:
#define MAX_ITEM_TYPES 6
new const m_rgpPlayerItems_CBasePlayer[MAX_ITEM_TYPES] = {367,368,...}

#define LD_CBasePlayerItem    4
#define    m_pNext                42
#define    m_iId                43

ham_get_user_weaponent2(idiCswId)
{
    new 
iWeapon
    
for(new i=1i<MAX_ITEM_TYPESi++)
    {
        
iWeapon get_pdata_cbase(idm_rgpPlayerItems_CBasePlayer[i])
        while( 
pev_valid(iWeapon) )
        {
            if( 
get_pdata_int(iWeaponm_iIdLD_CBasePlayerItem) == iCswId )
            {
                return 
iWeapon
            
}
            
iWeapon get_pdata_cbase(iWeaponm_pNextLD_CBasePlayerItem)
        }
    }
    return 
0


Or the often used only fakemeta way :

PHP Code:
fm_get_user_weaponent(idiCswId)
{
    new 
szWeaponName[20]
    if( !
get_weaponname(iCswIdszWeaponNamecharsmax(szWeaponName)) )
        return 
FM_NULLENT

    
new iWeapon FM_NULLENT
    
while(    (iWeapon engfuncEngFunc_FindEntityByStringiWeapon"classname"szWeaponName )) > 0
            
&&    pev(iWeaponpev_owner) != id        )
    { 
/* do nothing */ }

    return 
iWeapon

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-06-2012 at 19:08.
ConnorMcLeod is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 02-18-2009 , 14:04   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #2

Sorry I don't understood, this is something like get_user_weapon?
xbatista is offline
Send a message via Skype™ to xbatista
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-18-2009 , 14:13   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #3

Quote:
Originally Posted by xbatista View Post
Sorry I don't understood, this is something like get_user_weapon?
Quote:
Originally Posted by ConnorMcLeod View Post
This function returns the weapon entity index
This is the entity index, you need it for example to use cs_s/get_weapon_burst or cs_g/set_weapon_silen.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 02-18-2009 , 14:18   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #4

Thx ;) Now I understand.
Quote:
This is the entity index, you need it for example to use cs_s/get_weapon_burst or cs_g/set_weapon_silen.
xbatista is offline
Send a message via Skype™ to xbatista
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 02-18-2009 , 14:39   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #5

Thanks Connor. Great yours Helps.
+Karma
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
vittu
SuperHero Moderator
Join Date: Oct 2004
Location: L.A. County, CA
Old 02-18-2009 , 14:39   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #6

Thanks Connor, I was actually going to start looking into another method for this instead the the fakemeta way which i was currently using. Luckily I didn't have to look too long as you just posted this.


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

Oddly though, I came across this in someones code:
Code:
new wEnt = ExecuteHam(Ham_Item_GetWeaponPtr, id, CSW_DEAGLE)

Anyone know if this would work as intended?

ham_const shows a different format for it's usage (could it's comments be wrong?):
Code:
    /**      * Description:  Returns the entity index if the item is a weapon, -1 otherwise.      * Forward params:  function(this)      * Return type:  Entity.      * Execute Params:  ExecuteHam(Ham_Item_GetWeaponPtr, this)      */     Ham_Item_GetWeaponPtr,
vittu is offline
Send a message via AIM to vittu Send a message via MSN to vittu Send a message via Yahoo to vittu
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-18-2009 , 14:57   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #7

I don't think so, it seems that you should use this function with the already entity index.

May be it's the same (or reverse) as get_pdata_cbase, i'm not sure though.

Something like :

iWeaponEnt = get_pdata_cbase(id, OFFSET, 5)

ExecuteHam(Ham_Item_GetWeaponPtr, iWeaponEnt) == get_pdata_int(id, OFFSET, 5)

More chances that it is something like index_to_pointer from vexdum
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 02-18-2009 at 15:06.
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-18-2009 , 15:09   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #8

So far I understand ExecuteHam(Ham_Item_GetWeaponPtr, Entity) will return Entity ( not the pointer, the same provided entity ) if this one is a weapon, otherwise -1. Passing a player's id would return -1 since it's not a weapon.

Last edited by Arkshine; 02-18-2009 at 15:17.
Arkshine is offline
vittu
SuperHero Moderator
Join Date: Oct 2004
Location: L.A. County, CA
Old 02-18-2009 , 15:49   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #9

So basically it's a verification check to see if the ent id supplied is a weapon?
vittu is offline
Send a message via AIM to vittu Send a message via MSN to vittu Send a message via Yahoo to vittu
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-18-2009 , 15:55   Re: ham_get_user_weaponent [CSTRIKE]
Reply With Quote #10

Yep, I tried and seems that it does nothing else.

In HLSDK :
Code:
virtual CBasePlayerItem *GetWeaponPtr( void ) { return (CBasePlayerItem *)this; };

Last edited by Arkshine; 02-18-2009 at 15:58.
Arkshine 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 19:37.


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