AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   TF2Items (https://forums.alliedmods.net/forumdisplay.php?f=146)
-   -   Get slot of tf_wearable? (https://forums.alliedmods.net/showthread.php?t=266413)

boynedmaster 07-16-2015 15:12

Get slot of tf_wearable?
 
How can I get the slot # of a tf_wearable through TF2Items_OnGiveNamedItem

Powerlord 07-16-2015 16:48

Re: Get slot of tf_wearable?
 
Any particular reason you need to know the slot number?

Hell, TF2 can't even get cosmetic items slots correct for its own internal functions, such as CTFPlayer::GetEntityForLoadoutSlot, which returns nothing for slots 7 or 10, which are cosmetic 1 and 3 respectively.

For reference, loadout slots are:

0 = Primary
1 = Secondary
2 = Melee
3 = Utility
4 = Building
5 = Unknown
6 = PDA2
7 = Misc
8 = Misc
9 = Action
10 = Misc
11 = Taunt
12 = Taunt
13 = Taunt
14 = Taunt
15 = Taunt
16 = Taunt
17 = Taunt
18 = Taunt

Note: This was taken from g_szLoadoutStringsForDisplay in server_srv.so a while back, so Valve may have given them better names since then.

boynedmaster 07-16-2015 16:49

Re: Get slot of tf_wearable?
 
Quote:

Originally Posted by Powerlord (Post 2320419)
Any particular reason you need to know the slot number?

Hell, TF2 can't even get cosmetic items slots correct for its own internal functions, such as CTFPlayer::GetEntityForLoadoutSlot, which returns nothing for slots 7 or 10, which are cosmetic 1 and 3 respectively.

I need to check if they have a certain hat on, and I was thinking I could check their primary hat and see if the IDs match.

boynedmaster 07-16-2015 18:31

Re: Get slot of tf_wearable?
 
Is there another way I can check if a player has an item on?

Powerlord 07-16-2015 20:19

Re: Get slot of tf_wearable?
 
You can check an item's item definition index in TF2Items_OnGiveNamedItem.

pheadxdll 07-16-2015 20:37

Re: Get slot of tf_wearable?
 
Quote:

Originally Posted by boynedmaster (Post 2320421)
I need to check if they have a certain hat on, and I was thinking I could check their primary hat and see if the IDs match.

All the hats are in the same slot ( misc/8 ). So if you check by slot you will probably only get one hat the player is wearing. I would instead recommend looking at the m_hMyWearables netprop or by looping through all the wearables that belong to the player:
PHP Code:

int wearable MaxClients+1;
while((
wearable FindEntityByClassname(wearable"tf_wearable")) > MaxClients)
{
    if(
GetEntPropEnt(wearableProp_Send"m_hOwnerEntity") == client)
    {
        
// Wearable belongs to player.
    
}



boynedmaster 07-16-2015 20:45

Re: Get slot of tf_wearable?
 
Quote:

Originally Posted by Powerlord (Post 2320496)
You can check an item's item definition index in TF2Items_OnGiveNamedItem.

But that activates once for every hat.

boynedmaster 07-16-2015 21:23

Re: Get slot of tf_wearable?
 
Quote:

Originally Posted by pheadxdll (Post 2320510)
All the hats are in the same slot ( misc/8 ). So if you check by slot you will probably only get one hat the player is wearing. I would instead recommend looking at the m_hMyWearables netprop or by looping through all the wearables that belong to the player:
PHP Code:

int wearable MaxClients+1;
while((
wearable FindEntityByClassname(wearable"tf_wearable")) > MaxClients)
{
    if(
GetEntPropEnt(wearableProp_Send"m_hOwnerEntity") == client)
    {
        
// Wearable belongs to player.
    
}



How can I get the item ID?
GetEntPropEnt(wearable, Prop_Send, "m_iItemDefinitionIndex") returns -1

pheadxdll 07-16-2015 21:30

Re: Get slot of tf_wearable?
 
You almost had it! Use GetEntProp to get the integer value of the m_iItemDefinitionIndex netprop:
Code:

if(GetEntProp(wearable, Prop_Send, "m_iItemDefinitionIndex") == 1157)

boynedmaster 07-16-2015 21:46

Re: Get slot of tf_wearable?
 
Quote:

Originally Posted by pheadxdll (Post 2320525)
You almost had it! Use GetEntProp to get the integer value of the m_iItemDefinitionIndex netprop:
Code:

if(GetEntProp(wearable, Prop_Send, "m_iItemDefinitionIndex") == 1157)

Code:

PrintToServer("%d", GetEntProp(wearable, Prop_Send, "m_iItemDefinitionIndex"));
always prints -1


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

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