View Single Post
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: 237
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