Thread Tools Display Modes
11-24-13, 12:03 PM   #1
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
Stuf Custom Lua Help

I'm trying to make some custom text labels for Stuf Unit Frames that will show a "C" when in combat, an "L" for party/raid leader, "R" for resting, and a "+" for loot master. I found an older thread that had the code for this, but when I entered it into Stuf it didn't work.

Here's what I found:
Code:
    function(unit, cache) 
local str1 = '' 
local str2 = '' 
local str3 = '' 
local str4 = '' 
local str5 = '' 

local _, partyMaster, _ = GetLootMethod() 

if UnitAffectingCombat("player") == 1 then 
str1 = 'C' 
end 
if IsRaidLeader("player")==1 then 
str2 = 'L' 
end 
if UnitIsPVP("player") == 1 then 
str3 = 'P' 
end 
if partyMaster == 0 then 
str5 = '+' 
end 
if IsResting("player") == 1 then 
str4 = 'R' 
end 

return '|cffff4500%s|r |cffffff00%s|r |cffff9900%s|r |cff00ff00%s|r |cffffffff%s|r ', str1,str2,str3,str4,str5 
end

Any insight as to why that doesn't work and how I can fix it? I'm a complete beginner at Lua so I have next to no idea what I'm doing.

Any help would be awesome!
  Reply With Quote
11-24-13, 01:06 PM   #2
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
UPDATE: I realized I didn't have Stuf's Frequent Updates option enabled, so the code was returning my status at the time I made changes rather than checking on-the-fly.

I got it working now. I'm looking to change colors but don't know how Lua handles colors or what kind of codes I need, so if anyone could help, I'd appreciate it!
  Reply With Quote
11-24-13, 01:18 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
The above code is using hexadecimal color codes to alter the colors of each indicator right in the string using a color escape sequence.

http://wowpedia.org/UI_escape_sequences#Coloring
__________________
"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
11-24-13, 01:52 PM   #4
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
Oh, okay. I see it now. I didn't realize the alpha was in the code before. Thanks!
  Reply With Quote
11-25-13, 03:15 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The alpha values in font string color codes are ignored; only the RGB values matter. You can only change the opacity of the entire font string, by using the SetAlpha method of the font string object itself; there's no way to do it through escape sequences in the text. I don't use Stuf, but I'd assume there's an option for changing the opacity of the font string somewhere.

Also, you can simplify your function quite a bit:

Code:
function(unit, cache)
	local _, partyMaster = GetLootMethod()
	return "%s%s%s%s%s ",
		UnitAffectingCombat("player") and "|cffff4500 C|r" or "",
		IsRaidLeader("player") and "|cffffff00 L|r" or "",
		UnitIsPVP("player") and "|cffff9900 P|r" or "",
		partyMaster == 0 and "|cff00ff00 +|r" or "",
		IsResting() and "|cffffffff R|r" or ""
end
I moved the color codes into the conditional string definitions instead, so it's easier to tell which color codes with which, and did the same with the spaces so you won't end up with giant gaps (eg. when you're resting, but none of the other conditions apply).
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-11-13, 06:15 PM   #6
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
Hey Phanx,

Sorry I didn't see your reply earlier. Thanks for the help! I've revisited this since I realized that using the code for targets was (obviously) returning values from the player.

I tried your change, but now the text is displaying the whole color code rather than the actual values in the particular color. I don't know enough about what the return portion and color codes are doing to fix it myself.

That said, I used "UnitIsGroupLeader" and changed the three lines for leader, PVP, and combat to "target" for use on target frames (I deleted the rested since AFAIK we can't see other players' rested status). Is that the right way to handle that?

If you have any idea how to fix it, I'd really appreciate it.

Thanks again!
  Reply With Quote
12-11-13, 08:20 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Synchrony View Post
I tried your change, but now the text is displaying the whole color code rather than the actual values in the particular color.
You mean it's showing the literal color code, instead of coloring the text? If so, try changing each "|" in the code to "\124".

Originally Posted by Synchrony View Post
That said, I used "UnitIsGroupLeader" and changed the three lines for leader, PVP, and combat to "target" for use on target frames (I deleted the rested since AFAIK we can't see other players' rested status). Is that the right way to handle that?
Post your code. I'm not going to try to guess what it looks like after your changes. You are correct, though, that you cannot get the rested status for other players.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-11-13, 09:52 PM   #8
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Originally Posted by Phanx View Post

Code:
function(unit, cache)
	local _, partyMaster = GetLootMethod()
	return "%s%s%s%s%s ",
		UnitAffectingCombat("player") and "|cffff4500 C|r" or "",
		IsRaidLeader("player") and "|cffffff00 L|r" or "",
		UnitIsPVP("player") and "|cffff9900 P|r" or "",
		partyMaster == 0 and "|cff00ff00 +|r" or "",
		IsResting() and "|cffffffff R|r" or ""
end
I moved the color codes into the conditional string definitions instead, so it's easier to tell which color codes with which, and did the same with the spaces so you won't end up with giant gaps (eg. when you're resting, but none of the other conditions apply).
Can I ask a silly question? (not completely related though)
I am not completely understanding the return part sadly. Does it work the same as a format() with the strings? I'm just trying to put it in a plainer English form And this is one of the things that keep on confusing me
  Reply With Quote
12-12-13, 12:15 AM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I have never actually used (or looked at the code of) Stuf or LuaTexts (the library it uses for text tagging) but I am assuming it takes the returns from your custom tag function and either passes them through string.format or passes them directly to the fontstring's SetFormattedText method.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-13-13, 07:46 PM   #10
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
Code:
function(unit, cache)
    local _, partyMaster = GetLootMethod()
    return "%s%s%s%s%s ",
        UnitAffectingCombat("target") and "\124cffff4500 C\124r" or "",
        UnitIsGroupLeader("target") and "\124cffffff00 L\124r" or "",
        UnitIsPVP("target") and "\124cffff9900 P\124r" or "",
        partyMaster == 0 and "\124cff00ff00 +\124r" or "",
end
This is what I'm using for target. It doesn't seem to want to show combat, loot master, or group leader on my targets. I have no idea what the loot master portion is doing, anyway (not that I have much grasp over the rest).

I really appreciate the help, Phanx. I know you don't have to put any effort in, but you do and I thank you for it!
  Reply With Quote
12-13-13, 10:13 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Target the mob and run the following command. Report back with which it prints to your chat frame. If it prints the correct text, then the problem is not in the function itself, but in some other area of Stuf (check your settings etc.)

Code:
/run local u="target" print(format("%s%s%s%s%s",UnitAffectingCombat(u)and "\124cffff4500C\124r" or "",UnitIsGroupLeader(u)and "\124cffffff00L\124r" or "",UnitIsPVP(u)and "\124cffff9900P\124r" or ""))
(Removed the master loot part since it won't work for units other than the player the way it's written.)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-14-13, 01:13 AM   #12
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
I tested Phanx's code out of curiosity and got an error, and I realized that your format string expects five arguments, with only three provided. I shortened "%s%s%s%s%s" to "%s%s%s", and it works for me.

I went back and looked at Synchrony's target code, and it expects five arguments as well, with only four provided. "%s%s%s%s%s " should be "%s%s%s%s ".

Assuming Stuf passes whatever that function returns into format() or SetFormattedText(), that may resolve your issue.
  Reply With Quote
12-19-13, 06:26 PM   #13
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
I finally got a chance to try the code, and I got an error also (even after removing "%s").

Code:
[string "local u="target" print(format("%s%s%s%s",Un..."] line 1:
   bad argument #5 to 'format' (string expected, got no value)
I really wish I understood more about how Lua works so I could understand what's going on myself, but I haven't had much luck learning about it. If you know anything about this, that'd be awesome.

Thanks again.
  Reply With Quote
12-19-13, 06:37 PM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
For the slash command you need to remove two "%s". For the Stuf code you only need to remove one.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-19-13, 06:44 PM   #15
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
Ah, right, the loot master.

Fixed it and it did return the "L" for leader. So that command is working, it appears. Is there a way to make loot master show up as well?
  Reply With Quote
12-19-13, 07:10 PM   #16
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
I guess first of all, I need to figure out where the breakdown between the code and Stuf printing the right things is.

As far as I can tell, it should work, so I have no idea.
  Reply With Quote
12-19-13, 07:31 PM   #17
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
Well, copying directly from the code for "player" and changing it hasn't worked. As soon as I change something to "target", it disappears (even if I'm targeting myself, the group leader/loot master).

On the other hand, changing the code for the player frame from "player" to "target" DOES have the intended effect (if I'm targeting the leader [me], it shows "L" on my player frame).

I can only imagine it has something to do with the target frame. I had wondered if the commands were player specific, but if that was the case, changing the text on the player frame would show a blank rather than the "L" when targeting myself.

EDIT: It only stops working on the target when I remove the "IsResting" line. I pasted the code from the player frame into the target frame, deleted out or changed portions until the "L" disappeared. It stayed until I removed that line.

I'm flummoxed.

Last edited by Synchrony : 12-19-13 at 07:37 PM. Reason: added info
  Reply With Quote
12-19-13, 08:10 PM   #18
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The player code is fine.

For the target, since you removed one item (resting) you need to remove one "place an item here" code from the base pattern. Remove one "%s" from the pattern -- "%s%s%s%s%s " needs to change to "%s%s%s%s ". The number of "%s" codes in the pattern must match the number of items to be displayed.

If you still want to test the slash command (though there's not really any reason to) you need to remove two "place an item here" codes, since it includes TWO fewer items (resting + loot) than the player code -- "%s%s%s%s%s" needs to change to "%s%s%s".
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-21-13, 07:22 PM   #19
Synchrony
An Aku'mai Servant
Join Date: Jul 2012
Posts: 35
I realized that I'm dumb and just left the comma at the end of the line preceding "IsResting" when I deleted it and that was causing it to stop working. Still, though, it'd be nice to be able to show loot master on the target. Is that possible?
  Reply With Quote
12-21-13, 11:51 PM   #20
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Replace this:
Code:
	local _, partyMaster = GetLootMethod()
with this:
Code:
	local masterUnit, method, partyID, raidID = nil, GetLootMethod()
	if method == "master" then
		if partyID then
			masterUnit = partyID == 0 and "player" or ("party" .. partyID)
		elseif raidID then
			masterUnit = "raid" .. raidID
		end
	end
Then replace this:
Code:
		partyMaster == 0 and "\124cff00ff00 +\124r" or ""
with this:
Code:
		(masterUnit and UnitIsUnit(masterUnit, unit)) and "\124cff00ff00 +\124r" or ""
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 12-22-13 at 05:44 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Stuf Custom Lua Help


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