Thread Tools Display Modes
07-06-23, 08:20 PM   #1
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Unequip, make set, and then use set.

I want to unequip all items, create a naked equipment set, then register the PLAYER_EQUIPMENT_CHANGED event, and then use the naked set to be applied when I try to equip any items.

Here is the unequip function.
Lua Code:
  1. local InventorySlots = {
  2.     INVSLOT_AMMO,
  3.     INVSLOT_HEAD,
  4.     INVSLOT_NECK,
  5.     INVSLOT_SHOULDER,
  6.     INVSLOT_BODY,
  7.     INVSLOT_CHEST,
  8.     INVSLOT_WAIST,
  9.     INVSLOT_LEGS,
  10.     INVSLOT_FEET,
  11.     INVSLOT_WRIST,
  12.     INVSLOT_HAND,
  13.     INVSLOT_FINGER1,
  14.     INVSLOT_FINGER2,
  15.     INVSLOT_TRINKET1,
  16.     INVSLOT_TRINKET2,
  17.     INVSLOT_BACK,
  18. --    INVSLOT_MAINHAND,
  19. --    INVSLOT_OFFHAND,
  20. --    INVSLOT_RANGED,
  21.     INVSLOT_TABARD
  22. }
  23.  
  24. local function UnequipAll()
  25.     if #InventorySlots <= 0 then
  26.         return
  27.     end
  28.     local slotindex = 1
  29.     ClearCursor()
  30.     for bag = NUM_TOTAL_EQUIPPED_BAG_SLOTS, 0, -1 do
  31.         local free, type = C_Container.GetContainerNumFreeSlots(bag)
  32.         free = (type == 0 and free or 0)
  33.         for _ = 1, free do
  34.             local invslot = InventorySlots[slotindex]
  35.             while not GetInventoryItemID("player", invslot) do
  36.                 if slotindex < #InventorySlots then
  37.                     slotindex = slotindex + 1
  38.                 else
  39.                     return
  40.                 end
  41.                 invslot = InventorySlots[slotindex]
  42.             end
  43.             PickupInventoryItem(invslot);
  44.             (bag == 0 and PutItemInBackpack or PutItemInBag)(C_Container.ContainerIDToInventoryID(bag))
  45.             if slotindex < #InventorySlots then
  46.                 slotindex = slotindex + 1
  47.             else
  48.                 return
  49.             end
  50.         end
  51.     end
  52. end
I then have a button the the player clicks to run the unequid function.
Lua Code:
  1. "OnClick",
  2.     function()
  3.         if not IronManCharacterVariables.isAttemptingIronMan then            
  4.             UnequipAll()
  5.             IronManCharacterVariables.isAttemptingIronMan = true
  6.         end
  7.     )
  8.     C_EquipmentSet.CreateEquipmentSet("IronMan", 1035053)("PLAYER_EQUIPMENT_CHANGED")
This is where I track the event.
Lua Code:
  1. elseif event == "PLAYER_EQUIPMENT_CHANGED" then
  2. if not IronManCharacterVariables.isAttemptingIronMan then
  3.     C_EquipmentSet.UseEquipmentSet(0)
  4. end

The issue I have is that it does unequip all but the event triggers even though it has not been registered until after the unequip function, and the naked set never saves.

I have uploaded my full code on Pastebin.

I have been banging away at this for a couple of weeks without success, so any help would be great.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
07-06-23, 11:21 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
PLAYER_EQUIPMENT_CHANGED fires when the server acknowledges that your equipment has changed. Due to the nature of server-client communication, there's always going to be some latency to it. It may be a good idea to check if your equipment set is already equipped or scan the inventory for equipped items instead of just blindly trying to select the set.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
07-08-23, 06:20 PM   #3
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi SDPhantom

Thanks for your post, the server lag while not significant was the culprit, I added a simple wait after the unequip all and that works for me.

Cheers
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
07-09-23, 12:33 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
The point was more along the lines of the UI being a single-threaded process. Because PLAYER_EQUIPMENT_CHANGED is a communication-based event instead of a UI-based one, it can't fire while you have code still running.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Unequip, make set, and then use set.


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