Thread Tools Display Modes
Prev Previous Post   Next Post Next
12-15-23, 09:21 PM   #1
pflueger92
A Murloc Raider
Join Date: Oct 2022
Posts: 6
On Right Click get ItemId (Classsic SoD)

First time poster... I am in the very beginning stages of writing my first AddOn and its not going well. For this reason I am trying to just print messages for debugging and I am stuck with registering when right click happens, while left shift key is down, and the bank is open. Individually all 3 of these are satisfied through testing but my print message is not received let alone the rest of the function...

Ultimately I would like to retrieve the items information that was just right clicked. I know this is probably simple but I have searched all over and most of the help must be outdated or not compatible with Classic as any of the events I come across have zero documentation.

Code:
-- Create the frame
local frame = CreateFrame("Frame")

-- Set up event handling
frame:RegisterEvent("BANKFRAME_OPENED")
frame:RegisterEvent("BANKFRAME_CLOSED")

-- Function to handle events
frame:SetScript("OnEvent", function(self, event, ...)
    if event == "BANKFRAME_OPENED" then
        isBankOpen = true
        print("Bank frame opened!")
		print(isBankOpen)
    elseif event == "BANKFRAME_CLOSED" then
        isBankOpen = false
        print("Bank frame closed!")
		print(isBankOpen)
    end
end)

-- Set up script to handle item usage
frame:SetScript("OnMouseDown", function(self, button)
    if isBankOpen and IsLeftShiftKeyDown() and button == "RightButton" then
		print("Right Click Detected!")
        local bag, slot = self:GetRightClickedItem()
        if bag and slot then
            local itemId = GetContainerItemID(bag, slot)
            if itemId then
                print("Shift + Right-Click detected on item with ID:", itemId)
            end
        end
    else
        -- Default behavior to deposit the item into the bank
        print("Un-Modified Right-Click detected on an item!")
    end
end)

-- Function to get bag and slot of the right-clicked item
function frame:GetRightClickedItem()
    for bag = 0, NUM_BAG_SLOTS do
        for slot = 1, GetContainerNumSlots(bag) do
            local _, _, _, _, _, _, _, _, _, _, itemLink = GetContainerItemInfo(bag, slot)
            if itemLink then
                if IsModifiedClick("OPENALLBAGS") and GetCursorInfo() == nil then
                    return bag, slot
                end
            end
        end
    end
    return nil, nil
end
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » On Right Click get ItemId (Classsic SoD)


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