Thread Tools Display Modes
01-24-23, 06:42 AM   #1
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
Problem with UseInventoryItem()

I'll resume this topic for a moment: https://www.wowinterface.com/forums/showthread.php?t=59470
Since UseInventoryItem() seems to work only on inventory slot right click, I created this script that alarms when you try to disenchant an item you don't want straight from your inventory.
This script works with the original interface of the game: but if someone used an addon, would it still work?
Of course, better solutions are welcome

Lua Code:
  1. local mt = {
  2.     __index = {
  3.         isvalue = function(t, value)
  4.             local is = false
  5.             for k, entry in ipairs(t) do
  6.                 if (entry == value) then
  7.                     is = true
  8.                     break
  9.                 end
  10.             end
  11.             return is
  12.         end
  13.     }
  14. };
  15.  
  16.  
  17. local protected = { "item1", "item2", "item3", "etch." }; -- items I want to protect
  18. setmetatable(protected, mt);
  19.  
  20. local disenchanting;
  21. local antidisenchant = CreateFrame("Frame");
  22.  
  23. antidisenchant:RegisterEvent("UNIT_SPELLCAST_SENT");
  24.  
  25. antidisenchant:SetScript("OnEvent", function(self, event, ...)
  26.     if (event == "UNIT_SPELLCAST_SENT") then
  27.         local item, link = GameTooltip:GetItem()
  28.         if (arg2 == "Disenchant") and (protected:isvalue(item)) then
  29.             disenchanting = true
  30.         end
  31.     end
  32. end);
  33.  
  34. antidisenchant:SetScript("OnUpdate", function()
  35.     if GetMouseFocus() then
  36.         TargetItemID = GetInventoryItemID("player",GetMouseFocus():GetID())
  37.         if (TargetItemID) and (string.find(GetMouseFocus():GetName(),"Slot")) then
  38.             local name, link = GetItemInfo(TargetItemID)
  39.             if (disenchanting) and (protected:isvalue(name)) then
  40.                 DEFAULT_CHAT_FRAME:AddMessage("WARNING! YOU'RE DISENCHANTING "..link,1,0,0)
  41.             end
  42.         end
  43.     end
  44. end)

Last edited by Benalish : 01-24-23 at 05:46 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problem with UseInventoryItem()

Thread Tools
Display Modes

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