-
Notifications
You must be signed in to change notification settings - Fork 23
/
CourierController.lua
181 lines (156 loc) · 6.44 KB
/
CourierController.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
local CourierController = {}
CourierController.optionEnable = Menu.AddOption({"Utility", "Courier"}, "Enable", "Courier")
CourierController.MuteEnable = Menu.AddOption({"Utility", "Courier"}, "Use Mute Filter", "Mute")
CourierController.optionKey = Menu.AddKeyOption({"Utility", "Courier"}, "Key", Enum.ButtonCode.KEY_F)
CourierController.courierArray= {}
CourierController.tick = 0
CourierController.messageTick = 0
CourierController.playerHeroMap = {}
CourierController.heroesPlayerMap= {}
CourierController.mutedHeroes = {}
CourierController.mutedHeroesLength = 0
CourierController.forceTranfer = {}
CourierController.oldMutedHeroesLengh = 1000
CourierController.font = Renderer.LoadFont("Arial", 30, Enum.FontWeight.EXTRABOLD)
CourierController.players = {}
function CourierController.OnUpdate()
if not Menu.IsEnabled(CourierController.optionEnable) then return true end
CourierController.getPlayerHeroMap()
CourierController.findCourier()
if Menu.IsKeyDown(CourierController.optionKey) then
local pos = Input.GetWorldCursorPos()
for i = 1,#CourierController.courierArray do
CourierController.forceTranfer = {}
local courier = CourierController.courierArray[i]
NPC.MoveTo(courier, pos,false,false)
end
return
end
CourierController.controlCourier()
end
function CourierController.findCourier()
if GameRules.GetGameTime() < CourierController.tick then return end
local myHero = Heroes.GetLocal()
CourierController.courierArray = {}
for i= 1, NPCs.Count() do
local entity = NPCs.Get(i)
if entity and Entity.IsSameTeam(myHero, entity) and NPC.GetUnitName(entity) == "npc_dota_courier" and Entity.IsAlive(entity) then
table.insert(CourierController.courierArray, entity)
end
end
CourierController.getMutedHeroes()
CourierController.tick = GameRules.GetGameTime() + 1
end
function CourierController.controlCourier()
local myHero = Heroes.GetLocal()
for i = 1,#CourierController.courierArray do
local courier = CourierController.courierArray[i]
if courier then
local state = Courier.GetCourierState(courier)
local courierEnt = Courier.GetCourierStateEntity(courier)
local transfer = NPC.GetAbility(courier, "courier_take_stash_and_transfer_items")
local goBase = NPC.GetAbilityByIndex(courier, 0)
if state == Enum.CourierState.COURIER_STATE_DELIVERING_ITEMS and courierEnt == myHero then
CourierController.forceTranfer[courier] = true
end
if CourierController.forceTranfer[courier] == true then
if state ~= Enum.CourierState.COURIER_STATE_DELIVERING_ITEMS and courierEnt == myHero then
CourierController.forceTranfer[courier] = false
end
end
if CourierController.forceTranfer[courier] == true then
if NPC.IsEntityInRange(myHero, courier, 600) then
CourierController.forceTranfer[courier] = false
elseif Entity.IsAlive(myHero) then
if courierEnt and courierEnt ~= myHero then
Ability.CastNoTarget(transfer)
Log.Write("some one trying to use courier")
end
else
CourierController.forceTranfer[courier] = false
end
end
if courierEnt and Entity.IsHero(courierEnt) and CourierController.mutedHeroes[NPC.GetUnitName(courierEnt)] and not CourierController.forceTranfer[courier] then
Ability.CastNoTarget(goBase)
end
end
end
end
function CourierController.getPlayerHeroMap()
if CourierController.players[0] then return end
local myHero = Heroes.GetLocal()
if GameRules.GetServerGameState()~=5 then return end
for i = 0,10 do
if CourierController.players[i] then
Menu.RemoveOption(CourierController.players[i])
CourierController.players[i] = nil
end
end
for i= 1, Heroes.Count() do
local entity = Heroes.Get(i)
if entity and Entity.IsSameTeam(myHero, entity)then
local owner = Entity.GetOwner(entity)
CourierController.playerHeroMap[Player.GetPlayerID(owner)] = NPC.GetUnitName(entity)
CourierController.heroesPlayerMap[NPC.GetUnitName(entity)] = Player.GetPlayerID(owner)
if not CourierController.players[Player.GetPlayerID(owner)] then
--Log.Write(Player.GetPlayerID(owner)..":"..NPC.GetUnitName(entity))
CourierController.players[Player.GetPlayerID(owner)] = Menu.AddOption({"Utility", "Courier"}, string.upper(string.sub(NPC.GetUnitName(entity),15)), "Lock Courier Usage")
end
end
end
end
function CourierController.getMutedHeroes()
CourierController.mutedHeroes ={}
CourierController.mutedHeroesLength = 0
local myHero = Heroes.GetLocal()
for i= 1, NPCs.Count() do
local entity = NPCs.Get(i)
if entity and Entity.IsHero(entity) and Entity.IsSameTeam(myHero, entity) then
local owner = Entity.GetOwner(entity)
local ownerID = Hero.GetPlayerID(entity)
if (Menu.IsEnabled(CourierController.MuteEnable) and Player.IsMuted(owner)) or (CourierController.players[ownerID] and Menu.IsEnabled(CourierController.players[ownerID])) then
CourierController.mutedHeroes[NPC.GetUnitName(entity)] = true
CourierController.mutedHeroesLength = CourierController.mutedHeroesLength +1
end
end
end
if CourierController.oldMutedHeroesLengh ~= CourierController.mutedHeroesLength then
CourierController.messageTick = GameRules.GetGameTime() + 10
CourierController.oldMutedHeroesLengh = CourierController.mutedHeroesLength
end
end
function CourierController.OnGameStart()
CourierController.courierArray= {}
CourierController.tick = 0
CourierController.messageTick = 0
CourierController.playerHeroMap = {}
CourierController.heroesPlayerMap= {}
CourierController.mutedHeroes = {}
CourierController.oldMutedHeroesLengh = 1000
CourierController.players = {}
end
function CourierController.OnDraw()
if not Menu.IsEnabled(CourierController.optionEnable) then return end
if GameRules.GetGameMode() == -1 then
for i= 0, 10 do
if CourierController.players[i] then
Log.Write("removed")
Menu.RemoveOption(CourierController.players[i])
CourierController.players[i] = nil
end
end
end
if CourierController.messageTick < GameRules.GetGameTime() or not Engine.IsInGame() then return end
local message = ""
for key,value in pairs(CourierController.mutedHeroes) do
message= message..string.upper(string.sub(key,15))..", "
end
local w, h = Renderer.GetScreenSize()
Renderer.SetDrawColor(255, 0, 255)
if CourierController.mutedHeroesLength == 0 then
Renderer.DrawTextCentered(CourierController.font, w / 2, h / 2, "No players are muted", 1)
else
Renderer.DrawTextCentered(CourierController.font, w / 2, h / 2, message.." muted", 1)
end
end
return CourierController