skadistats / clarity-examples

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

Hero Inventory #10

Closed kerstenc closed 9 years ago

kerstenc commented 9 years ago

I am trying to get the heroes inventory at different times using the below code:

//get hero inventory
for(int slot = 0; slot <= 13; slot++){
    String slotNumber = String.format("%02d", slot);                            
    int item_id = (int)getEntityProperty(e, "m_hItems.00"+slotNumber, null);

    Entity item = ctx.getProcessor(Entities.class).getByHandle(item_id);
    if (item != null) {
        entry.items[slot] = item.getDtClass().getDtName().toLowerCase();
    } else {
        entry.items[slot] = Integer.toString(item_id);
    }
}

The issue that I'm having is that I'm getting a generic CDOTA_Item class for most of the items. Any reason why this might be happening?

Thanks in advance

spheenik commented 9 years ago

When the item is generic and needs no special implementation, it's class will be CDOTA_Item. To retrieve the name, annotate your processor class with

@UsesStringTable("EntityNames")

and retrieve the name of the entity with

        Entities entities = ctx.getProcessor(Entities.class);
        StringTables stringTables = ctx.getProcessor(StringTables.class);
        Entity item = entities.getByHandle(itemHandle);
        if (item != null) {
            Integer idx = item.getProperty("m_pEntity.m_nameStringableIndex");
            String name = stringTables.forName("EntityNames").getNameByIndex(idx);
        }

and yes, that typo in "StringableIndex" was in my replay, might be fixed in yours :)

kerstenc commented 9 years ago

Thanks a million @spheenik! Worked like a charm :)