PDA

View Full Version : First Try At Mod Creation


PvtFreddy
27-06-2007, 05:30 PM
Hi all,

I've recently jumped into the world of mod creation and am currently learning Lua. I know much about XML already, and I'm trying to create a mod that will monitor my health and rage/mana as I'm a warrior and priest as mains.

I've come up with most of the code but something is not working. The two bars (health and rage/mana) aren't moving when I regen or take damage or use what power I have. I've been studying mods like ArcHud and MetaHud so ides on what could be the possible problem, however, as I'm still in the phrase of learning Lua, I cant seem to get the gfx of the health/mana/rage to move when needed.

I'm not asking for a solution here, as I want to figure this out myself so I can learn, though maybe a suggestion on what I should be looking for might help.

Thank you ever so much,

PF.

Duugu
27-06-2007, 10:38 PM
Hi

Thats pretty easy. Assuming you're using a status bar:
StatusBar:SetMinMaxValues(min, max) to set up the min/max values
then call StatusBar:SetValue(value)

See http://www.wowwiki.com/Widget_API#StatusBar

JaedxRapture
27-06-2007, 11:33 PM
Make sure you've got the event "UNIT_HEALTH" registered, which passes the UnitID of the unit which triggered the event as arg1.

PvtFreddy
28-06-2007, 02:29 PM
Yes, this I already got. I have to bars to the sides of my character. One green (health), one blue/red (mana/rage). And for the love of god, I can't get them to move when needed. I'll show you an example of my status bar in xml, cause after reading what the previous posts have put I have a feelin I'm going wrong in the xml department.

Example:

<StatusBar name="PlayerFrameHealthBar" inherits="TextStatusBar">
<Size>
<AbsDimension x="25" y="150"/>
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset>
<AbsDimension x="-70" y="-30"/>
</Offset>
</Anchor>
</Anchors>
<BarTexture file="Interface\TargetingFrame\UI-StatusBar"/>
<BarColor r="0" g="1" b="0" a="0.5"/>
</StatusBar>

This example does not include <Scripts> </Scripts> I know but they are there in the original file.

Thank you again.

JaedxRapture
28-06-2007, 04:48 PM
Ack. I hate XML.

Mind if we peek at your scripts/handlers related to the bar?

PvtFreddy
28-06-2007, 05:40 PM
Ack. I hate XML.

Mind if we peek at your scripts/handlers related to the bar?

Sure, let me get it a mo...

<Scripts>
<OnLoad>
PlayerFrame_OnLoad(self)
</OnLoad>
<OnEvent>
PlayerFrame_OnEvent(self, event,...)
</OnEvent>
</Scripts>


Umm, one thing, I was wondering if <StatusBar> could stand alone on its own two feet, if you like, or has it gotta to be wrapped in a <Frame></Frame> section?

Thank you again,

PF

Tunga
28-06-2007, 05:53 PM
I think Jaed was asking for the lua code.

JaedxRapture
28-06-2007, 06:01 PM
Sure, let me get it a mo...

<Scripts>
<OnLoad>
PlayerFrame_OnLoad(self)
</OnLoad>
<OnEvent>
PlayerFrame_OnEvent(self, event,...)
</OnEvent>
</Scripts>


Umm, one thing, I was wondering if <StatusBar> could stand alone on its own two feet, if you like, or has it gotta to be wrapped in a <Frame></Frame> section?

Thank you again,

PF

Statusbar is a frame. "<Statusbar ..></Statusbar>" is the same as "<Frame ..></Frame>", only it tells the game that the frame is specifically a statusbar and should be treated as such.

Edit: Your Lua as well for those two functions would help. Chances are the code-breaking segment is in your Lua.

PvtFreddy
28-06-2007, 07:09 PM
Statusbar is a frame. "<Statusbar ..></Statusbar>" is the same as "<Frame ..></Frame>", only it tells the game that the frame is specifically a statusbar and should be treated as such.

Edit: Your Lua as well for those two functions would help. Chances are the code-breaking segment is in your Lua.


function PlayerFrame_OnLoad(frame)
frame:RegisterEvent("PLAYER_TARGET_CHANGED");
frame:RegisterEvent("UNIT_HEALTH");
frame:RegisterEvent("UNIT_MAXHEALTH");
frame:RegisterEvent("ADDON_LOADED");
end

function PlayerFrame_OnEvent(frame, event, arg1)
if (event == "ADDON_LOADED" and arg1 == "PlayerFrameHealthBar") then
frame:UnregisterEvent("ADDON_LOADED");
if (not PlayerFrameOptions) then
PlayerFrameOptions = {};
end
PlayerFrame_Reset()
elseif (event == "PLAYER_TARGET_CHANGED") then
PlayerFrame_Reset()
elseif (event == "UNIT_MAXHEALTH" and arg1 == "player") then
PlayerFrameHealthBar:SetMinMaxValues(0, UnitHealthMax("player"));
elseif (event == "UNIT_HEALTH" and arg1 == "player") then
PlayerFrameHealthBar:SetMinMaxValues(0, UnitHealthMax("player"));
end
end

function PlayerFrame_Reset()
PlayerFrameHealthBar:SetMinMaxValues(0, UnitHealthMax("player"));
PlayerFrameHealthBar:SetValue(UnitHealth("player"));
end


:smiley:

JaedxRapture
28-06-2007, 08:05 PM
Your event "UNIT_HEALTH" is fired whenever health changes. You have to use "SetValue" at UNIT_HEALTH. A working code would be:

function PlayerFrame_OnEvent(frame, event, arg1)
if event == "ADDON_LOADED" and arg1 == "PlayerFrameHealthBar" then
frame:UnregisterEvent("ADDON_LOADED")
if not PlayerFrameOptions then
PlayerFrameOptions = {}
end
PlayerFrame_Reset()
--elseif event == "PLAYER_TARGET_CHANGED" then
--PlayerFrame_Reset() -- Why are you resetting on target change? Remove this event entirely, including removing the "RegisterEvent" for it.
elseif event == "UNIT_MAXHEALTH" and arg1 == "player" then
PlayerFrame_Reset()
elseif event == "UNIT_HEALTH" and arg1 == "player" then
PlayerFrameHealthBar:SetValue(UnitHealth("player")) -- no need to constantly set the max value here
end
end

(Removed some unecessary syntax crap that's stripped away before processing anyway like semicolons and parenthesis.)

I'm out for the day. Won't be back till tomorrow for more help.

Edit: Made changes.

PvtFreddy
05-07-2007, 05:12 PM
Thanks, that worked but not for completely what I wanted. It moved the number of the health but not the gfx.

Anyway, Ive put that task aside for now, while I finished off other pieces of the mod. One thing I am stuck on if how you get the xml and lua files to read your own fonts.

I have a font that i want to put into the mod so I dont have to inherit the ons from the game. Whenever the I /reload I get an error saying font path not found. i've check the code and somewhere I am going wrong ofcourse but I cant find where.

Here is the code atm that I am looking at:

XML:

<FontString name="$parent_Text2" outline="THICK" text="">
<Anchors>
<Anchor point="BOTTOM">
<Offset>
<AbsDimension x="0" y="20"/>
</Offset>
</Anchor>
</Anchors>
</FontString>

This code is to change the name of the player I have targeted which I'll show you in the LUA part. I did have 'inherit="GameFontNormal"' there to but I got rid of it to replace it with my own.

LUA:

function FrostbiteHUD_OnLoad(self)
self:RegisterEvent("PLAYER_TARGET_CHANGED");
end

function FrostbiteHUD_OnEvent(self, event)
if (event == "PLAYER_TARGET_CHANGED") then
getglobal(self:GetName().."_Text2"):SetFont("Interface\Fonts\ComicBD.tff", 18));
getglobal(self:GetName().."_Text2"):SetText(UnitClass("target"));
getglobal(self:GetName().."_Text3"):SetText(UnitLevel("target"));
end

Thank you ever so much again, I know I may seem stupid with this but I'm trying to learn how to do this. :)