WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Combine two lua scripts (https://www.wowinterface.com/forums/showthread.php?t=58061)

Aur0r4 06-21-20 06:16 AM

Combine two lua scripts
 
Hi guys,

Since I'm not good in Lua and my friends that are more into programming can't help me with that, this forum is my last hope.

I want to create a Lua-Text in PitBull Unit Frames, so that it shows this:

Name | HP %

Name should be in classcolor and HP% in HPColor.

So I have to separate scripts for that running:

Name | (ClassColor)
Code:

local r,g,b = ClassColor(unit)
return '|cff%02x%02x%02x%s|r %s%s%s|',r,g,b,Name(unit),Angle(AFK(unit) or DND(unit))

HP % (HPColor)
Code:

local s = Status(unit)
if s then
  return s
end
local cur,max = HP(unit),MaxHP(unit);
local hr,hg,hb=HPColor(cur,max);
return "|cff%02x%02x%02x%.0f|r" or "", hr,hg,hb,100*cur/max


I want to combine both scripts, so that I can display them in one lua-text. I need that, because otherwise I'm not able to center the text within the unitframe.

Can you help me with that?

Thanks!

edit:
We've tried that, but it isn't working:

Code:

local s = Status(unit)
if s then
  return s
end

local cur,max = HP(unit),MaxHP(unit);
local hr,hg,hb=HPColor(cur,max);
local r,g,b = ClassColor(unit)

return '|cff%02x%02x%02x%s|r %s%s%s| |cff%02x%02x%02x%.0f|r',r,g,b,Name(unit),Angle(AFK(unit) or DND(unit)), hr,hg,hb,100*cur/max


Fizzlemizz 06-21-20 11:06 AM

I don't know PitBull so I'm not sure what Status() or Angle() is doing but my best guess is that it has more than 1 return and all but the first one are being cut off because it's no longer the last return in the format.

Without thinking too hard, maybe something like still treating the return as two strings:

Lua Code:
  1. local s = Status(unit)
  2. if s then
  3.   return s
  4. end
  5. local r,g,b = ClassColor(unit)
  6. local string1 = string.format('|cff%02x%02x%02x%s|r %s%s%s|', r,g,b,Name(unit),Angle(AFK(unit) or DND(unit)))
  7. local cur,max = HP(unit),MaxHP(unit);
  8. local hr,hg,hb=HPColor(cur,max);
  9. return string1 .. "|cff%02x%02x%02x%.0f|r" or "", hr,hg,hb,100*cur/max

Aur0r4 06-21-20 11:50 AM

Hi Fizzlemizz,

I have tried it but its not working correctly, I got this:



Do you have another idea? I will show your code to a friend, maybe he can fix it with your help.

Wish I would be better in programming :p

Fizzlemizz 06-21-20 11:57 AM

Lua Code:
  1. local s = Status(unit)
  2. if s then
  3.   return s
  4. end
  5. local r,g,b = ClassColor(unit)
  6. local string1 = string.format('|cff%02x%02x%02x%s|r %s%s%s|', r,g,b,Name(unit),Angle(AFK(unit) or DND(unit)))
  7. local cur,max = HP(unit),MaxHP(unit);
  8. local hr,hg,hb=HPColor(cur,max);
  9. local string2 = string.format("|cff%02x%02x%02x%.0f|r" or "", hr,hg,hb,100*cur/max)
  10. return string1 .. string2

Someone here probably has a better solution.

Aur0r4 06-21-20 02:01 PM

Thank you!
Sadly it is the same outcoming :(

Name |CFF00FF00100

Quote:

Originally Posted by Fizzlemizz
Someone here probably has a better solution.

Hopefully :) or maybe its just a typo? But I don't see it...


Nevermind:

My girlfriend fixed it :p

Lua Code:
  1. local s = Status(unit)
  2. if s then
  3.   return s
  4. end
  5. local r,g,b = ClassColor(unit)
  6. local string1 = string.format('|cff%02x%02x%02x%s|r %s%s%s| ', r,g,b,Name(unit),Angle(AFK(unit) or DND(unit)))
  7. local cur,max = HP(unit),MaxHP(unit);
  8. local hr,hg,hb=HPColor(cur,max);
  9. local string2 = string.format('|cff%02x%02x%02x%.0f|r' or "", hr,hg,hb,100*cur/max)
  10. return string1 .. string2

Kanegasi 06-21-20 02:35 PM

According to PitBull documentation, "LuaText" is simply fed into SetFormattedText and Angle returns three strings, which surrounds the input with "angle brackets" < >. If there's no input, in this case if the unit is not afk or dnd, it still returns three empty strings. Also, if you want to use the pipe character or the percent sign, you need to escape both.

Lua Code:
  1. local s=Status(unit)
  2. if s then return s end
  3. local cur,max=HP(unit),MaxHP(unit)
  4. local hr,hg,hb=HPColor(cur,max)
  5. return "|cff%02x%02x%02x%s|r %s%s%s || |cff%02x%02x%02x%.0f|r %%",ClassColor(unit),Name(unit),Angle(AFK(unit) or DND(unit)),hr,hg,hb,100*cur/max

I left a space between the health and the percent sign.

Edit: I didn't refresh the page before posting, looks like you got it working anyways :)

Aur0r4 06-24-20 03:15 PM

Thanks Kanegesi, it's only half as long, nice. But unfortunately, it gives you an ERROR. :P

Kanegasi 06-24-20 03:27 PM

Thank you for trying my code out, even though you stated you had something working. Unfortunately, "it gives you an ERROR" is not helpful at all.

SDPhantom 06-25-20 09:57 AM

Both ClassColor() and Angle() are only giving their first return values since they are not at the end of the list. The rest are discarded.

Lua Code:
  1. local s=Status(unit)
  2. if s then return s end
  3. local s1,s2,s3=Angle(AFK(unit) or DND(unit))
  4. local cur,max=HP(unit),MaxHP(unit)
  5. local cr,cg,cb=ClassColor(unit)
  6. local hr,hg,hb=HPColor(cur,max)
  7. return "|cff%02x%02x%02x%s|r %s%s%s || |cff%02x%02x%02x%.0f|r %%",cr,cg,cb,Name(unit),s1,s2,s3,hr,hg,hb,100*cur/max


All times are GMT -6. The time now is 01:11 PM.

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