-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathTroll.lua
85 lines (70 loc) · 3.24 KB
/
Troll.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
-- File: Troll.lua
-- Author: EroicaCpp (https://github.com/Eroica-cpp/dota2scripts)
-- Version: 2.0
-- Release Date: 2017/5/24
local Troll = {}
local optionAutoSwap = Menu.AddOption({"Hero Specific", "Troll Warlord"}, "Auto Swap", "Auto Swap between range and melee")
local optionEnableKey = Menu.AddOption({"Hero Specific", "Troll Warlord"}, "Enable Key", "On/Off")
local keyAxeMelee = Menu.AddKeyOption({"Hero Specific", "Troll Warlord"}, "Whirling Axe (Melee) Key", Enum.ButtonCode.KEY_W)
local keyAxeRanged = Menu.AddKeyOption({"Hero Specific", "Troll Warlord"}, "Whirling Axes (Ranged) Key", Enum.ButtonCode.KEY_E)
function Troll.OnPrepareUnitOrders(orders)
if not Menu.IsEnabled(optionAutoSwap) then return true end
if not orders then return true end
local myHero = Heroes.GetLocal()
if not myHero or NPC.GetUnitName(myHero) ~= "npc_dota_hero_troll_warlord" then return true end
if NPC.IsStunned(myHero) or NPC.IsSilenced(myHero) then return true end
local swap = NPC.GetAbilityByIndex(myHero, 0)
if not swap or not Ability.IsCastable(swap, 0) then return true end
-- swap to melee when running
if not Ability.GetToggleState(swap) and
(orders.order == Enum.UnitOrder.DOTA_UNIT_ORDER_MOVE_TO_POSITION
or orders.order == Enum.UnitOrder.DOTA_UNIT_ORDER_MOVE_TO_TARGET
or orders.order == Enum.UnitOrder.DOTA_UNIT_ORDER_ATTACK_MOVE)
then
Ability.Toggle(swap, true)
return true
end
-- auto swap between melee and range
local melee_attack_range = 150
local range = melee_attack_range + 100
if orders.order == Enum.UnitOrder.DOTA_UNIT_ORDER_ATTACK_TARGET then
if NPC.IsEntityInRange(myHero, orders.target, range) and not Ability.GetToggleState(swap) then
Ability.Toggle(swap, true)
return true
end
if not NPC.IsEntityInRange(myHero, orders.target, range) and Ability.GetToggleState(swap) then
Ability.Toggle(swap, true)
return true
end
end
return true
end
function Troll.OnUpdate()
if not Menu.IsEnabled(optionEnableKey) then return end
local myHero = Heroes.GetLocal()
if not myHero or NPC.GetUnitName(myHero) ~= "npc_dota_hero_troll_warlord" then return end
local swap = NPC.GetAbility(myHero, "troll_warlord_berserkers_rage")
local axe_melee = NPC.GetAbility(myHero, "troll_warlord_whirling_axes_melee")
local axe_ranged = NPC.GetAbility(myHero, "troll_warlord_whirling_axes_ranged")
-- melee axe
if Menu.IsKeyDownOnce(keyAxeMelee) and Ability.IsCastable(axe_melee, NPC.GetMana(myHero)) then
if swap and not Ability.GetToggleState(swap) then
Ability.Toggle(swap)
Ability.CastNoTarget(axe_melee)
Ability.Toggle(swap)
else
Ability.CastNoTarget(axe_melee)
end
end
-- ranged axe
if Menu.IsKeyDownOnce(keyAxeRanged) and Ability.IsCastable(axe_ranged, NPC.GetMana(myHero)) then
if swap and Ability.GetToggleState(swap) then
Ability.Toggle(swap)
Ability.CastPosition(axe_ranged, Input.GetWorldCursorPos())
Ability.Toggle(swap)
else
Ability.CastPosition(axe_ranged, Input.GetWorldCursorPos())
end
end
end
return Troll