-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFailSwitch.lua
115 lines (95 loc) · 4.27 KB
/
FailSwitch.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
local failSwitch= {}
failSwitch.optionEnable = Menu.AddOption({ "Utility", "Fail Switch"}, "Enable", "Stop ultimate if no enemy in radius")
failSwitch.optionKey = Menu.AddKeyOption({ "Utility", "Fail Switch"}, "Force Cast Key", Enum.ButtonCode.KEY_P)
failSwitch.ultiRadius = {enigma_black_hole = 420, magnataur_reverse_polarity = 410, faceless_void_chronosphere = 425}
failSwitch.castPoint = {enigma_black_hole = 0.3, magnataur_reverse_polarity = 0.3, faceless_void_chronosphere = 0.35}
failSwitch.castPosition = Vector(0,0,0)
failSwitch.castAbilityName = ""
failSwitch.animationEndTime = 0
function failSwitch.OnUpdate()
failSwitch.CheckOnAnimationEnd()
if not Menu.IsEnabled(failSwitch.optionEnable) then return true end
if not Menu.IsKeyDown(failSwitch.optionKey) then return end
local myHero = Heroes.GetLocal()
local mousePos = Input.GetWorldCursorPos()
local myMana = NPC.GetMana(myHero)
local ulti = NPC.GetAbilityByIndex(myHero, 3)
if ulti ~= nil and Ability.IsCastable(ulti, myMana) then
local name =Ability.GetName(ulti)
Log.Write(name)
if name == "enigma_black_hole" or name == "faceless_void_chronosphere" then
Ability.CastPosition(ulti, mousePos)
elseif name == "magnataur_reverse_polarity" then
Ability.CastNoTarget(ulti)
end
end
end
function failSwitch.OnPrepareUnitOrders(orders)
if not Menu.IsEnabled(failSwitch.optionEnable) then return true end
if not orders.ability then return true end
if not (orders.order == Enum.UnitOrder.DOTA_UNIT_ORDER_CAST_POSITION or orders.order == Enum.UnitOrder.DOTA_UNIT_ORDER_CAST_NO_TARGET) then return true end
local abilityName = Ability.GetName(orders.ability)
if not ( abilityName == "enigma_black_hole" or abilityName == "magnataur_reverse_polarity" or abilityName == "faceless_void_chronosphere") then return true end
local myHero = Heroes.GetLocal()
failSwitch.castPosition = Input.GetWorldCursorPos()
if abilityName == "magnataur_reverse_polarity" then
failSwitch.castPosition = NPC.GetAbsOrigin(myHero)
end
failSwitch.castAbilityName = abilityName
if failSwitch.CountEnemyInRange(failSwitch.castPosition, failSwitch.ultiRadius[failSwitch.castAbilityName]) > 0 then return true end
return false
end
function failSwitch.CountEnemyInRange(position, range)
local entities = Heroes.GetAll()
local me = Heroes.GetLocal()
local inRangeCount = 0
for index, ent in pairs(entities) do
local enemyhero = Heroes.Get(index)
local enemyspeed = NPC.GetMoveSpeed(enemyhero)
-- Account for the distance enemy can walk in 50ms(enemyspeed/20)
if not Entity.IsSameTeam(me, enemyhero) and not NPC.IsIllusion(enemyhero) and NPC.IsPositionInRange(enemyhero, position, range - enemyspeed/20, 0) then
inRangeCount = inRangeCount + 1
end
end
return inRangeCount
end
function failSwitch.OnUnitAnimation(animation)
if not Menu.IsEnabled(failSwitch.optionEnable) then
failSwitch.ClearVars()
return
end
if Menu.IsKeyDown(failSwitch.optionKey) then
failSwitch.ClearVars()
return
end
if animation.unit==Heroes.GetLocal() and animation.activity==Enum.GameActivity.ACT_DOTA_CAST_ABILITY_4 then
if failSwitch.CountEnemyInRange(failSwitch.castPosition, failSwitch.ultiRadius[failSwitch.castAbilityName]) == 0 then
failSwitch.CancelAnimation()
else
-- Check if enemies in range 50ms before animation ends
failSwitch.animationEndTime = os.clock() + failSwitch.castPoint[failSwitch.castAbilityName] - 0.05
end
end
end
function failSwitch.CancelAnimation()
Log.Write("CancelAnimation")
local myHero = Heroes.GetLocal()
local myPlayer = Players.GetLocal()
Player.PrepareUnitOrders(myPlayer, Enum.UnitOrder.DOTA_UNIT_ORDER_STOP, nil, Entity.GetAbsOrigin(myHero), nil, Enum.PlayerOrderIssuer.DOTA_ORDER_ISSUER_PASSED_UNIT_ONLY, myHero, false, true)
failSwitch.ClearVars()
end
function failSwitch.CheckOnAnimationEnd()
local currentTime = os.clock()
if failSwitch.animationEndTime > 0 and currentTime > failSwitch.animationEndTime then
if failSwitch.CountEnemyInRange(failSwitch.castPosition, failSwitch.ultiRadius[failSwitch.castAbilityName]) == 0 then
failSwitch.CancelAnimation()
end
failSwitch.ClearVars()
end
end
function failSwitch.ClearVars()
failSwitch.castPosition = Vector(0,0,0)
failSwitch.castAbilityName = ""
failSwitch.animationEndTime = 0
end
return failSwitch