Script to post target name

I made a spamable macro to inspect players. I added the following to post the target’s health.

/script print(UnitHealth(“target”)/1000,“kHP”)

(Note: I couldn’t figure out how to add a comma to the health value so i gave up and expressed the value in thousands.)

I’d like to post the target’s name with, or in the line above, the target’s health. My trial and error skills have resulted in only errors so far. Any help with this or info on resources to learn LUA, or i guess WoW’s version of LUA, would be appreciated. I’m pretty much need the Moron’s Guide to LUA as I haven’t coded since DOS.

/run local u="target" if UnitExists(u) then print(format("%s has %s of %s hp (%.1f%%).",UnitName(u),BreakUpLargeNumbers(UnitHealth(u)),BreakUpLargeNumbers(UnitHealthMax(u)),UnitHealth(u)*100/UnitHealthMax(u))) end

A little more than you asked for but hopefully you can pick it apart to modify. BreakUpLargeNumbers() adds comma separators (This is something Blizzard added. It’s not standard Lua.) format() will let you plug in values into a prepared string, where %s (string), %d (integer), %.1f (float to one decimal) will be replaced with the same-ordered parameter that follows the pattern.

For learning Lua, the official site is very accessible. (Note we’re on Lua 5.1 though that won’t affect your everyday use of Lua.)

Community-based documentation for WoW in-game API:

If you want a more guided approach, there’s a book called World of Warcraft Programming: A Guide and Reference for Creating WoW Addons by James Whitehead (author of Clique, TomTom and others). I don’t know how current it is but it should still be relevant for 90% of stuff even if it hasn’t been updated for years.

2 Likes

Thank you!