Raised This Month: $ Target: $400
 0% 

[HELP] Explaining Strip Stock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 02-13-2017 , 11:59   [HELP] Explaining Strip Stock
Reply With Quote #1

So i found this weapon strip stock, and i was looking over to learn couple things from it when i got the the lines i marked with red

What i don't understand is why get the weapon's name using it's index, in order to pass it to the next stock to retrieve it's index using it's name when you could simply pass directly the index ? o.O

Code:
stock strip_weapons(iPlayer, iType)
{
	new iWeapons[32], iNum, iWeaponID
	get_user_weapons(iPlayer, iWeapons, iNum)

	for (new x = 0; x < iNum; x++)
	{
		iWeaponID = iWeapons[x]

		if ((1<<iWeaponID) & iType)
		{
			new szWeaponName[32]
			get_weaponname(iWeaponID, szWeaponName, charsmax(szWeaponName))

			ham_strip_weapon(iPlayer, szWeaponName)

			cs_set_user_bpammo(iPlayer, iWeaponID, 0)
		}
	}
}

stock ham_strip_weapon(iPlayer, const szWeapon[])
{
	new iWeaponID = get_weaponid(szWeapon)

	if (!pev_valid(iWeaponID))
		return false;

	new iEntity = ks_get_entity_owner(-1, szWeapon, iPlayer)

	if (!pev_valid(iEntity))
		return false;

	new iWeaponEntity = ks_get_weapon_owner(iPlayer)
	new iWeapon = pev_valid(iWeaponEntity) ? cs_get_weapon_id(iWeaponEntity) : -1

	if (iWeapon == iEntity)
		ExecuteHamB(Ham_Weapon_RetireWeapon, iEntity)

	if(!ExecuteHamB(Ham_RemovePlayerItem, iPlayer, iEntity))
		return false;

	ExecuteHamB(Ham_Item_Kill, iEntity)

	set_pev(iPlayer, pev_weapons, pev(iPlayer, pev_weapons) & ~(1<<iWeaponID))

	return true;
}
__________________

Last edited by Depresie; 02-13-2017 at 12:02.
Depresie is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-13-2017 , 12:03   Re: [HELP] Explaining Strip Stock
Reply With Quote #2

I'm not sure why in the ham_strip_weapon stock get_weaponid is used.. You can simply use the weapon name (weapon_).
In strip_weapons get_weaponname is used to get the weapon name in weapon_ method (weapon_ak47) because get_user_weapons returns weapon name in CSW_ form (CSW_AK47).
__________________

Last edited by edon1337; 02-13-2017 at 12:07.
edon1337 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-13-2017 , 12:57   Re: [HELP] Explaining Strip Stock
Reply With Quote #3

Theres two id for the weapon

First id is the weapon entity in the world that player holds or dropped on the ground which its not constant entity id...

Second id is the weapon id which its constant & defined ex : CSW_GLOCK18

Last edited by Natsheh; 02-13-2017 at 13:00.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Depresie
Veteran Member
Join Date: Nov 2013
Old 02-13-2017 , 13:30   Re: [HELP] Explaining Strip Stock
Reply With Quote #4

I was thinking about that, but i don't get this

In the first stock the index we retrieve is is the index of the weapon ( CSW_* ) since we compare it with the CSW_* bitsum ( iType )

Then we retrieve it's name ( weapon_* )

Then in the second stock, iWeaponID cannot be the entity index, because we retrieve just one by the name of the weapon, and there are multiple weapons with the same name also the entity index is actually retrieved after with get_entity_by_owner ( ks_get_entity_owner )

In conclusion we retrieve the weapon index in the second stock while we already retrieved it in the first...
__________________

Last edited by Depresie; 02-13-2017 at 13:33.
Depresie is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-13-2017 , 13:39   Re: [HELP] Explaining Strip Stock
Reply With Quote #5

NVM, get_weaponid is used to check for pev_valid.

@Depresie what iType are you talking about? Can you mark the line you don't understand?
__________________
edon1337 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-13-2017 , 13:58   Re: [HELP] Explaining Strip Stock
Reply With Quote #6

Quote:
Originally Posted by edon1337 View Post
NVM, get_weaponid is used to check for pev_valid.

@Depresie what iType are you talking about? Can you mark the line you don't understand?
iType is a bitsum constant to define which wpns to strip from the player 4 example SECONDARILY_WPNS = (1<<CSW_USP) | (1<<CSW_GLOCK) | .....etc pistols...

Last edited by Natsheh; 02-15-2017 at 17:41.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 21:00.


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