Thread Tools Display Modes
01-16-22, 08:42 PM   #1
pinmouse
A Murloc Raider
Join Date: Jul 2014
Posts: 9
Question 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!
  Reply With Quote
01-16-22, 09:58 PM   #2
pinmouse
A Murloc Raider
Join Date: Jul 2014
Posts: 9
Lightbulb

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!!!
  Reply With Quote
01-19-22, 02:54 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » How to wrap my macro addon in PLAYER_ENTERING_WORLD

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off