AddItem directly to stash
Is there a way, how to addItem directly to hero's stash?
I have got a few functions that check if the hero is in range of the correct shop type. If he is not, then the item should go to stash. However I haven't found a way how to do that correctly.
Currently I add the item by AddItem(itemName) function and I find the item in inventory and swap it with first empty slot in stash. This has several drawbacks. Items that are added to inventory and are stackable will get stacked before moving and the function will then move the entire stack to stash. Also if you buy item that is the last component to some item, you are no longer able to move it to stash (as it combines and looses its name).
Here is the code:
self:BuyAndAddItem(eHero, itemName) local index = self:FindItemInInventory(itemName, eHero)
if index == -1 then Warning("I have not found the item!!!!" return else hero:SwapItems(index, self:FindEmptyStashSlot(eHero, DOTA_STASH_SLOT_1)) end
Is there a way how to move item directly to stash? Am I missing some function, that would do the buiyng for me (with range checks etc.)?
One solution might be to swap stash with inventory, buy the item and then swap it back. But you can have some components in your backpack, or the items might combine while swapping.