skadistats / clarity-examples

Example code for clarity
BSD 3-Clause "New" or "Revised" License
113 stars 37 forks source link

Getting hero items #14

Closed ericp1337 closed 8 years ago

ericp1337 commented 8 years ago

I was wondering how I would go about getting the players items at the end of the game. I looked at the example for getting the end of game stats, but am unsure how to go about getting the list of items a player has in their inventory when the game is finished.

I suspect i have to tell it the field path but am unsure what that would be or how to get it.

Thanks

spheenik commented 8 years ago

First, you gotta get hold of the hero entity.

Those hero entities have properties m_hItems.XXXX (XXXX being a number, 0000 for the first item). The value of the property is a "handle", you can get the corresponding item-entity with ctx.getProcessor(Entities.class).getByHandle(theHandleFromTheHeroEntity)

To find out exactly what item it is, the item has a property m_pEntity.m_nameStringableIndex, which is an index into a StringTable (dunno exact name, something along the lines of "EntityNames").

Good luck!

TodorovicF commented 8 years ago

So I noticed that m_hItems.XXXX goes between 0000-0013. If there are only 6 hero backpack slots, what are the other 8 slots used for?

spheenik commented 8 years ago

Good question, I'm guessing this is probably to not restrain custom games to 6 items? Or maybe it's the stash?

TodorovicF commented 8 years ago

Thanks! I'll take a look and see what they are. Would be great if the stash is included there.

spheenik commented 8 years ago

It was indeed the stash :)