-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathAutoStash.lua
142 lines (120 loc) · 4.6 KB
/
AutoStash.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
local AutoStash = {}
AutoStash.optionEnable = Menu.AddOption({ "Utility", "Auto Stash Item" }, "Enable", "Auto stash items when in base")
AutoStash.dontStashList = {
item_aegis = true,
item_soul_ring = true,
item_rapier = true,
item_tpscroll = true,
item_wind_lace = true,
item_boots = true,
item_tranquil_boots = true,
item_phase_boots = true,
item_travel_boots = true,
item_travel_boots_2 = true,
item_quelling_blade = true,
item_iron_talon = true,
item_blink = true,
item_infused_raindrop = true,
item_bottle = true,
item_faerie_fire = true,
item_flask = true, -- healing salve
item_clarity = true,
item_tango = true,
item_tango_single = true,
item_enchanted_mango = true,
item_smoke_of_deceit = true,
item_dust = true,
item_ward_observer = true,
item_ward_sentry = true,
item_recipe_ward_dispenser = true,
item_ward_dispenser = true,
item_gem = true,
item_hand_of_midas = true,
item_stout_shield = true,
item_poor_mans_shield = true
}
-- stash items when (1) using soul ring in base; (2) using bottle in base
function AutoStash.OnPrepareUnitOrders(orders)
if not Menu.IsEnabled(AutoStash.optionEnable) then return true end
if not orders or not orders.ability then return true end
local myHero = Heroes.GetLocal()
if not myHero then return true end
if Entity.IsAbility(orders.ability)
and Ability.GetName(orders.ability) == "item_soul_ring"
and NPC.HasModifier(myHero, "modifier_fountain_aura_buff") then
AutoStash.inventory2stash(myHero)
end
if Entity.IsAbility(orders.ability)
and Ability.GetName(orders.ability) == "item_bottle"
and NPC.HasModifier(myHero, "modifier_fountain_aura_buff") then
AutoStash.inventory2stash(myHero)
end
return true
end
function AutoStash.OnUpdate()
if not Menu.IsEnabled(AutoStash.optionEnable) then return end
local myHero = Heroes.GetLocal()
if not myHero then return end
-- move items back to inventory afer using soul ring
if NPC.HasModifier(myHero, "modifier_fountain_aura_buff")
and NPC.HasModifier(myHero, "modifier_item_soul_ring_buff") then
local mod = NPC.GetModifier(myHero, "modifier_item_soul_ring_buff")
if GameRules.GetGameTime() - Modifier.GetCreationTime(mod) > 0.1 then
AutoStash.stash2inventory(myHero)
end
end
-- move items back to inventory afer using bottle
if NPC.HasModifier(myHero, "modifier_fountain_aura_buff")
and NPC.HasModifier(myHero, "modifier_bottle_regeneration") then
local mod = NPC.GetModifier(myHero, "modifier_bottle_regeneration")
if GameRules.GetGameTime() - Modifier.GetCreationTime(mod) > 0.5 then
AutoStash.stash2inventory(myHero)
end
end
-- when healed by shrine
if NPC.HasModifier(myHero, "modifier_filler_heal") then
local enemyUnits = NPC.GetHeroesInRadius(myHero, 1000, Enum.TeamType.TEAM_ENEMY)
local mod = NPC.GetModifier(myHero, "modifier_filler_heal")
if #enemyUnits <= 0 and GameRules.GetGameTime()-Modifier.GetCreationTime(mod) < 0.1 then
AutoStash.tmpMoveItem2Backpack(myHero)
end
end
end
function AutoStash.tmpMoveItem2Backpack(myHero)
local tmp_slot = 8
for i = 0, 5 do
local item = NPC.GetItemByIndex(myHero, i)
if item then
local itemName = Ability.GetName(item)
if not AutoStash.dontStashList[itemName] then
AutoStash.moveItemToSlot(myHero, item, tmp_slot)
AutoStash.moveItemToSlot(myHero, item, i)
end
end
end
end
function AutoStash.inventory2stash(myHero)
local delta = 9
for i = 0, 5 do
local item = NPC.GetItemByIndex(myHero, i)
if item and not NPC.GetItemByIndex(myHero, i+delta) then
local itemName = Ability.GetName(item)
if not AutoStash.dontStashList[itemName] then
AutoStash.moveItemToSlot(myHero, item, i+delta)
end
end
end
end
function AutoStash.stash2inventory(myHero)
local delta = 9
for i = 9, 14 do
local item = NPC.GetItemByIndex(myHero, i)
if item and not NPC.GetItemByIndex(myHero, i-delta) then
AutoStash.moveItemToSlot(myHero, item, i-delta)
end
end
end
function AutoStash.moveItemToSlot(myHero, item, slot_index)
Player.PrepareUnitOrders(Players.GetLocal(), Enum.UnitOrder.DOTA_UNIT_ORDER_MOVE_ITEM, slot_index, Vector(0, 0, 0), item, Enum.PlayerOrderIssuer.DOTA_ORDER_ISSUER_PASSED_UNIT_ONLY, myHero)
end
return AutoStash