-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreeSlot.lua
More file actions
48 lines (42 loc) · 1.69 KB
/
FreeSlot.lua
File metadata and controls
48 lines (42 loc) · 1.69 KB
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
local function GetLowest()
local items = {}
local lowest = nil
for bagID = 0, 4 do
if GetContainerNumSlots(bagID) > 0 then
for slot = 0, GetContainerNumSlots(bagID) do
local _, itemCount, _, quality, _, _, itemLink = GetContainerItemInfo(bagID, slot)
if (itemLink == nil or quality > 0) then
else
table.insert(items, {(select(11, GetItemInfo(itemLink)))*itemCount, itemLink, itemCount, bagID, slot})
end
end
end
end
for _,v in pairs(items) do
if (lowest == nil or v[1] < lowest[1]) then lowest = v end
end
return lowest
end
local function GetFreeSlots()
local freeSlots = 0
for bagID = 0, 4 do
freeSlots = freeSlots + GetContainerNumFreeSlots(bagID)
end
return freeSlots
end
local function Evaluate()
if GetFreeSlots() <= 1 then
local totalValue, itemLink, itemCount, bagID, slot = unpack(GetLowest())
DEFAULT_CHAT_FRAME:AddMessage("Discarding "..itemLink.." x "..itemCount.." (Value: "..totalValue.."c) due to insufficent bag space.")
PickupContainerItem(bagID, slot)
DeleteCursorItem()
end
end
local loot = CreateFrame("Frame")
loot:RegisterEvent("LOOT_READY")
loot:SetScript("OnEvent", Evaluate)
-- TODO: Figure out why discard message displays multiple times
-- TODO: Skip discard if item to pick up is worth less than current lowest value item in bags
-- TODO: Blacklist of non-greys that we want to allow discarding of anyway
-- TODO: Figure out inconsistency in one/zero slot being available
-- TODO: Handling for cases where we have no greys to toss