PDA

View Full Version : Need help with API and percentages.


Bryant
08-11-2006, 02:02 AM
I just started to learn LUA a day or two ago, and have some of the basics down. Here are my two questions:

1. How do you make text appear in the middle of the screen, such as the red "Not enough mana", and "Out of range" text that shows above the player? Is there an API variable for this? If so, is it possible to change the size, shape, and color?

2. I'm not sure how to phrase this one, really. How does the WoW API (or it might be how LUA calculates percentages) work with percentages. For exampe, I want to display my targets health has dropped below 20%. I'm pretty sure of the basic layout of the code:

if UnitHealth("target") <= 20% then SendChatMessage('%t is about to die!')
else
end

Theres probably some serious errors in there. Don't be afraid to point them out and criticize. :thumbsup:

I've been learning LUA from http://robertico.ro.funpic.de/en/index.php, and the author doesn't use grammar very well.

Thanks for any help, guys.

Daviesh
08-11-2006, 09:25 AM
WoW wiki is your friend:

http://www.wowwiki.com/API_UnitHealth

Returns the current health of the specified unit. The health is returned in real points only if the unit is in the player's group (party or raid). Otherwise, a percentage is returned (0-100).

Duugu
08-11-2006, 09:45 AM
1. How do you make text appear in the middle of the screen, such as the red "Not enough mana", and "Out of range" text that shows above the player? Is there an API variable for this? If so, is it possible to change the size, shape, and color?

This is don via anchor points.
To place frame in the middle of the screen just use "UIParent" as parent (the top level frame) and the anchor point "CENTER".
Example:

<Frame name="CABBar" parent="UIParent">
<Size>
<AbsDimension x="100" y="100"/>
</Size>
<Anchors>
<Anchor point="CENTER" relativeTo="UIParent" relativePoint="CENTER">
</Anchor>
</Anchors>
</Frame>

Bryant
08-11-2006, 02:05 PM
Thanks for the help, Duugu and Daviesh.

Daviesh, I was asking how LUA handles percentages in equations, not just UnitHealth in perticular. I think I know how now, though. I'll just have to multiply .2 (20% in decimal form) by UnitHealth("target") to represent 20% of health unless someone knows an easier way. :wink:

Bryant
08-11-2006, 10:48 PM
Since this is related to API, I'm not going to make a new post for it.

I need some help with macros. What I'm trying to do is display the resistance of my target in the chat (Will this work if the unit is not in my party/raid?). I thought I would be able to make global variables and then call them in another macro, because I saw someone reply to another post telling them to do it to save characters. They said just press the macro when you log in, and all of the variables will be there until you log out.

Well, there are values that display in the chat, but they're not correct values. It always displays the target as having every resistance as 0.

Code for setglobal():
/script setglobal('F',UnitResistance("target",2));
/script setglobal('I',UnitResistance("target",4));
/script setglobal('S',UnitResistance("target",5));
/script setglobal('N',UnitResistance("target",3));
/script setglobal('A',UnitResistance("target",6));


Code for displaying the resistances in chat:
/script SendChatMessage('Fire '..F)
/script SendChatMessage('Ice '..I)
/script SendChatMessage('Shadow '..S)
/script SendChatMessage('Nature '..N)
/script SendChatMessage('Arcane '..A)


I tried /script getglobal(F), but it didn't work. I have no idea why the values are being displayed but are shwoing as 0. I asked one person I targeted, and he said he had 20 in all resistances, and then I tried it on myself with 10 frost resist, but it also did not show.

Any help is appreciated. =]

Duugu
08-11-2006, 11:34 PM
Quote from wowwiki:

Arguments

"Unit" The unit to be evaluated (appears to only work on "player")

http://www.wowwiki.com/API_UnitResistance

Bryant
09-11-2006, 12:19 AM
Doh... I seriously need to read more...

Thanks again, Duugu.