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:
local mt = {
__index = {
isvalue = function(t, value)
local is = false
for k, entry in ipairs(t) do
if (entry == value) then
is = true
break
end
end
return is
end
}
};
local protected = { "item1", "item2", "item3", "etch." }; -- items I want to protect
setmetatable(protected, mt);
local disenchanting;
local antidisenchant = CreateFrame("Frame");
antidisenchant:RegisterEvent("UNIT_SPELLCAST_SENT");
antidisenchant:SetScript("OnEvent", function(self, event, ...)
if (event == "UNIT_SPELLCAST_SENT") then
local item, link = GameTooltip:GetItem()
if (arg2 == "Disenchant") and (protected:isvalue(item)) then
disenchanting = true
end
end
end);
antidisenchant:SetScript("OnUpdate", function()
if GetMouseFocus() then
TargetItemID = GetInventoryItemID("player",GetMouseFocus():GetID())
if (TargetItemID) and (string.find(GetMouseFocus():GetName(),"Slot")) then
local name, link = GetItemInfo(TargetItemID)
if (disenchanting) and (protected:isvalue(name)) then
DEFAULT_CHAT_FRAME:AddMessage("WARNING! YOU'RE DISENCHANTING "..link,1,0,0)
end
end
end
end)