nosoop / SMExt-TF2Items

Custom patches on top of https://github.com/asherkin/TF2Items
5 stars 2 forks source link

TF2Items_OnGetLoadoutItem reports invalid handle? #2

Open keybangz opened 1 year ago

keybangz commented 1 year ago

It is of my understanding that TF2Items_OnGetLoadoutItem should pass through the TF2Item handle object of the already created items, however the handle passed is always invalid.

public Action TF2Items_OnGetLoadoutItem(int client, int class, int slot, Handle &item) {
    TF2Items_SetNumAttributes(item, 1); 
    TF2Items_SetQuality(item, 5); 

    TF2Items_SetAttribute(item, 0, 134, float(5)));

    return Plugin_Changed;
}

Creating an item and assigning it to the handle also breaks all weapons.

Using latest release r5

nosoop commented 1 year ago

Unfortunately your interpretation is incorrect — the behavior matches that of TF2Items_OnGiveNamedItem, which also initially assigns null to the item param and requires a new handle to be assigned by-ref with flags set to override specific properties.

Maybe it's worth reworking the API (that is, creating new forwards) to pass a full item definition instead, since it's a fairly common misunderstanding.

Creating an item and assigning it to the handle also breaks all weapons.

Got some sample code for that? Do note that additional validation checks are performed after OnGetLoadoutItem returns, so items not valid for the player / slot will still be ignored without further code patches.

keybangz commented 1 year ago

Unfortunately your interpretation is incorrect

Sounds about right. My apologies.

Got some sample code for that? Do note that additional validation checks are performed after OnGetLoadoutItem returns, so items not valid for the player / slot will still be ignored without further code patches.

item = TF2Items_CreateItem(OVERRIDE_ATTRIBUTES | PRESERVE_ATTRIBUTES);

Tried to grab current weapon slot classname, indexes & applying them to the newly created item but failed.

Maybe it's worth reworking the API (that is, creating new forwards) to pass a full item definition instead, since it's a fairly common misunderstanding.

Might look into that, I suppose at that point it's no different then modifying weapons in OnResupply right?

nosoop commented 1 year ago

Might look into that, I suppose at that point it's no different then modifying weapons in OnResupply right?

As long as the weapon on hand is the one you want to use; TF2Items_OnGetLoadoutItem would still be useful to change out the item definition index and class without creating an item drop.

item = TF2Items_CreateItem(OVERRIDE_ATTRIBUTES | PRESERVE_ATTRIBUTES);

Tried to grab current weapon slot classname, indexes & applying them to the newly created item but failed.

I'll have to recheck that at some point, but that forward does run before the initial weapon is granted as well.