Originally Posted by Dreamfade
1. If target is same faction then add "Add to Blacklist" (once clicked it would go to a lua function)
2. If target is oposite faction then add "Add to KOSlist" (this woud be linked to a different lua function)
|
Inserting menu entries into UnitPopup menus is kind of "hacky", a bit complicated and generally more trouble than its worth (there is a possibility of introducing taint, among other things) and I'd personally recommend against it. That being said, here's a very simplistic example, of what you are asking :
Code:
local myframe = CreateFrame("Frame")
myframe:RegisterEvent("UNIT_TARGET")
myframe:SetScript("OnEvent", function(_, event, ...)
myframe[event](myframe, ...)
end)
function myframe:UNIT_TARGET(unitid)
if unitid == "player" and UnitExists("target") then
if UnitFactionGroup("target") == UnitFactionGroup("player") and UnitIsPlayer("target") then
for i = 1, #UnitPopupMenus["PLAYER"] do
if UnitPopupMenus["PLAYER"][i] == "ADD_BLIST" or UnitPopupMenus["PLAYER"][i] == "ADD_KOS" then
tremove(UnitPopupMenus["PLAYER"], i)
end
end
tinsert(UnitPopupMenus["PLAYER"], #UnitPopupMenus["PLAYER"] - 1, "ADD_BLIST")
elseif UnitFactionGroup("target") ~= UnitFactionGroup("player") and UnitIsPlayer("target") then
for i = 1, #UnitPopupMenus["PLAYER"] do
if UnitPopupMenus["PLAYER"][i] == "ADD_BLIST" or UnitPopupMenus["PLAYER"][i] == "ADD_KOS" then
tremove(UnitPopupMenus["PLAYER"], i)
end
end
tinsert(UnitPopupMenus["PLAYER"], #UnitPopupMenus["PLAYER"] - 1, "ADD_KOS")
end
end
end
UnitPopupButtons["ADD_BLIST"] = {
text = "Add to Blacklist",
dist = 0,
func = function() -- do stuff here
end
}
UnitPopupButtons["ADD_KOS"] = {
text = "Add to KOSlist",
dist = 0,
func = function() -- do stuff here
end
}
function Assignfunchook(dropdownMenu, which, unit, name, userData, ...)
for i=1, UIDROPDOWNMENU_MAXBUTTONS do
local button = _G["DropDownList"..UIDROPDOWNMENU_MENU_LEVEL.."Button"..i];
if button.value == "ADD_KOS" then
button.func = UnitPopupButtons["ADD_KOS"].func
elseif button.value == "ADD_BLIST" then
button.func = UnitPopupButtons["ADD_BLIST"].func
end
end
end
hooksecurefunc("UnitPopup_ShowMenu", Assignfunchook)