1. #1

    Button Targeting Question

    Hello,

    I am trying to create a button that functions for the functions of the Unit frames. I recreated unit frames in weakauras, but wanted some of the functionality to remain. I've been looking on the internet, and know the TargetUnit() function no longer is usable for self targeting. My issue is finding a workaround to that to help me targeting myself. I have the menu functions to work and everything works, but I just can't target myself. I've been working with the frame:SetAttribute functions to try and set a macro text to target the player, but can't quite get it figured out. Here is the code I have so far.

    Code:
    local PlayerMenu = CreateFrame("Button", "PlayerMenu", UIParent, "SecureActionButtonTemplate")
    PlayerMenu:SetAlpha(0)
    PlayerMenu:SetWidth(82)
    PlayerMenu:SetHeight(25)
    PlayerMenu:SetPoint("CENTER",nil, "CENTER", -357, -74)
    PlayerMenu:SetNormalTexture("Interface\\CHATFRAME\\CHATFRAMEBACKGROUND")
    PlayerMenu:RegisterForClicks("LeftButtonUp", "RightButtonUp") 
    
    PlayerMenu:SetScript("OnClick", function(self, button) 
    if button == "LeftButton" then 
    PlayerMenu:SetAttribute("unit", "player")
    PlayerMenu:SetAttribute("type", "target")
    elseif button == "RightButton" then 
    ToggleDropDownMenu(1, nil, PlayerFrameDropDown, "PlayerMenu", 0, -15)  
    end
     end)
    Thanks in advance!

  2. #2
    SecureActionButtons have their own OnClick handler. Don't overwrite it. What you'd want to do instead is this (after creating the button, not every time it's clicked):
    Code:
    PlayerMenu:SetAttribute("unit", "player")
    PlayerMenu:SetAttribute("type1", "target")
    PlayerMenu:SetAttribute("type2", "menu")
    Really, though, why not just use SecureUnitButtonTemplate? It already does this work for you.

  3. #3
    Yeah, you want to use SecureUnitButtonTemplate because it has an extra bit of code for when you have the glowing hand cursor and try to open a menu. You also want to use type "togglemenu" and not "menu" since the secure handler for "menu" was removed awhile ago. No need to set the alpha to zero either, just don't set the texture and you get the same effect. You also probably want to parent this to whatever it is covering and just to a SetAllPoints on it instead of the manual placement too (no need to set a texture to see where it is to line up).
    Code:
    local PlayerMenu = CreateFrame("Button", "PlayerMenu", UIParent, "SecureUnitButtonTemplate")
    PlayerMenu:SetSize(82, 25)
    PlayerMenu:SetPoint("CENTER", -357, -74)
    --PlayerMenu:SetNormalTexture("Interface\\CHATFRAME\\CHATFRAMEBACKGROUND")
    PlayerMenu:RegisterForClicks("LeftButtonUp", "RightButtonUp") 
    
    PlayerMenu:SetAttribute("type1", "target")
    PlayerMenu:SetAttribute("unit", "player")
    PlayerMenu:SetAttribute("type2", "togglemenu")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •