WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   How to wrap my macro addon in PLAYER_ENTERING_WORLD (https://www.wowinterface.com/forums/showthread.php?t=59022)

pinmouse 01-16-22 08:42 PM

How to wrap my macro addon in PLAYER_ENTERING_WORLD
 
I used https://addon.bool.no/ to generate an addon for me from a macro. I'd like that addon to run every time I zone. I believe I should wrap it in a function that uses PLAYER_ENTERING_WORLD but I'm not really sure how to do it. Here is what I have so far...

NameplateShrinker.toc
Code:

## Interface: 90100
## Title: NameplateShrinker
core.lua

core.lua
Code:

C_NamePlate.SetNamePlateFriendlySize(60, 30)
Hoping someone can tell me how to run that line of code in the core.lua so that it fires when I zone.

Thanks!

pinmouse 01-16-22 09:58 PM

Ended up doing this...

Code:

local ShrinkNameplate = CreateFrame("frame", "ShrinkNameplate")
ShrinkNameplate:RegisterEvent("PLAYER_ENTERING_WORLD")

ShrinkNameplate:SetScript("OnEvent", function(self, event, ...)
        if(event == "PLAYER_ENTERING_WORLD") then
                C_NamePlate.SetNamePlateFriendlySize(60, 30)
                print("Nameplates Resized!")
        end
end)

I think it will work - I'm about to test it, but if you see any way I can simplify it more please let me know.

Thanks!!!

Seerah 01-19-22 02:54 PM

Good job. If you would like to simplify it a little, you can do just this:
Lua Code:
  1. local ShrinkNameplate = CreateFrame("frame")
  2. ShrinkNameplate:RegisterEvent("PLAYER_ENTERING_WORLD")
  3.  
  4. ShrinkNameplate:SetScript("OnEvent", function()
  5.     C_NamePlate.SetNamePlateFriendlySize(60, 30)
  6. end)
Since you only have 1 event registered to your frame, you don't have to check to see which event just fired. And since you are not using any of the arguments passed through to your OnEvent function, you don't need to save them to any variables. Lastly, you don't need to give your frame a global name, since you won't be accessing it outside of your addon.


All times are GMT -6. The time now is 05:09 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI