AddItem directly to stash

edited April 2018 in Questions

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!!!!"
    hero:SwapItems(index, self:FindEmptyStashSlot(eHero, DOTA_STASH_SLOT_1))

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.


  • edited April 2018 Posts: 32

    You can try the SetItemAddedToInventoryFilter()

    When you add an item to the hero or the hero pickup an item will touch it

    SetItemAddedToInventoryFilter(function( kv )
        kv.suggested_slot = DOTA_STASH_SLOT_1
        return true
  • Thank you. This looks promising. However I have not found anyone who has used the function like this. Can you elaborate on what is the input argument? Is it the item? Is it a handle? Then you have used .suggested_slot, is that to make a point or is it something the scripting supplies? (I haven't found this mentioned anywhere..)