As I mentioned - probably above in this thread - handles are no item handles but 'slot handles' or better 'handles of objects that occupy one slot in a container'.
That is the reason why the query GetItemHandleForItemTemplateInInventory() (or similar ;-) does not return a tuple but a single entry for a stack of items.
Since weapons and armor are not stackable, crafting them for sale is real poison in the whole handle problem context.
Sorry to ask again: so we speak of 'handles of objects that occupy one slot in a
certain container/character inventory' and not of 'handles of objects that occupy one slot in
any container or character inventory'? So is the handle for a stack of objects or a slot with objects? And: is a new handle created when I move a stack of objects to another character inventory or container?
No, the problem here is only a non-native speaker being unable to clearly say what he means ;-)
The container does not matter at all. It's the same for any container including our character inventories and bags we might have in our inventories.
What I was trying to say was, that we have to be careful when dealing with _ItemHandles, because they do not represent a single item but a complete stack of items. For items that cannot stack like armor or weapons of course, this makes no difference, but it does for all items that are stackable, like basically all ingredients. Which matters for you because you need to deal with ingredients in your crfting mod.
You mentioned before that you don't use something like ItemHandleDelete but something like ItemTemplateRemoveFromCharacter which most likely has an _Amount parameter, so you are not affected.
Just keep in mind that if you ever deal with handles, you have to be careful.
Though for some reason I thought there already was a trader DB somewhere, which is why I thought generic flavor NPCS like those around the docks might not regenerate based on time/level. I'd look at what calls GenTradeItems and see which _Trader's get passed.
It seems Osiris iterates all characters when the goal _NPC_Stats is initiated and starts a process to add them to DB_Trader if certain conditions are fulfilled:
PROC
CreateDefaultTradeStats((CHARACTER)_Npc)
AND
NOT DB_NoInitialTrade(_Npc)
AND
NOT DB_EvilDude(_Npc)
AND
CharacterIsTagged(_Npc, "Animal", 0)
THEN
DB_Trader(_Npc);
It doesn't except trading NPCs from trade item generation.
Side note: pickpocket requests also start the GenTradeItems process.
Well, all that matters in the context of treasure generation is, if the call GenerateItems() is ever reached or not. (or CharacterGenerateCustomTradeTreasure())
Those are the Osiris calls that actually trigger treasure generation - and handle use.
Everything else is only setting internal Osiris facts to determine if those calls can be reached or not.
There are other calls of course like CharacterSetCanTrade() which probably only affect if the trade diamond button shows up in a dialog or not.
And yes, Pickpocketing can also start a trade generation, which is no different from the 'regular' trade generation before trading. (After all the game must make sure that the pickpocketed character carries something that can be looted.)
The thing that is still unclear to me is, if characters have the same generation as real containers (barrels, chests, ...), both use treasure tables but the engine could differentiate between them by looking at the root template type, one being a character, the other an item.
If characters also have their treasure pre-created every player levelup and on every zoning, it might be a massive waste of handles. Because on top of that comes the required generation after the stack of items 'waiting in the background' has been 'claimed' by an NPC through an Osiris call.
So there seem to be at least two cases of treasure generation, the standard one on player levelup and zoning - done by the engine alone - and the other on explicit Osiris calls like GenerateItems() (which works only for characters).
The GenerateItems() call looks weird because it takes two characters as parameters, but maybe that is only a relic from previous games. Trade treasure does not change if you trade with different characters, unless a generation is explicitely triggered by character level differences.
I have no idea why the call requires two characters.