Thread Tools Display Modes
01-09-11, 08:32 AM   #1
Cerranos
A Cyclonian
 
Cerranos's Avatar
Join Date: Dec 2010
Posts: 48
STUF Help - [perchp]

Currently I'm using Stuf UF... and was wondering how I could change the "[perchp]" text to include a decimal, such as 100.0% instead of just a whole number. This way, it'll make it easier to determine what specific health the target is at when it is around 0%; eg 0.6% or 0.2%, etc.

Any help is greatly appreciated. Thank you in advance!
  Reply With Quote
01-09-11, 11:06 AM   #2
Taryble
A Molten Giant
 
Taryble's Avatar
Join Date: Jan 2009
Posts: 811
Well, the [perchp] tag won't work for you.

However, StUF has the option for "Custom Lua Code" or "Custom Lua Script". Use that, and copy/paste this into the text box that pops up, and then click "Accept", and then click the box for "Frequent Updates" (necessary to see changes as they happen).

Code has been tested - shows "%100.0" at full HP, "%37.1" after I jumped from the FP in Thunder Bluff to the lowest plateau in TB.

Changing the number in the two instances of "%%%.1f" will change how many positions after the decimal point are shown - 1 for 1, 2 for 2, etc.
Code:
function(unit, cache, textframe)
  if UnitExists(unit) then
    local perchp = 100 * UnitHealth(unit)/UnitHealthMax(unit)
    return "%.1f%%",perchp
  else
    local perchp = 100 * UnitHealth("player")/UnitHealthMax("player")
    return "%.1f%%",perchp
  end
end
__________________
-- Taryble

Last edited by Taryble : 01-10-11 at 04:10 PM. Reason: Whoops - needed to change "unit" in "else" to "player", and move % signs to after
  Reply With Quote
01-10-11, 12:32 PM   #3
Cerranos
A Cyclonian
 
Cerranos's Avatar
Join Date: Dec 2010
Posts: 48
Awesome... just one quick question; the code puts the % symbol in front of the number - how would I get it to be behind the number?
  Reply With Quote
01-10-11, 01:34 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
See where there are three percent signs in a row in the code? Move two of them to after the f.
__________________
"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
01-10-11, 02:50 PM   #5
Cerranos
A Cyclonian
 
Cerranos's Avatar
Join Date: Dec 2010
Posts: 48
Originally Posted by Seerah View Post
See where there are three percent signs in a row in the code? Move two of them to after the f.
Very cool, Seerah!

I had a hunch that was it... but I entered 3 of the percentage symbols initially.

Thank you for the help!!
  Reply With Quote
01-10-11, 02:56 PM   #6
Cerranos
A Cyclonian
 
Cerranos's Avatar
Join Date: Dec 2010
Posts: 48
It seems to only work for my player frame... how would I get it to work for target, pet, group, etc? I tried replacing the "player" text with "target," but it shows -1.$

EDIT: Nvm... I was in config mode for Stuf. But I'm curious - this code should work for all unit frames that I apply it to, right? Regardless if it's a pet, target, target/target, the text should still have "player" referenced? (sorry, at work and haven't had a chance to test it)

Last edited by Cerranos : 01-10-11 at 03:05 PM.
  Reply With Quote
01-10-11, 04:09 PM   #7
Taryble
A Molten Giant
 
Taryble's Avatar
Join Date: Jan 2009
Posts: 811
StUF is a little goofy - that code is safe to use in any frame, the "player" reference in the second half is to deal with StUF's config mode.

StUF can fake stuff on it's own really well - if you're using the tags that StUF provides.

I'll go line by line through the code, so you can see what's going on.

Code:
function(unit, cache, textframe)
  if UnitExists(unit) then 
    local perchp = 100 * UnitHealth(unit)/UnitHealthMax(unit)
    return "%.1f%%",perchp
  else
    local perchp = 100 * UnitHealth("player")/UnitHealthMax("player")
    return "%.1f%%",perchp
  end
end
Code:
function(unit, cache, textframe)
function header required by StUF Custom Lua

Code:
if UnitExists(unit) then
if there's actually such a unit (target, party, etc) do the next chunk (in this case, the next 2 lines)

Code:
local perchp = 100 * UnitHealth(unit)/UnitHealthMax(unit)
make a local variable called "perchp", and set it equal to their current percentage of HP.

Code:
return "%.1f%%",perchp
tell StUF to show the current HP percentage, with 1 decimal place, and a % sign after it

Code:
else
refers to the 2nd line - if Unit does NOT exist, do the next chunk (next 2 lines)

Code:
local perchp = 100 * UnitHealth("player")/UnitHealthMax("player")
make that local variable perchp, set it to the player's health percentage (why? so StUF config mode doesn't bug out)

Code:
return "%.1f%%",perchp
return the player's health percentage, formatted the same as earlier

Code:
end
closes the If-Then-Else decision

Code:
end
closes the function
__________________
-- Taryble
  Reply With Quote
01-10-11, 05:28 PM   #8
Cerranos
A Cyclonian
 
Cerranos's Avatar
Join Date: Dec 2010
Posts: 48
Awesome... got it to work. Thanks again!

  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » STUF Help - [perchp]

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