Quantcast
Getting my Lua nameplate script right. - WoWInterface
Thread Tools Display Modes
06-12-17, 04:12 PM   #1
Mandraxon
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 17
Getting my Lua nameplate script right.

Hello
I am trying to ad a nameplate funktion to my Little project Emyramod

i already have the scaling working in the LUA but i want the funktion to change font size on the nameplate but i cant get it right

anyone to share a light on this?

Lua Code:
  1. -- Nameplate targeting size
  2.  
  3. local Frame = CreateFrame("Frame")
  4. Frame:RegisterEvent("PLAYER_LOGIN")
  5.  
  6. Frame:SetScript("OnEvent", function(...)
  7. SetCVar("nameplateMaxDistance", 45)
  8. SetCVar("nameplateSelectedScale", 1.2)
  9. end)
  10.  
  11. --Set nameplate fontsize
  12.  
  13. local f = CreateFrame("Frame")
  14. f:RegisterEvent("PLAYER_LOGIN")
  15. f:SetScript("OnEvent", function()  
  16.  
  17. local function SetFont(obj, optSize)
  18.    local fontName= obj:GetFont()
  19.    obj:SetFont(fontName,optSize,"OUTLINE")
  20. end
  21.  
  22. SetFont(SystemFont_LargeNamePlate,10)
  23. SetFont(SystemFont_NamePlate,10)
  24. SetFont(SystemFont_LargeNamePlateFixed,10)
  25. SetFont(SystemFont_NamePlateFixed,10)
  26.  
  27. end)
  Reply With Quote
06-14-17, 05:09 AM   #2
aallkkaa
A Warpwood Thunder Caller
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 98
Hello Mandraxon,

I'm really not that savy about all this but I do see a couple odd things in your code:

SetFont is a global WoW function defined by Blizzard.
Yet, you define a new, local, SetFont function (which, if it were allowed by the game's API, would indeed replace the orginal SetFont function).
And then, within this new, local function, you call the SetFont function! Which one are you trying to call? The original global?... Or recursively call your own new local one?...
In the former case, had your function successfully replaced the original one, it would have failed to call the original because that would no longer exist (be callable by that name). In the later case, then your function doesn't actually do anything except define a local variable and call itself again.

As I said, I know nearly nothing about all this and I understand your "error" as a simple overlook (like many I often do). I don't actually have an answer for you; matter of fact I don't know whether you can actually change the Blizzard nameplates' fonts, might be the only way around would be to somehow disable the default nameplates and replace them entirely with your own. Or maybe you don't need that. I just don't know.
Just thought the above pointer might help you move forward on your endeavour.
  Reply With Quote
06-14-17, 05:35 PM   #3
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 962
Originally Posted by aallkkaa View Post
SetFont is a global WoW function defined by Blizzard.
Yet, you define a new, local, SetFont function (which, if it were allowed by the game's API, would indeed replace the orginal SetFont function).
And then, within this new, local function, you call the SetFont function! Which one are you trying to call? The original global?... Or recursively call your own new local one?...
In the former case, had your function successfully replaced the original one, it would have failed to call the original because that would no longer exist (be callable by that name). In the later case, then your function doesn't actually do anything except define a local variable and call itself again.

I also don't have an answer, but I think you're confused with the FontInstance.SetFont method, rather than it being a global function
  Reply With Quote
06-15-17, 07:00 AM   #4
aallkkaa
A Warpwood Thunder Caller
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 98
Originally Posted by Ketho View Post
I also don't have an answer, but I think you're confused with the FontInstance.SetFont method, rather than it being a global function
Mostly true, yes. I mean, I do understand the difference between a method such as :SetFont and a global function (like SetCVar for example), but indeed I did confuse myself over :SetFont - a fine example of my frequent "overlooks"...

So, in fact, Mandraxon's script is actually correct - as far as what I said wasn't...? I mean, no conflicts whatsoever can occur from her/him defining a local SetFont function...?

Thank you for taking the time to correct me, Ketho.
And I apologize to Mandraxon for doing nothing more than adding to the confusion.
  Reply With Quote
06-15-17, 03:30 PM   #5
Mandraxon
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 17
Hey guys thanks for taking the time.
since i am utterly N00b at this i realy do not have a clue lol..
basicly i found the font part on a nothe thread but cant get it to work as i want.

what i want to do is be able to change the nameplate fontsize as i Think the stock size is WAY to big.
  Reply With Quote
06-20-17, 08:47 PM   #6
aallkkaa
A Warpwood Thunder Caller
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 98
Hi Mandraxon,

I've been messing around WoW Lua for a few years now but I'm still a noob at it. Not saying this to discourage you, more like "I've been playing WoW for a few years now and I'm still a noob at it." The later is as true as the former.

But I do have a few things down.
What I was talking before was about global and local variables and functions.
Global variables or functions can be accessed by any Lua script. The standard Lua functions implemented in WoW are global. The WoW-specific Lua functions a user Lua-script can call are global (NB: WoW has some protected functions which can only be called by other Blizzard functions, not by user-scripts).
For a list of standard Lua functions present in WoW, see: http://wow.gamepedia.com/Lua_functions
For a list of WoW-specific Lua functions, see: http://wow.gamepedia.com/Global_functions
Local functions (and variables) are so declared by prefexing their declaration with the reserved word "local" (no quote of course!) and can only be accessed within the scope in which they were declared. For example, functions declared as local in a .lua file can only be called in that same file (not in another file).
Your "SetFont" function, declared and defined as "local function SetFont(obj, optSize)" etc is an example of a local function.
It can get fairly more complicated than this but for starters I guess this is good enough.

But I'll add this: It's not a good idea to have a global and a local function with the same one name (unless you actually want to replace the global function with the local one; which may also not be such a good idea, though it is possible).
I thought you'd make this mistake, but as Ketho pointed out, what I called "the global SetFont" is NOT a global function but rather a method of the respective font objects. In a way, methods work as functions local to a specific widget, usually a frame (or a font object ...). Simply put, FrameOne:Hide() and FrameTwo:Hide() are not the same, as FrameOne:Hide() hides FrameOne but not FrameTwo, and vice-versa.

So now looking at your code again, I think I know why it's not working. I mean, the logic is mostly correct but there may be something ...
A "font object" can refer to the ones you whose fonts you are trying to change (SystemFont_LargeNamePlate, SystemFont_NamePlate, ...) but they can also be the texts on the player's nameplate text or, another one, the target's nameplate text, or .. some other namplate's text, ...
Now, changing the font for those specific font-objects might work the way your code is doing it but that would be cumbersome to code and a lot heavier on the CPU cycles (possibly reducing FPS rate as a consequence).
Changing the generic nameplate font objects, from which the aforementioned specific font-objects inherit their properties (including font size), would be a one-time task with zero subsequent impact on the game performance. But this can likely NOT be done because said properties are defined in FrameXML which means they are protected.
Yet, there are a couple properties you can usually change for any UI object, scale being one of them. So, despite the fact you may not be able to change the font size (in points), you can likely change its scale.

I can't test it out right now, but try changing your code to this:
EDIT: I tested it (changing the scale of the nameplate system fonts and it did NOT work.
Specifically, running the following command on the game console throws an error that the method (:SetScale) is a nil value (doesn't exist):
Code:
/run SystemFont_NamePlate:SetScale(0.8)
I removed the code I had proposed earlier.

Sorry, I can't help you any further at this point.

Last edited by aallkkaa : 06-21-17 at 07:27 PM.
  Reply With Quote
08-10-17, 05:21 AM   #7
Sylen
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 49
I use this to change the size of the nameplate font.

Code:
local function ScaleNameplateNames(...)
 for i, frame in ipairs(C_NamePlate.GetNamePlates()) do
	local names = frame.UnitFrame.name
	names:SetFont(STANDARD_TEXT_FONT, 10, "THINOUTLINE")
 end
end
NamePlateDriverFrame:HookScript("OnEvent", ScaleNameplateNames)
end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Getting my Lua nameplate script right.

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