AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get secondary weapon? (https://forums.alliedmods.net/showthread.php?t=309012)

sekac 07-10-2018 09:49

Get secondary weapon?
 
How to get someone's secondary weapon (pistol) even if they are not holding it?

CrazY. 07-10-2018 09:54

Re: Get secondary weapon?
 
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... }

sekac 07-10-2018 10:15

Re: Get secondary weapon?
 
Thank you!

HamletEagle 07-10-2018 10:16

Re: Get secondary weapon?
 
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)).

sekac 07-10-2018 10:29

Re: Get secondary weapon?
 
Quote:

Originally Posted by HamletEagle (Post 2602650)
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?

CrazY. 07-10-2018 10:40

Re: Get secondary weapon?
 
get_weaponname through weapon index and not through entity index or GetHamItemInfo through entity index.

sekac 07-10-2018 10:50

Re: Get secondary weapon?
 
How would I do it with GetHamItemInfo?

CrazY. 07-10-2018 11:01

Re: Get secondary weapon?
 
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.

sekac 07-10-2018 11:06

Re: Get secondary weapon?
 
I switched to 1.8.3 recently. I will see if I can find out how it works.

HamletEagle 07-10-2018 11:11

Re: Get secondary weapon?
 
pev_classname on WeaponEnt or get_weaponname on WeaponIndex. Don't overcomplicate things.


All times are GMT -4. The time now is 12:24.

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