View Single Post
nosoop
Veteran Member
Join Date: Aug 2014
Old 11-20-2019 , 12:12   Re: [TF2] Client game crash when the client get a weapon
Reply With Quote #10

Quote:
Originally Posted by PC Gamer View Post
I think maybe there is a problem with TF2_GetPlayerLoadoutSlot incorrectly because it always returns slot 8 for any wearable. I tested this with the tf2wearables_test plugin and found similar result. In other words, when I have three wearable items equipped the 'checkmyitems' command will only show one wearable in slot 8.

The impact is that it when I try to remove an item it will usually remove the wrong item.

Any idea on what I can do to fix the problem?
Ah, my mistake; thought it'd show all the wearables there. I was also operating under the assumption that you were only dealing with wearable-based weapons and not actual cosmetics.

Besides the solution by iterating all wearables in the above post, you can also read from the client's m_hMyWearables property. However, it's pretty unsafe -- the offset isn't exposed by the game so you'll need to maintain that information yourself, and since SourceMod doesn't have any facilities to read entity handle / reference values from arbitrary memory locations (yet?), that's something you'd also have to do.

Otherwise, I'm not sure how you expect to identify which specific wearable you want to remove.

If you actually want to do that, here's a snippet for it.

Quote:
Originally Posted by Whai View Post
The reason that I didn't use tf2 econ data is because of this: [...]
That's what the schema supports. You can recreate the item slot functionality by parsing the item_slot schema value. That's pretty much what TF2II and TF2IDB would need to do.

If you've already instantiated a new weapon entity, you can also SDKCall its Weapon_GetSlot function to determine what weapon slot needs to be replaced.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline