AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Explaining Strip Stock (https://forums.alliedmods.net/showthread.php?t=293881)

Depresie 02-13-2017 11:59

[HELP] Explaining Strip Stock
 
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;
}


edon1337 02-13-2017 12:03

Re: [HELP] Explaining Strip Stock
 
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).

Natsheh 02-13-2017 12:57

Re: [HELP] Explaining Strip Stock
 
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

Depresie 02-13-2017 13:30

Re: [HELP] Explaining Strip Stock
 
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...

edon1337 02-13-2017 13:39

Re: [HELP] Explaining Strip Stock
 
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?

Natsheh 02-13-2017 13:58

Re: [HELP] Explaining Strip Stock
 
Quote:

Originally Posted by edon1337 (Post 2495194)
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...


All times are GMT -4. The time now is 21:00.

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