-
Notifications
You must be signed in to change notification settings - Fork 0
/
splitter.lua
70 lines (58 loc) · 1.92 KB
/
splitter.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
local ids = LibStub("tekIDmemo")
local function Print(...) ChatFrame1:AddMessage(string.join(" ", "|cFF33FF99tekauc splitter|r:", ...)) end
local function findempty()
for bag=0,4 do
for slot=1,GetContainerNumSlots(bag) do
if not GetContainerItemLink(bag, slot) then return bag, slot end
end
end
end
local f = CreateFrame("Frame")
local idqueue, sizequeue = {}, {}
local pendingbag, pendingslot, lastbag, lastslot
local function teksplit()
local id, size = idqueue[1], sizequeue[1]
for bag=0,4 do
for slot=1,GetContainerNumSlots(bag) do
local link = GetContainerItemLink(bag, slot)
if link and ids[link] == id then
local _, qty = GetContainerItemInfo(bag, slot)
if qty > size then
local ebag, eslot = findempty()
if not (ebag and eslot) then
pendingbag, pendingslot, lastbag, lastslot = nil
idqueue, sizequeue = {}, {}
f:UnregisterEvent("BAG_UPDATE")
return
end
if lastbag ~= ebag or lastslot ~= eslot then
lastbag, lastslot = ebag, eslot
pendingbag, pendingslot = bag, slot, id, size
f:RegisterEvent("BAG_UPDATE")
SplitContainerItem(bag, slot, size)
PickupContainerItem(ebag, eslot)
end
return
end
end
end
end
table.remove(idqueue, 1)
table.remove(sizequeue, 1)
if #idqueue == 0 then
pendingbag, pendingslot, lastbag, lastslot = nil
f:UnregisterEvent("BAG_UPDATE")
else return teksplit() end
end
f:SetScript("OnEvent", function(self, event, bag)
if not pendingbag or pendingbag ~= bag or select(3, GetContainerItemInfo(pendingbag, pendingslot)) then return end
teksplit()
end)
SLASH_TEKSPLITTER1 = "/split"
SlashCmdList.TEKSPLITTER = function(input)
local id, size = string.match(input, "item:(%d+):.*%|h%|r%s*([%d]+)%s*$")
if not id or not size then return Print("Usage: /split [Item Link] size") end
table.insert(idqueue, tonumber(id))
table.insert(sizequeue, tonumber(size))
if #idqueue == 1 then teksplit() end
end