Thread Tools Display Modes
10-01-09, 02:44 PM   #1
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Dequip all problem

Hey, I have a - most likely - simple problem with my AddOn, Dequip. This is the code:

Code:
--Setting up variables
local cb = DEFAULT_CHAT_FRAME

--The actual function
function Dequip(msg)
if GetInventoryItemLink("player",msg) then
    for i=0,4 do
        for j=1,GetContainerNumSlots(i) do
            if not GetContainerItemLink(i,j) then
                PickupInventoryItem(msg) PickupContainerItem(i,j)
                return
            end 
         end
    end
end
end

--The function for dequipping all items
function Dequipall()
    for m=0,19 do
        Dequip(m)
    end
end

--Slash command handling
SLASH_DEQUIP1 = "/dq"
SLASH_DEQUIP2 = "/dequip"
SlashCmdList["DEQUIP"] = function(msg)
if (not msg or msg == "" or msg == "help") then
	cb:AddMessage('/dequip xxx | /dq xxx - Dequips slot where xxx can be the following slot or "all":')
    cb:AddMessage("Ammo = 0")
    cb:AddMessage("Head = 1")
    cb:AddMessage("Neck = 2")
    cb:AddMessage("Shoulder = 3")
    cb:AddMessage("Shirt = 4")
    cb:AddMessage("Chest = 5")
    cb:AddMessage("Waist = 6")
    cb:AddMessage("Legs = 7")
    cb:AddMessage("Feet = 8")
    cb:AddMessage("Wrist = 9")
    cb:AddMessage("Hands = 10")
    cb:AddMessage("First finger = 11")
    cb:AddMessage("Second finger = 12")
    cb:AddMessage("First trinket = 13")
    cb:AddMessage("Second trinket = 14")
    cb:AddMessage("Cloak = 15")
    cb:AddMessage("Mainhand = 16")
    cb:AddMessage("Offhand = 17")
    cb:AddMessage("Ranged = 18")
    cb:AddMessage("Tabard = 19")
elseif (msg=="all") then
    Dequipall()
else
    Dequip(msg)
end
end
Now, when I try Dequipall() it only dequips one thing instead of all, what should I do?
  Reply With Quote
10-01-09, 03:29 PM   #2
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
I'm sure it's because of the lag until an item slot in your bags changes.
You might want to blacklist slots already used OR save the last position you where at and continue from the slot after.

E.g.

Code:
local black = {}
 --The actual function
function Dequip(msg)
    if GetInventoryItemLink("player",msg) then
        for i=0,4 do
            for j=1,GetContainerNumSlots(i) do
                if not GetContainerItemLink(i,j) and not black[i.."-"..j] then
                    PickupInventoryItem(msg)
                    PickupContainerItem(i,j)
                    black[i.."-"..j] = true
                    return
                end 
             end
        end
    end
end
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning.
This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so.
This is your permission slip.

If you need to contact me, do so on Twitter @v6ooo

Best regards, v6.

Last edited by v6o : 10-01-09 at 03:43 PM.
  Reply With Quote
10-02-09, 12:39 AM   #3
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
EDIT: Your one works, the only thing that had to be changed was:

Code:
local black = {}

--The actual function
function Dequip(msg)
if GetInventoryItemLink("player",msg) then
    for i=0,4 do
        for j=1,GetContainerNumSlots(i) do
            if not GetContainerItemLink(i,j) and not black[i.."-"..j]  then
                PickupInventoryItem(msg) PickupContainerItem(i,j)
                black[i.."-"..j] = true
                return
            end 
         end
    end
end
end

function Dequipall()
    for m=0,19 do
        Dequip(m)
    end
    black = {}
end
Because else if the user requips the items by hand, it will run out of slots eventually while there are empty slots.

Last edited by nightcracker : 10-02-09 at 12:57 AM.
  Reply With Quote
10-02-09, 01:46 AM   #4
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
Ah well it was just an fast example late at night with non-ironed out bugs so to say.
The only time you need to blacklist or remember which slots are being used is when you're unequipping more than one item at a time before the bags have time to update.
You might even want to save the time since last unequip to see if you need to use it. ~1sec should be enough for bags to update.
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning.
This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so.
This is your permission slip.

If you need to contact me, do so on Twitter @v6ooo

Best regards, v6.

Last edited by v6o : 10-02-09 at 02:01 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Dequip all problem


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off