-
Notifications
You must be signed in to change notification settings - Fork 0
/
WhoHasIt.lua
262 lines (228 loc) · 8.44 KB
/
WhoHasIt.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
-- Main Frame
local checkGear = CreateFrame("Frame")
checkGear.width = 200
checkGear.height = 225
checkGear:SetFrameStrata("FULLSCREEN_DIALOG")
checkGear:SetSize(checkGear.width, checkGear.height)
checkGear:SetPoint("CENTER",0,0)
checkGear:SetMovable(true)
checkGear:SetResizable(true)
checkGear:EnableMouse(true)
checkGear:EnableMouseWheel(true)
checkGear:RegisterForDrag("LeftButton")
checkGear:SetScript("OnDragStart", checkGear.StartMoving)
checkGear:SetScript("OnDragStop", checkGear.StopMovingOrSizing)
checkGear:SetMinResize(155,125)
checkGear:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileSize = 32,
edgeSize = 32,
insets = { left = 8, right = 8, top = 8, bottom = 8 }
})
checkGear:SetBackdropColor(0, 0, 0, 1)
local resizeButton = CreateFrame("Button", nil, checkGear)
resizeButton:SetSize(16, 16)
resizeButton:SetPoint("BOTTOMRIGHT")
resizeButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
resizeButton:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
resizeButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
resizeButton:SetScript("OnMouseDown", function(self, button)
checkGear:StartSizing("BOTTOMRIGHT")
checkGear:SetUserPlaced(true)
end)
resizeButton:SetScript("OnMouseUp", function(self, button)
checkGear:StopMovingOrSizing()
end)
tinsert(UISpecialFrames, "AnimorHistoryFrame")
-- Stuff Frame
local messageFrame = CreateFrame("ScrollingMessageFrame", nil, checkGear)
messageFrame:SetPoint("LEFT", 20, 0)
messageFrame:SetSize(checkGear.width - 60, checkGear.height - 50)
messageFrame:SetFontObject(GameFontNormal)
messageFrame:SetTextColor(1, 1, 1, 1)
messageFrame:SetJustifyH("LEFT")
messageFrame:SetHyperlinksEnabled(true)
messageFrame:SetFading(false)
messageFrame:SetMaxLines(500)
checkGear.messageFrame = messageFrame
-- Players Frame
local playersFrame = CreateFrame("ScrollingMessageFrame", nil, checkGear)
playersFrame:SetPoint("LEFT", 20, 0)
playersFrame:SetSize(checkGear.width - 60, checkGear.height - 50)
playersFrame:SetFontObject(GameFontNormal)
playersFrame:SetTextColor(1, 1, 1, 1)
playersFrame:SetJustifyH("LEFT")
playersFrame:SetHyperlinksEnabled(true)
playersFrame:SetFading(false)
playersFrame:SetMaxLines(100)
checkGear.playersFrame = playersFrame
checkGear.playersFrame:Hide();
-- Scrollbar Frame
local scrollBar = CreateFrame("Slider", nil, checkGear, "UIPanelScrollBarTemplate")
scrollBar:SetPoint("RIGHT", checkGear, "RIGHT", -10, 10)
scrollBar:SetSize(30, checkGear.height - 90)
scrollBar:SetMinMaxValues(0, 9)
scrollBar:SetValueStep(1)
scrollBar.scrollStep = 1
checkGear.scrollBar = scrollBar
scrollBar:SetScript("OnValueChanged", function(self, value)
messageFrame:SetScrollOffset(select(2, scrollBar:GetMinMaxValues()) - value)
end)
scrollBar:SetValue(select(2, scrollBar:GetMinMaxValues()))
checkGear:SetScript("OnMouseWheel", function(self, delta)
local cur_val = scrollBar:GetValue()
local min_val, max_val = scrollBar:GetMinMaxValues()
if delta < 0 and cur_val < max_val then
cur_val = math.min(max_val, cur_val + 1)
scrollBar:SetValue(cur_val)
elseif delta > 0 and cur_val > min_val then
cur_val = math.max(min_val, cur_val - 1)
scrollBar:SetValue(cur_val)
end
end)
checkGear:SetScript("OnSizeChanged", function(_, w, h)
messageFrame:SetSize(w - 60, h - 50)
scrollBar:SetHeight(h - 90)
end)
-- Exit Button
local b = CreateFrame("Button", "MyButton", checkGear, "UIPanelButtonTemplate")
b:SetSize(25 ,22)
b:SetText("X")
b:SetPoint("BOTTOM")
b:SetScript("OnClick", function()
checkGear:Hide()
end)
local button_scan = CreateFrame("Button", "ButtonScan", checkGear, "UIPanelButtonTemplate")
button_scan:SetSize(45 ,22)
button_scan:SetText("Scan")
button_scan:SetPoint("BOTTOM", 37, 0)
button_scan:SetScript("OnClick", function()
checkGear:InspectNextUnit()
end)
local switched = true
local button_switch = CreateFrame("Button", "ButtonSwitch", checkGear, "UIPanelButtonTemplate")
button_switch:SetSize(55 ,22)
button_switch:SetText("Switch")
button_switch:SetPoint("BOTTOM", -42, 0)
button_switch:SetScript("OnClick", function()
if switched then
checkGear.messageFrame:Hide();
checkGear.playersFrame:Show();
switched = false;
else
checkGear.playersFrame:Hide();
checkGear.messageFrame:Show();
switched = true;
end
end)
checkGear:Show()
checkGear:RegisterEvent("LOOT_OPENED");
checkGear:RegisterEvent("AUTOFOLLOW_BEGIN");
checkGear:RegisterEvent("GROUP_ROSTER_UPDATE")
checkGear.known = {}
local found = false
checkGear:SetScript("OnEvent", function(self, event, ...)
if event=="INSPECT_READY" then
checkGear:InspectReady()
elseif event=="GROUP_ROSTER_UPDATE" then
checkGear:InspectNextUnit()
elseif event=="LOOT_OPENED" then
partySize = GetNumGroupMembers();
if partySize > 1 then
for i = 1, GetNumLootItems() do
if LootSlotHasItem(i) then
local itemName2, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount,
itemEquipLoc, itemIcon, itemSellPrice, itemClassID = GetItemInfo(GetLootSlotLink(i));
print(itemRarity)
print(itemClassID)
if (itemRarity > 1) and (itemClassID == 2 or itemClassID == 4) then
messageFrame:AddMessage("\n" .. itemName2)
for k, v in pairs(checkGear.known) do
for j = 1, 17 do
if v[j]==itemName2 then
found = true
break
end
end
if found then
messageFrame:AddMessage(k .. " : Yes")
else
messageFrame:AddMessage(k .. " : No")
end
found = false
end
checkGear:Show();
end
end
end
end
end
end)
local function dostuff(unit,name)
for i=1, 17 do
itemName = GetItemInfo(GetInventoryItemID(unit,i))
checkGear.known[name][i] = itemName
end
end
function checkGear:InspectNextUnit()
if IsInGroup() then
local inRaid = IsInRaid()
local oor = false
for i=1,GetNumGroupMembers() do
local unit = inRaid and "raid"..i or i==1 and "player" or "party"..(i-1)
local name = GetUnitName(unit,true)
if ((checkGear.known[name] == nil) or (not checkGear.known[name])) then
if CheckInteractDistance(unit,1) then
checkGear.unit = unit
checkGear.name = name
checkGear.known[name] = {}
NotifyInspect(unit)
checkGear:RegisterEvent("INSPECT_READY")
return
else
oor = true
end
end
end
if oor then
checkGear.timer = 3
checkGear:SetScript("OnUpdate",checkGear.WaitForOOR)
return
end
end
end
function checkGear:WaitForOOR(elapsed)
self.timer = self.timer - elapsed
if self.timer < 0 then
self.timer = 0
self:SetScript("OnUpdate",nil)
self:InspectNextUnit()
end
end
function checkGear:InspectReady()
checkGear:UnregisterEvent("INSPECT_READY")
checkGear:SetScript("OnUpdate",nil)
local unit = checkGear.unit
local missing
for i=1,17 do
if GetInventoryItemID(unit,i) and not GetInventoryItemLink(unit,i) then
missing = true
end
end
if missing then
checkGear:SetScript("OnUpdate",checkGear.InspectReady)
return
end
-- Show scanned players
playersFrame:AddMessage(checkGear.name)
dostuff(unit,checkGear.name)
checkGear:InspectNextUnit()
end
SLASH_WHOHASIT1 = "/whi";
local function WHOHASITfunc(msg)
checkGear:Show()
end
SlashCmdList["WHOHASIT"] = WHOHASITfunc;
print("Use /whi to open the frame")