I’m trying to make an addon that manages soul shards, but I’m having problems with using DeleteCursorItem()
because its not registering my slash command as a hardware event. How do I properly manage this?
SOUL_SHARDS_TO_KEEP = 5
SOUL_SHARD_ITEMID = 6265
function GetCurrentSoulShards()
count = 0
for bagIndex = 0, 4 do
bagSlots = C_Container.GetContainerNumSlots(bagIndex)
for bagSlot = 0, bagSlots do
if C_Container.GetContainerItemID(bagIndex, bagSlot) == SOUL_SHARD_ITEMID then
count = count + 1
end
end
end
return count
end
function ManageSoulShards()
if CursorHasSoulShard() then
DeleteCursorItem()
end
currentSoulShards = GetCurrentSoulShards()
if currentSoulShards > SOUL_SHARDS_TO_KEEP then
PickupItem(SOUL_SHARD_ITEMID)
if CursorHasSoulShard() then
print("Deleting soulshard...")
DeleteCursorItem()
end
end
end
function CursorHasSoulShard()
cursorInfoType, itemId = GetCursorInfo()
if tonumber(itemId) == SOUL_SHARD_ITEMID then
return true
end
return false
end
SLASH_MANAGESOULSHARDS1 = "/mss"
SlashCmdList["MANAGESOULSHARDS"] = function()
ManageSoulShards()
end
EDIT:
This cannot be called directly from /script (RunScript) and loadstring, e.g. WowLua and WeakAuras.
* Limited to deleting a single item per hardware event.
As of 2022-09-17 Classic (Vanilla and Wrath) can delete multiple items per hardware event and has no NOSCRIPT protection.