-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoCarrot.lua
executable file
·395 lines (385 loc) · 17.1 KB
/
AutoCarrot.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
if not AutoCarrotDB then
AutoCarrotDB = { enabled = true, ridingGloves = true, mithrilSpurs = true, swimBelt = true, swimHelm = true, button = false, buttonScale = 1.0, trinketSlot1 = false, instance = false }
end
local CROP_OR_CARROT_ID = nil
local hasEnteredWorld = false
local f = CreateFrame("Frame")
f:RegisterEvent('PLAYER_ENTERING_WORLD')
f:RegisterEvent('PLAYER_LEAVING_WORLD')
f:RegisterEvent('BAG_UPDATE')
f:RegisterEvent('ADDON_LOADED')
f:RegisterEvent('PLAYER_EQUIPMENT_CHANGED')
f:SetScript("OnUpdate", function()
if(not hasEnteredWorld or not UnitExists("player") or not UnitIsConnected("player") or not AutoCarrotDB.enabled or InCombatLockdown() or UnitIsDeadOrGhost("player")) then return end
if(UnitLevel("player") <= 70) then
if(IsMounted() and not UnitOnTaxi("player")) then
local itemId = GetInventoryItemID("player", AutoCarrotDB.trinketSlot1 and 13 or 14) -- trinket slot 1/2
if(itemId) then
if(itemId ~= 25653 and itemId ~= 11122 and itemId ~= 32863) then
AutoCarrotDB.trinketId = itemId
if(CROP_OR_CARROT_ID and not StaticPopup1:IsShown()) then
EquipItemByName(CROP_OR_CARROT_ID, AutoCarrotDB.trinketSlot1 and 13 or 14)
end
end
else
AutoCarrotDB.trinketId = nil
if(CROP_OR_CARROT_ID and not StaticPopup1:IsShown()) then
EquipItemByName(CROP_OR_CARROT_ID, AutoCarrotDB.trinketSlot1 and 13 or 14)
end
end
if(AutoCarrotDB.ridingGloves and AutoCarrotDB.enchantHandsLink) then
itemLink = GetInventoryItemLink("player", 10) -- hands
if(itemLink) then
local itemId, enchantId = itemLink:match("item:(%d+):(%d*)")
if(enchantId ~= "930") then
AutoCarrotDB.handsLink = "item:"..itemId..":"..enchantId..":"
if(not StaticPopup1:IsShown()) then
EquipItemByName(AutoCarrotDB.enchantHandsLink, 10)
end
end
else
AutoCarrotDB.handsLink = nil
if(not StaticPopup1:IsShown()) then
EquipItemByName(AutoCarrotDB.enchantHandsLink, 10)
end
end
end
if(AutoCarrotDB.mithrilSpurs and AutoCarrotDB.enchantBootsLink) then
itemLink = GetInventoryItemLink("player", 8) -- feet
if(itemLink) then
local itemId, enchantId = itemLink:match("item:(%d+):(%d*)")
if(enchantId ~= "464") then
AutoCarrotDB.bootsLink = "item:"..itemId..":"..enchantId..":"
if(not StaticPopup1:IsShown()) then
EquipItemByName(AutoCarrotDB.enchantBootsLink, 8)
end
end
else
AutoCarrotDB.bootsLink = nil
if(not StaticPopup1:IsShown()) then
EquipItemByName(AutoCarrotDB.enchantBootsLink, 8)
end
end
end
else
local itemId = GetInventoryItemID("player", AutoCarrotDB.trinketSlot1 and 13 or 14) -- trinket slot 1/2
if(itemId) then
if(itemId ~= 25653 and itemId ~= 11122 and itemId ~= 32863) then
AutoCarrotDB.trinketId = itemId
elseif(AutoCarrotDB.trinketId and AutoCarrotDB.trinketId ~= GetInventoryItemID("player", AutoCarrotDB.trinketSlot1 and 14 or 13)) then
EquipItemByName(AutoCarrotDB.trinketId, AutoCarrotDB.trinketSlot1 and 13 or 14)
end
else
AutoCarrotDB.trinketId = nil
end
if(AutoCarrotDB.ridingGloves and AutoCarrotDB.enchantHandsLink) then
itemLink = GetInventoryItemLink("player", 10) -- hands
if(itemLink) then
local itemId, enchantId = itemLink:match("item:(%d+):(%d*)")
if(enchantId ~= "930") then
AutoCarrotDB.handsLink = "item:"..itemId..":"..enchantId..":"
elseif(AutoCarrotDB.handsLink) then
EquipItemByName(AutoCarrotDB.handsLink, 10)
end
else
AutoCarrotDB.handsLink = nil
end
end
if(AutoCarrotDB.mithrilSpurs and AutoCarrotDB.enchantBootsLink) then
itemLink = GetInventoryItemLink("player", 8) -- feet
if(itemLink) then
local itemId, enchantId = itemLink:match("item:(%d+):(%d*)")
if(enchantId ~= "464") then
AutoCarrotDB.bootsLink = "item:"..itemId..":"..enchantId..":"
elseif(AutoCarrotDB.bootsLink) then
EquipItemByName(AutoCarrotDB.bootsLink, 8)
end
else
AutoCarrotDB.bootsLink = nil
end
end
end
end
if(IsSwimming() and AutoCarrotDB.swimBelt) then
local itemId = GetInventoryItemID("player", 6) -- waist
if(itemId) then
if(itemId ~= 7052) then
AutoCarrotDB.beltId = itemId
if(not StaticPopup1:IsShown()) then
EquipItemByName(7052, 6)
end
end
else
AutoCarrotDB.beltId = nil
if(not StaticPopup1:IsShown()) then
EquipItemByName(7052, 6)
end
end
else
local itemId = GetInventoryItemID("player", 6) -- waist
if(itemId) then
if(itemId ~= 7052) then
AutoCarrotDB.beltId = itemId
elseif(AutoCarrotDB.beltId) then
EquipItemByName(AutoCarrotDB.beltId, 6)
end
else
AutoCarrotDB.beltId = nil
end
end
if(IsSubmerged() and AutoCarrotDB.swimHelm) then
local itemId = GetInventoryItemID("player", 1) -- head
if(itemId) then
if(itemId ~= 10506) then
AutoCarrotDB.headId = itemId
if(not StaticPopup1:IsShown()) then
EquipItemByName(10506, 1)
end
end
else
AutoCarrotDB.headId = nil
if(not StaticPopup1:IsShown()) then
EquipItemByName(10506, 1)
end
end
else
local itemId = GetInventoryItemID("player", 1) -- head
if(itemId) then
if(itemId ~= 10506) then
AutoCarrotDB.headId = itemId
elseif(AutoCarrotDB.headId) then
EquipItemByName(AutoCarrotDB.headId, 1)
end
else
AutoCarrotDB.headId = nil
end
end
end)
f:SetScript('OnEvent', function(self, event, ...)
if(event == 'ADDON_LOADED') then
local addon = ...
if(addon == 'AutoCarrot') then
AutoCarrot_OnLoad()
end
elseif(event == 'PLAYER_LEAVING_WORLD') then
hasEnteredWorld = false
else -- PLAYER_ENTERING_WORLD / BAG_UPDATE / PLAYER_EQUIPMENT_CHANGED
if(event == 'PLAYER_ENTERING_WORLD' and AutoCarrotDB.instance) then
if (IsInInstance()) then
if (AutoCarrotDB.enabled) then
AutoCarrotButton:Click()
AutoCarrotDB.wasAutoDisabled = true
end
else
if (not AutoCarrotDB.enabled and AutoCarrotDB.wasAutoDisabled) then
AutoCarrotButton:Click()
end
end
end
hasEnteredWorld = true
CROP_OR_CARROT_ID = nil
local itemId = GetInventoryItemID("player", 13)
if(itemId == 25653 or itemId == 32863) then
CROP_OR_CARROT_ID = itemId
AutoCarrotDB.trinketSlot1 = true
AutoCarrotDB.enchantHandsLink = nil
AutoCarrotDB.enchantBootsLink = nil
return
elseif(itemId == 11122) then
CROP_OR_CARROT_ID = 11122
AutoCarrotDB.trinketSlot1 = true
end
itemId = GetInventoryItemID("player", 14)
if(itemId == 25653 or itemId == 32863) then
CROP_OR_CARROT_ID = itemId
AutoCarrotDB.trinketSlot1 = false
AutoCarrotDB.enchantHandsLink = nil
AutoCarrotDB.enchantBootsLink = nil
AutoCarrotDB.handsLink = nil
AutoCarrotDB.bootsLink = nil
return
elseif(itemId == 11122) then
CROP_OR_CARROT_ID = 11122
AutoCarrotDB.trinketSlot1 = false
end
for bag = 0, NUM_BAG_SLOTS do
for slot = 0, C_Container.GetContainerNumSlots(bag) do
local link = C_Container.GetContainerItemLink(bag, slot)
if(link) then
local sItemId, enchantId = link:match("item:(%d+):(%d*)")
if(sItemId == "25653" or sItemId == "32863") then
CROP_OR_CARROT_ID = tonumber(sItemId)
AutoCarrotDB.enchantHandsLink = nil
AutoCarrotDB.enchantBootsLink = nil
AutoCarrotDB.handsLink = nil
AutoCarrotDB.bootsLink = nil
return
elseif(sItemId == "11122") then
CROP_OR_CARROT_ID = 11122
elseif(enchantId == "930") then -- riding gloves
AutoCarrotDB.enchantHandsLink = "item:"..sItemId..":930:"
elseif(enchantId == "464") then -- mithril spurs
AutoCarrotDB.enchantBootsLink = "item:"..sItemId..":464:"
end
end
end
end
end
end)
function AutoCarrot_EquipNormalSet()
if(InCombatLockdown() or UnitIsDeadOrGhost("player")) then return end
if(AutoCarrotDB.trinketId) then
EquipItemByName(AutoCarrotDB.trinketId, AutoCarrotDB.trinketSlot1 and 13 or 14)
end
if(AutoCarrotDB.handsLink) then
EquipItemByName(AutoCarrotDB.handsLink, 10)
end
if(AutoCarrotDB.bootsLink) then
EquipItemByName(AutoCarrotDB.bootsLink, 8)
end
if(AutoCarrotDB.beltId) then
EquipItemByName(AutoCarrotDB.beltId, 6)
end
if(AutoCarrotDB.headId) then
EquipItemByName(AutoCarrotDB.headId, 1)
end
end
-- Print handler
function AutoCarrot_Print(msg)
print("|cff00ff00Auto|cffed9121Carrot|r: "..(msg or ""))
end
function AutoCarrot_OnLoad()
if AutoCarrotDB.enabled then
AutoCarrotButton.overlay:SetColorTexture(0, 1, 0, 0.3)
else
AutoCarrotButton.overlay:SetColorTexture(1, 0, 0, 0.5)
end
if AutoCarrotDB.button then
AutoCarrotButton:Show()
else
AutoCarrotButton:Hide()
end
AutoCarrotButton:SetScale(AutoCarrotDB.buttonScale or 1)
end
-- Slash handler
local function OnSlash(key, value, ...)
if key and key ~= "" then
if key == "enabled" then
if value == "toggle" or tonumber(value) then
if value == "toggle" then
AutoCarrotButton:Click()
elseif AutoCarrotDB.enabled ~= (tonumber(value) == 1 and true or false) then
AutoCarrotButton:Click()
end
AutoCarrot_Print("'enabled' set: "..( AutoCarrotDB.enabled and "1" or "0" ))
else
AutoCarrot_Print("'enabled' = "..( AutoCarrotDB.enabled and "1" or "0" ))
end
elseif key == "ridinggloves" then
if tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.ridingGloves = enable
AutoCarrot_Print("'ridingGloves' set: "..( enable and "1" or "0" ))
else
AutoCarrot_Print("'ridingGloves' = "..( AutoCarrotDB.ridingGloves and "1" or "0" ))
end
elseif key == "mithrilspurs" then
if tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.mithrilSpurs = enable
AutoCarrot_Print("'mithrilSpurs' set: "..( enable and "1" or "0" ))
else
AutoCarrot_Print("'mithrilSpurs' = "..( AutoCarrotDB.mithrilSpurs and "1" or "0" ))
end
elseif key == "swimbelt" then
if tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.swimBelt = enable
AutoCarrot_Print("'swimBelt' set: "..( enable and "1" or "0" ))
else
AutoCarrot_Print("'swimBelt' = "..( AutoCarrotDB.swimBelt and "1" or "0" ))
end
elseif key == "swimhelm" then
if tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.swimHelm = enable
AutoCarrot_Print("'swimHelm' set: "..( enable and "1" or "0" ))
else
AutoCarrot_Print("'swimHelm' = "..( AutoCarrotDB.swimHelm and "1" or "0" ))
end
elseif key == "instance" then
if tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.instance = enable
AutoCarrot_Print("'instance' set: "..( enable and "1" or "0" ))
else
AutoCarrot_Print("'instance' = "..( AutoCarrotDB.instance and "1" or "0" ))
end
elseif key == "button" then
if tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.button = enable
AutoCarrot_Print("'button' set: "..( enable and "1" or "0" ))
AutoCarrot_OnLoad()
elseif value == "reset" then
AutoCarrotButton:ClearAllPoints()
AutoCarrotButton:SetPoint("CENTER")
AutoCarrotDB.buttonScale = 1
AutoCarrot_OnLoad()
AutoCarrot_Print("Button position/scale reset.")
elseif value == "scale" then
local arg2 = ...
if tonumber(arg2) then
AutoCarrotDB.buttonScale = arg2
AutoCarrot_Print("'buttonScale' set: "..AutoCarrotDB.buttonScale)
AutoCarrot_OnLoad()
else
AutoCarrot_Print("'buttonScale' = "..AutoCarrotDB.buttonScale or "1.0")
AutoCarrot_Print("Usage: /autocarrot button scale 1.0")
end
else
AutoCarrot_Print("'button' = "..( AutoCarrotDB.button and "1" or "0" ))
end
end
else
AutoCarrot_Print("Slash commands")
AutoCarrot_Print(" - enabled 0/1/toggle ("..(AutoCarrotDB.enabled and "1" or "0")..")")
AutoCarrot_Print(" - ridingGloves 0/1 ("..(AutoCarrotDB.ridingGloves and "1" or "0")..")")
AutoCarrot_Print(" - mithrilSpurs 0/1 ("..(AutoCarrotDB.mithrilSpurs and "1" or "0")..")")
AutoCarrot_Print(" - swimBelt 0/1 ("..(AutoCarrotDB.swimBelt and "1" or "0")..")")
AutoCarrot_Print(" - swimHelm 0/1 ("..(AutoCarrotDB.swimHelm and "1" or "0")..")")
AutoCarrot_Print(" - instance 0/1 ("..(AutoCarrotDB.instance and "1" or "0")..")")
AutoCarrot_Print(" - button 0/1/reset/scale ("..(AutoCarrotDB.button and "1" or "0")..")")
end
end
SLASH_AUTOCARROT1 = "/autocarrot";
SLASH_AUTOCARROT2 = "/ac";
SlashCmdList["AUTOCARROT"] = function(msg)
msg = string.lower(msg)
msg = { string.split(" ", msg) }
if #msg >= 1 then
local exec = table.remove(msg, 1)
OnSlash(exec, unpack(msg))
end
end
AutoCarrotButton = CreateFrame("Button", "AutoCarrotButton", UIParent, "ActionButtonTemplate")
AutoCarrotButton.icon:SetTexture(134010)
AutoCarrotButton:SetPoint("CENTER")
AutoCarrotButton.overlay = AutoCarrotButton:CreateTexture(nil, "OVERLAY")
AutoCarrotButton.overlay:SetAllPoints(AutoCarrotButton)
AutoCarrotButton:RegisterForDrag("LeftButton")
AutoCarrotButton:SetMovable(true)
AutoCarrotButton:SetUserPlaced(true)
AutoCarrotButton:SetScript("OnDragStart", function() if IsAltKeyDown() then AutoCarrotButton:StartMoving() end end)
AutoCarrotButton:SetScript("OnDragStop", AutoCarrotButton.StopMovingOrSizing)
AutoCarrotButton:SetScript("OnClick", function()
if AutoCarrotDB.enabled then
AutoCarrotButton.overlay:SetColorTexture(1, 0, 0, 0.5)
AutoCarrotDB.enabled = false
AutoCarrot_EquipNormalSet()
else
AutoCarrotButton.overlay:SetColorTexture(0, 1, 0, 0.3)
AutoCarrotDB.enabled = true
end
AutoCarrotDB.wasAutoDisabled = false
end)