Hi y'all!
Been lurking here awhile and decided it was finally time to post (you know, because I'm selfish and need help).
I'm trying to create a basic Lua tool to help me get guild charter signatures.
I have the following code, which identifies players eligible to sign.
lua Code:
local InviteList={}
local PlayersInvited={}
local BACKDROP = {
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
}
--[[ I am beginning to wonder if creating this frame should be sized/implemented diferently ]]
local GuildCreator = CreateFrame("Frame","GuildCreator", UIParent)
HEIGHT = math.min(PlayerFrame:GetBottom() - QuickJoinToastButton:GetTop() -40, 500)
WIDTH = PlayerFrame:GetRight()-PlayerPortrait:GetLeft()
GuildCreator:SetSize(WIDTH,HEIGHT) --width, height
--[[I hear BACKDROP is "basically obsolute"...but I haven't spent the time
or figured out how to implement textures well yet, so...guidance appreciatedf]]
GuildCreator:SetBackdrop(BACKDROP)
GuildCreator:SetBackdropColor(0, 0, 0)
GuildCreator:SetPoint("TOPLEFT","PlayerPortrait","BOTTOMLEFT", 0, -20)
GuildCreator:RegisterEvent("NAME_PLATE_UNIT_ADDED")
GuildCreator:SetScript("OnEvent", function(self, event, ...)
f[event](self, ...)
end)
local function CheckSameRealm(unitToken)
local name, realm = UnitName(unitToken)
local isSameRealm = false -- defaulting to False
if realm == nil then isSameRealm = true
end
return isSameRealm
end
local function CheckHasGuild(unitToken)
local guildName, guildRankName, guildRankIndex = GetGuildInfo(unitToken)
local hasGuild = true
if guildName == nil then hasGuild = false end
return hasGuild
end
local function CheckAlreadyInvited(name) return not not PlayersInvited[name] end --[[HUGE THANKS TO: Meorawr, Icesythe7, and Vlad]]
local function CheckAlreadyOnList(name) return not not InviteList[name] end
local function CheckIsPlayer(unitToken) return not not UnitIsPlayer(unitToken) end
local function CheckElligibility(unitToken)
local name, realm = UnitName(unitToken)
local isPlayer = CheckIsPlayer(unitToken)
local isSameRealm = CheckSameRealm(unitToken)
local hasGuild = CheckHasGuild(unitToken)
local alreadyInvited = CheckAlreadyInvited(name)
local alreadyOnList = CheckAlreadyOnList(name)
local isElligible = false
if isSameRealm and isPlayer and not hasGuild and not alreadyInvited and not alreadyOnList then isElligible = true end
return isElligible
end
Now I need to use prospects identified to create a frame (or set a frames) that will allow me to:
- Target the prospect (obviously this doesn't need to happen first, but it's the part I currently anticipate being the most difficult)
- Whisper them to ask if they would might signing my guild charter
- Request GuildCharterSig
- Remove the frame(s) for that prospect so that there are always 10 (arbitrary number) of these secure buttons fit to the frame
For this, I'm given to understand FramePools are the way to go...but after browsing the source code and finding frustratingly few examples, I'm still lost on how to implement this.
Currently I'm trying to sort out just how to create the frames...I havn't even really been able to figure out how to keep ten populated at all times.
My attempt to create the "TargetUnit" frame is:
lua Code:
local pool = CreateFramePool("Button", GuildCreator, "SecureUnitButtonTemplate")
-- To create or reuse a button:
local function AddProspect(prospect)
local button = pool:Acquire()
button:SetAttribute("unit", prospect)
button:RegisterForClicks("AnyUp")
button:SetAttribute("*type1", "target")
local t = button:CreateFontString()
t:SetFontObject(GameFontHighlightSmall)
t:SetText(target)
t:SetPoint("CENTER")
button:SetSize(WIDTH-10, HEIGHT/10) -- make the width slightly smaller than it's parent frame and make room for ten active buttons
local bg = button:CreateTexture()
bg:SetColorTexture(0.317, 0.317, 0.317, .5) -- Greyish color; half opaque
bg:SetAllPoints()
button:Show()
return button
end
Sorrry for the nooboscity, I'm just out of my depth a bit.