Created
August 25, 2024 16:19
-
-
Save aTei/e725b8e025c15fe34f8f96769b26925b to your computer and use it in GitHub Desktop.
WoW addon that makes it easier to find alive target with the same name. `/lasttarget` in chat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local lastTargetName = nil | |
| -- Create a frame to capture events | |
| local frame = CreateFrame("Frame") | |
| -- Register the frame to listen to the ADDON_LOADED event and PLAYER_TARGET_CHANGED event | |
| frame:RegisterEvent("ADDON_LOADED") | |
| frame:RegisterEvent("PLAYER_TARGET_CHANGED") | |
| -- Function to handle events | |
| frame:SetScript("OnEvent", function(self, event, addonName) | |
| if event == "ADDON_LOADED" and addonName == "LastTarget" then | |
| elseif event == "PLAYER_TARGET_CHANGED" then | |
| local targetName = UnitName("target") | |
| -- If there is a valid target, store its name | |
| if targetName and targetName ~= "" then | |
| lastTargetName = targetName | |
| end | |
| end | |
| end) | |
| -- Function to create and show an input box with the target command | |
| local function ShowTargetInputBox(targetName) | |
| -- Create an EditBox frame | |
| local editBox = CreateFrame("EditBox", "LastTargetEditBox", UIParent, "InputBoxTemplate") | |
| editBox:SetSize(300, 30) -- width, height | |
| editBox:SetPoint("CENTER") -- position in the middle of the screen | |
| editBox:SetAutoFocus(true) -- auto-focus the edit box | |
| editBox:SetText("/target " .. targetName) -- set the text to the target command | |
| editBox:HighlightText() -- highlight the text for easy copying | |
| -- Add a title to the input box | |
| local title = editBox:CreateFontString(nil, "OVERLAY", "GameFontNormal") | |
| title:SetPoint("BOTTOM", editBox, "TOP", 0, 5) | |
| title:SetText("Copy the command below:") | |
| -- Function to hide the input box when pressing Enter or Escape | |
| editBox:SetScript("OnEnterPressed", function(self) | |
| self:ClearFocus() | |
| self:Hide() | |
| end) | |
| editBox:SetScript("OnEscapePressed", function(self) | |
| self:ClearFocus() | |
| self:Hide() | |
| end) | |
| -- Show the edit box | |
| editBox:Show() | |
| end | |
| -- Register the slash command | |
| SLASH_LASTTARGET1 = "/lasttarget" | |
| SlashCmdList["LASTTARGET"] = function(msg) | |
| -- Check if there is a stored target name | |
| if lastTargetName then | |
| ShowTargetInputBox(lastTargetName) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment