Raised This Month: $51 Target: $400
 12% 

Get secondary weapon?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sekac
Senior Member
Join Date: Nov 2016
Old 07-10-2018 , 09:49   Get secondary weapon?
Reply With Quote #1

How to get someone's secondary weapon (pistol) even if they are not holding it?
sekac is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-10-2018 , 09:54   Re: Get secondary weapon?
Reply With Quote #2

You should get all weapons of the player and create a bit const with ids of pistols., that means:

Code:
const BITSUM_PISTOLS = ((1<<CSW_USP) | (1<<CSW_GLOCK18) | (1<<CSW_P228) | (1<<CSW_ELITE) | (1<<CSW_FIVESEVEN) | (1<<CSW_DEAGLE)) ... new rgWeapons[32], iWeaponsCount, iWeaponId; get_user_weapons(this, rgWeapons, iWeaponsCount); for (new i = 0; i < iWeaponsCount; i++) {     iWeaponId = rgWeapons[i];     if (!(BITSUM_PISTOLS & (1<<iWeaponId)))         continue;     // something with pistol... }
__________________








CrazY. is offline
sekac
Senior Member
Join Date: Nov 2016
Old 07-10-2018 , 10:15   Re: Get secondary weapon?
Reply With Quote #3

Thank you!
sekac is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-10-2018 , 10:16   Re: Get secondary weapon?
Reply With Quote #4

Or the better way:
PHP Code:
new const m_rgpPlayerItems_CBasePlayer[6] = {367,368,...}
new 
WeaponEnt get_pdata_cbase(idm_rgpPlayerItems_CBasePlayer[2])
new 
WeaponIndex cs_get_weapon_id(WeaponEnt
If he has multiple pistols then to get the others retrieve their index from m_pNext offset(get_pdata_cbase(WeaponEnt, m_pNext, 4)).
__________________

Last edited by HamletEagle; 07-10-2018 at 10:17.
HamletEagle is offline
sekac
Senior Member
Join Date: Nov 2016
Old 07-10-2018 , 10:29   Re: Get secondary weapon?
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
Or the better way:
PHP Code:
new const m_rgpPlayerItems_CBasePlayer[6] = {367,368,...}
new 
WeaponEnt get_pdata_cbase(idm_rgpPlayerItems_CBasePlayer[2])
new 
WeaponIndex cs_get_weapon_id(WeaponEnt
If he has multiple pistols then to get the others retrieve their index from m_pNext offset(get_pdata_cbase(WeaponEnt, m_pNext, 4)).

Thank you. Is there a way to directly get the weapon name from WeaponEnt or is get_weaponname necessary?
sekac is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-10-2018 , 10:40   Re: Get secondary weapon?
Reply With Quote #6

get_weaponname through weapon index and not through entity index or GetHamItemInfo through entity index.
__________________









Last edited by CrazY.; 07-10-2018 at 10:42.
CrazY. is offline
sekac
Senior Member
Join Date: Nov 2016
Old 07-10-2018 , 10:50   Re: Get secondary weapon?
Reply With Quote #7

How would I do it with GetHamItemInfo?
sekac is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-10-2018 , 11:01   Re: Get secondary weapon?
Reply With Quote #8

I'm not sure why you don't want to use get_weaponname... anyway, it's only for amx 1.8.3 and I believe you are using amx 1.8.2. Also, you just need to take a look at hamsandwich.inc and ham_cost.inc to understand how it works.
__________________








CrazY. is offline
sekac
Senior Member
Join Date: Nov 2016
Old 07-10-2018 , 11:06   Re: Get secondary weapon?
Reply With Quote #9

I switched to 1.8.3 recently. I will see if I can find out how it works.
sekac is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-10-2018 , 11:11   Re: Get secondary weapon?
Reply With Quote #10

pev_classname on WeaponEnt or get_weaponname on WeaponIndex. Don't overcomplicate things.
__________________

Last edited by HamletEagle; 07-10-2018 at 11:11.
HamletEagle 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 02:41.


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