WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   To Gello (https://www.wowinterface.com/forums/showthread.php?t=1444)

wow4me 08-06-05 06:08 AM

To Gello
 
Hi there, Gello its me again and i would like to ask for helk once more.

Here's the story.

If you use Mobhealth2 and Gypsy, when you fight PCs, their health is shown in the target frame.

I shifted to MG coz of the targetting issue that currently exists. Since Nurfed and MG both have a check to override the issue.

Now, i found out that these 2 addons do not show the PC health.

Since i cannot play around with those addons, i tried making a new addon similar to the class frame we made a few days back.

I looked at Mobhealth and i thought it was as simple as making a visible frame that wouls contain the returned health value. But i was wrong.

I guess since a lot of the addons use MobHealth as a dependency, i found out that if i use the frame name "MobHealthFrame" the frame is automatically hidden from view.

Would you be able to make an addon that makes a simple frame that contains the returned health from mobhealth2?

I can make the frame, coz you showed me how already (thanks again :))
but how do i make it so that it would call the mobhealth functions without copying all of the functions in mobhealth lua again.

can i simply put mobhealth.lua as the script file eben if my frame name isnt mobhealth?and copy the scripts portion of the original mobhealth xml?

thanks again!

Gello 08-06-05 07:30 AM

I don't have the mod installed, but from looking at it, you can get the current/max hp from calling:

current hp = MobHealth_GetTargetCurHP()
max hp = MobHealth_GetTargetMaxHP()

However to display it in realtime you'll want an OnUpdate that continually updates the hp. An easier method if this is just for personal use is to edit MobHealth2. Edit the MobHealth2.lua and MobHealth2.xml and change every "MobHealthFrame" to "MobHealthFrame2" or something that other mods won't try to hide.

But for a simple label that continually updates target hp:

MobHealth3.toc
## Interface: 1600
## Title: MobHealth3
## Notes: Puts MobHealth2-generated current/max hp on TargetFrame hp bar
## Dependencies: MobHealth2
MobHealth3.xml

MobHealth3.xml
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="MobHealth3.lua"/>
<Frame name="MobHealth3Frame" frameStrata="HIGH" toplevel="true" enableMouse="true" movable="true" parent="TargetFrame">
<Size>
<AbsDimension x="124" y="16"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT" relativeTo="TargetFrame" relativePoint="TOPLEFT">
<Offset>
<AbsDimension x="0" y="-40"/>
</Offset>
</Anchor>
</Anchors>
<Layers>
<Layer level="OVERLAY">
<FontString name="MobHealth3Text" inherits="NumberFontNormal" justifyH="CENTER" wraponspaces="false" text=""/>
</Layer>
</Layers>
<Scripts>
<OnUpdate>
MobHealth3_OnUpdate(arg1);
</OnUpdate>
</Scripts>
</Frame>
</Ui>

MobHealth3.lua
local update_timer = 0 -- time (in seconds) since last update
local update_speed = 1.0 -- time (in seconds) between updates

function MobHealth3_OnUpdate(arg1)

update_timer = update_timer + arg1
if update_timer > update_speed then
update_timer = 0
if UnitExists("target") then
MobHealth3Text:SetText(string.format("%d / %d",MobHealth_GetTargetCurHP(),MobHealth_GetTargetMaxHP()))
else
MobHealth3Text:SetText("")
end
end
end

--

Without MobHealth2 I'm not sure how the above will work. Every second (or however long you set update_speed to) if you have a target it will overlay a "hp/max" over the target's hp bar. You can move it around by setting the anchor offsets. Or put it in another frame and move the frame around, etc. parent="TargetFrame" causes this to hide when your target window hides.

wow4me 08-06-05 11:07 AM

Thanks again.

I thought about changing the time the addon updates itself to when something happens to the targets health. this way i thought it wouldnt fire each second but rather when my targets hpmoves.

the lua i made is as follows:
function MHealth_OnLoad ()
this:RegisterEvent("UNIT_HEALTH");
this:RegisterEvent("UNIT_HEALTHMAX");
-- this:RegisterEvent("VARIABLES_LOADED");
this:RegisterEvent("PLAYER_TARGET_CHANGED");
message ("Loaded");
end


function MHealth_OnEvent (event)
if (event == "UNIT_HEALTH" or event == "UNIT_HEALTHMAX" or event == "PLAYER_TARGET_CHANGED") then
MHealth_UpdateTargetHealth();
return;
end
end

function MHealth_UpdateTargetHealth ()
local c_hp = MobHealth_GetTargetCurHP();
local m_hp = MobHealth_GetTargetMaxHP();

if UnitExists("target") then
MHealthText:SetText(string.format("%d / %d",c_hp,m_hp));
else
MHealthText:SetText("None")
end
end

----------

The addon would load. also when i targetted a pig outside of org the health managed to appear on the bar

but whenever i click anything this error comes out
[string
"Interface\AddOns\mhealth\MHealth.lua"]:22:bad argument #2 to `format'
(number expected, got nil)

any idea?

the code you put up kept getting errors around the settext area, i think it was getting confused with all the ))) hehheh....so i did a workaround by assigning them to local variables.

Gello 08-06-05 03:55 PM

You have MobHealth2 installed also? I'm certain the two errors are related. Maybe it's returning nil instead of 0 with no information. I would experiment with the return values of MobHealth_GetTargetCurHP()

Try "MobHealth_GetTargetCurHP() or 0"

wow4me 08-06-05 06:13 PM

this is weird. they are coming up nil.

i placed a message in between to find out and the messagebox comes out clean so it is definitely nil BUT putting this statement

MHealthText:SetText(c_hp.." / "..m_hp)

works, what i mean is that MHealthText does show the currenthp/maxhp. but it always complains of concatenating a nil value which is m_hp.

how is it possible that c_hp and m_hp are nil but they display values in the text area?

wow4me 08-07-05 07:06 PM

bumping for help since im stumped....:)

Gello 08-07-05 08:21 PM

When concatenating (string..string) a variable that may be nil, two things to work around it:

1. wrap the variable in tostring() : s = "this is a test "..tostring(variable)
This will force nil values to a string "nil". Tables will become "table: 0E701648". etc

2. use the or operator : s = "this is a test "..(variable or "nil")
When you use (variable or "nil"), it will result in the variable if it has a value, or if it's nil, then the operand after the 'or'.

Does MobHealth2 return a value if the target isn't a mob? That among other things I couldn't tell right away.

wow4me 08-07-05 08:54 PM

Thanks gello, ill try that when i get home from work. Im sorry to keep bugging you on code but youve been such a great help.

Let me just say that i have no previous experience with regards to lua. Ive been a cobol coder, VB, javascript, Power Builder, Oracle , C and Pascal coder. Old school you might say. BUt now ive gone beyond the realm of coding into a totally different industry in that of banking. hehehe....so i appreciate the help in answering very noobish questions.

EDIT: catch up question. Do you have a lowdown on how the hell it is possible to get a nil value and yet the addon displays the results just fine?

Im thinking is it the fact that the function is an external function that when it is called from a separate addon it results in initially a nil value? But then again i cant resolve the fact that it returns the values correctly to be printed out in the textbox. Some weird things which i have never encountered before as a coder.

wow4me 08-08-05 10:42 AM

i think i found out a lil about this problem. It seems that when you choose a new target it doesnt look up the database because it results to nil but after hitting the mob once it then updates the values.

Beladona 08-08-05 12:01 PM

maybe try something like this:

Code:

function MHealth_OnLoad()
        this:RegisterEvent("UNIT_HEALTH");
        this:RegisterEvent("UNIT_MAXHEALTH");
        this:RegisterEvent("PLAYER_TARGET_CHANGED");
        message("Loaded");
end


function MHealth_OnEvent()
        if (event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH") and (arg1 == "target") then MHealth_OnUpdate(); end
        if (event == "PLAYER_TARGET_CHANGED") then MHealth_OnUpdate(); end
end

function MHealth_OnUpdate();
        local health = {};
        if UnitExists("target") then
                health.c = MobHealth_GetTargetCurHP();
                health.m = MobHealth_GetTargetMaxHP();
               
                if (health.c == nil) then health.c = 0;
                if (health.m == nil) then health.m = 0;
               
                health.t = string.format("%d / %d", health.c, health.m);
                MHealthText:SetText(health.t);
        else
                MHealthText:SetText("none");
        end
end

extra check for target in the OnEvent insures that the update doesn't get called on ALL health updates (like your own), only the mobs. Also put a check in there to see if the health returned nil, and it gets set to 0 if it did. Let me know if that helps at all...

wow4me 08-08-05 06:42 PM

thank you thank you :)

I will try that out as soon as i get home. Ill be at my fiancee's place tonight though so i might get to work at around 11:30ish PM. Ill update as soon as i can.

You guys are so helpful! I appreciate it very much.

Littlejohn 08-09-05 07:25 AM

Quote:

Originally Posted by Beladona
Code:

function MHealth_OnUpdate()
        local health = {};
        if UnitExists("target") then
                health.c = MobHealth_GetTargetCurHP();
                health.m = MobHealth_GetTargetMaxHP();


Why create a table? That will put pressure on the GC. I'd use the following:

Code:

function MHealth_OnUpdate()
        if UnitExists("target") then
                local health_c = MobHealth_GetTargetCurHP()
                local health_m = MobHealth_GetTargetMaxHP()


wow4me 08-09-05 09:52 PM

Hi bela and little. I tried the suggestions but they came up the same way.

Basically, we've gotten the addon to the point that it wont issue errors anymore because we captured the times when it results to nil.

What i experienced is that if you choose a new target, the health values will not show. But once yuo hit it, mobhealth starts its computations and or DB data extraction.

I think what is happening is that we cannot call the 2 functions outright because those are to calculate the health of your target as they are being hit.

I think we are missing the first step that of the initial value extraction from the DB.

:)

Thank you so much.....

Psychokitty 09-19-05 11:20 AM

I use recap and for some reason it gets real buggy on me.

Sometimes it will only show that my char (lvl60 hunter) only does 35 dps as well as others showing up with extremely low dps. Seems kinda weird due to the fact that I crit several times per combat. Yet when I ask a friend what he shows me at he says 150 dps or higher.

When my guild raids Molten Core we run recap for the whole instance to see if maybe someone needs help improving their damage output, but with my recap giving me very weird and low dps numbers it kinda defeats the purpose.

I have my recap set up exactly like the others have it but it still gets wacked after a fight or two.

Any suggestions?

Gello 09-19-05 11:48 AM

Recap seems to have massive problems for hunters in 1.7. Unfortunately the mod is semi-discontinued. I suspect the hunter's globalstrings for combat are different than they are for mage, priest or warrior.

The feature creep, lack of personal interest in the mod, discomfort with its direction and use, and mostly a desire to play more and work on other more technically interesting mods has kinda left it abandoned sorry. :(

If anyone wants to pick it up they are more than welcome.

I plan to resurrect it someday. But it will be without logging what other people in the group/raid are doing.

btw in raids, the radius of information for combat around you shrinks dramatically. In an unpopulated area you can see combat from across the room. In a Magmadar fight you'll be lucky to get a handful of people recorded due to spacing and stuff.


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

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