PDA

View Full Version : Idea: RegenCalc - Estimates the amount of time...


jwwpua
12-17-2004, 08:24 AM
RegenCalc - Estimates the amount of time until your health/mana will be full.

Anyone interested in coding this?

Necromancyr
12-17-2004, 03:41 PM
I'm pretty sure there's a function hidden somewhere in WoW or in Cosmos that gets you the regen rate of health (It shows the points per second) so...all it should be is (Guessing it's called regen rate):


function HealTimeLeft (person)
Health=UnitHealth(person);
HealthMax=UnitHealthMax(person);
RegenRate=UnitRegen(person);

HealthToHeal = (HealthMax-Health);
SecToHeal = (HealthToHeal / RegenRate);

return SecToHeal;

end;


That function should work if you pass it things like player, player1, player2, etc. You could also just slam everything together like this:


function HealTimeLeft (person)
TimeToHeal=(((UnitHealth(person)-UnitHealthMax(person))/(UnitRegen(person)));
return TimeToHeal;
end;


I dont exactly know how Lua parses stuff or does operations but that would work too unless LUA can't handle it. Also, the 'UnitRegen' is a function I made up. No idea what it's called.

Lastly, I don't currently know how to display stuff. Hehe. I can try to take a look into shardcount and see if I can use the stuff in there to do it. This is just a basic idea. SHould theoretically be easy to do.

Also, I may be nuts...but I think this is built into the Clock addon when you mouseover the clock. (just looking at the code for clock and it references health count downs, etc.)

jwwpua
12-17-2004, 11:07 PM
Hey thanks for the reply. You're right that the health and mana regen rate are calculated by the Clock addon. I guess we just need to know the variable names for the health and mana regen rate.

Are "UnitHealth()" and "UnitHealthMax()" built in functions? And would 'person' have to be your player's name? If so, what's the variable that stores your own name?

Also why did you mention player1, player2, etc? Wouldn't it always just be your player's name?

sarf
12-17-2004, 11:14 PM
UnitHealth("player") and UnitHealthMax("player") would work. Built-in Blizzard functions. :)

Sarf
---
My friend Winnie is a procrastinator. He didn't get his birthmark until he was eight years old.

jwwpua
12-18-2004, 12:06 AM
Thanks sarf!

Necromancyr, let me know if you get it working please! thanks

Necromancyr
12-18-2004, 12:35 AM
I'm going to try over the weekend and early next week. This is something that I think I can handle as a first 'releaseable' project, but I have to get down how to display it. That and decode some stuff in clock.

Necromancyr
12-20-2004, 03:35 AM
Ok...I HAVE a mod I can use to do this now (there's a HP/MANA regen ticker mod). ANd it displays the way I think it should so I'm basically tweaking/changing things.

The main issue is - and maybe I'm missing something, but this is what ALL the code that shows regen per tick - that there's not actually a regen per tick function. Basically, people record the 'starting health' and the 'health this tick' and 'health last tick' and base the regen on that.

I have to figure out a way to do it with the variables and all. It shouldn't be that hard...I just need to really sit and look at it (havent had the time...that and the way I was going to do it I tossed out the window).

So...I'm basically trying to figure out how to do addition and subtraction with only multiplication and division to do it with...if you catch my drift.

sarf
12-20-2004, 11:07 AM
OK.

-- in OnLoad somewhere
this:RegisterEvent("UNIT_HEALTH");

-- in OnEvent somewhere
if ( event == "UNIT_HEALTH" ) then
if ( arg1 == "player" ) then
CalculateTimeToFullHealth();
end
end

OldHealth = 0;

function CalculateTimeToFullHealth()
local curHealth = UnitHealth("player");
local maxHealth = UnitHealthMax("player");
local text = "";
if ( not OldHealth ) then
OldHealth = curHealth;
return;
end
if ( curHealth == maxHealth ) then
text = "At full health";
else
local diff = curHealth-OldHealth;
if ( diff > 0 ) then
local ticksToFullHealth = math.ceil((UnitHealthMax("player")-curHealth)/diff);
local secondsToFullHealth = ticksToFullHealth;
text = format("Seconds to full health: %d", secondsToFullHealth);
OldHealth = curHealth;
elseif(diff == 0 ) then
-- don't change the text
else
local ticksToDeath = math.floor(curHealth/diff);
local secondsToDeath = ticksToDeath;
text = format("Seconds to death: %d", secondsToDeath);
OldHealth = curHealth;
end
end
if ( ( text ) and ( strlen(text) > 0 ) ) then
DoSomethingWithText(text);
end
end

function DoSomethingWithText(text)
-- SomeUIWidget:SetText(text);
end

Sarf
---
"Man is a Religious Animal. Man is the only Religious Animal. He is the only animal that has the True Religion -- several of them. He is the only animal that loves his neighbor as himself and cuts his throat if his theology isn't straight. He has made a graveyard of the globe in trying his honest best to smooth his brother's path to happiness and heaven.... The higher animals have no religion. And we are told that they are going to be left out in the Hereafter. I wonder why? It seems questionable taste." - Mark Twain

Necromancyr
12-20-2004, 02:39 PM
Well, SURE, you could go and do it the easy way. :) Hehe. In my own defense, I was having a hard time figuring out how to do a running average. That being said, I think I may have just figured it out but I'm still not 100% sure I won't overflow something or cause a memory leak.

Basically, add the change in health to a variable every time a change is made to health and increment a counter. Divide the sum variable by the counter and you have the average change.

I could reset the counter variable when the change in health is zero, the problem being I dont know if the OnHealthChange event passes that last 'zero' change or not. If it doesn't then you hit the memory leak/gigantic variable/etc.

Other idea I had was to reset it on combat start, combat end, login, and 5 seconds after no change. The 5 seconds after no change I have absolutely no idea how to do. The others should be simply on events.

(BTW, I have a tendency to make things unnnecessarily hard :), in case you havent noticed.)

Necromancyr
12-22-2004, 11:31 PM
So I coded up an addon..and..well..it doesnt load. Test functions dont load. I tried to paste in (as in...use instead of my mod) the HelloWorld addon from the Custom UI forum...that wouldnt load. I cant figure out whats up.

I'm doing Christmas presents with the fiance tonight, so...maybe later/tomorrow morning I'll put what I wrote up in a zip file on my server and if someone can look at it, that owuld be great. I cannot figure out wtf is up and why it's not working.

sarf
12-22-2004, 11:42 PM
http://www.fukt.bth.se/~k/wow/scripts/BaseMod/

Has most things you need to "start up" an AddOn.

Sarf
---
Abortion kills, but so does McDonalds.

Necromancyr
12-23-2004, 12:44 AM
Sarf, thats the thing. UNless theres some naming convention I dont know about...this thing should load. After I'm done with the christmas stuff with the fiance I'll post something tonight (late...like...2am eastern late)

Necromancyr
12-23-2004, 03:32 AM
Since WoW is down (AGAIN!), heres what I tried to use:
http://www.wam.umd.edu/~razambon/RegenTimer.zip

THat was in WowDir\Interface\AddOn\RegenTimer.

I also tried http://www.wam.umd.edu/~razambon/Regeneration.zip. (Similar directory, but Addon\Regeneration instead) - I did this in case RegenTimer was reserved or something. This Zip is also basically a copy of the HelloWorld example from the UI forum over at the WoW site. I just changed the names to reference the files I was using.


ANy ideas on what might be the problem? I can't access ANY functions from the scripts/addons using /script functionname();

I get a 'calling a nil global' error or something to that effect.