Author Topic: Trying to make a health regeneration script  (Read 1449 times)

Now it's spamming an error in the console:

Lol what the forget did I type data for?
That should be damage

%this.player.setDamageLevel(%health);

Now it just spams showing me dying and displaying Health: 1 and then after about 8 times my screen messes up like when someone deletes your player object via console/eval.

thats because setDamageLevels sets the amount of damage, not the health. So 100 would kill you
0 would be 100 health.

The bottomprint still flickers and I want the health to regenerate slowly like .5 seconds per 1 health.
The health does regenerate, but it does it instantly to 100.  That's why I want it to have a delay.

How hasn't this been solved yet?

Post your code guy, i'll help you.

Code: [Select]
package HealthRegeneration
{
    function gameConnection::onClientEnterGame(%this)
    {
        parent::onClientEnterGame(%this);
        %this.HealthRegenerationBar();
    }

    function gameConnection::onClientLeaveGame(%this)
    {
        cancel(%this.HealthRegenerationBar);
        parent::onClientLeaveGame(%this);
    }
};
activatepackage(HealthRegeneration);

function gameConnection::HealthRegenerationBar(%this)
{
if(isObject(%this.player))
{
cancel(%this.healthRegenerationTick);
%health = %this.player.getDatablock().maxDamage - %this.player.getDamageLevel();
if(%health <= 99)
{
%health = %health + 1;
}
%this.player.setDamageLevel(0);
commandToClient(%this,'BottomPrint',"Health: "@%health);
echo(%health);
%this.healthRegenerationTick = %this.schedule(200,"HealthRegenerationBar");
}
}

The bottomprint still flickers and I want the health to regenerate slowly like .5 seconds per 1 health.
The health does regenerate, but it does it instantly to 100.  That's why I want it to have a delay.

- Move the cancel and the schedule outside the if. Cancel before, schedule after
- Change the setDataLevel argument to 100 - %health
« Last Edit: September 01, 2012, 03:08:45 PM by Headcrab Zombie »

- Change the setDataLevel argument to 100 - %health
Actually use %this.player.getDatablock().maxDamage - %health

Actually use %this.player.getDatablock().maxDamage - %health
Yes, actually, do this. Also change the if condition to if(%health < %this.player.getDatablock().maxDamage




Actually, I think you should change so it reflects the fact that health is actually represented as damage; check if it's greater than zero, and decrement it if it's not, then set damage level to that

Something like this:

Code: [Select]
function gameConnection::HealthRegenerationBar(%this)
{
cancel(%this.healthRegenerationTick);
if(isObject(%this.player))
{
%maxDamage = %this.player.getDatablock().maxDamage;
%damage = %this.player.getDamageLevel();
if(%damage > 0)
%this.player.setDamageLevel(%damage--;);
commandToClient(%this,'BottomPrint',"Health: "@ %maxDamage - %damage @ "/" @ %maxDamage);
}
%this.healthRegenerationTick = %this.schedule(200,"HealthRegenerationBar");
}
I'd say get this working, then add in different recovery rates based on different damage amounts
« Last Edit: September 01, 2012, 06:56:04 PM by Headcrab Zombie »

So, something like this?

Code: [Select]
package HealthRegeneration
{
    function gameConnection::onClientEnterGame(%this)
    {
        parent::onClientEnterGame(%this);
        %this.HealthRegenerationBar();
    }

    function gameConnection::onClientLeaveGame(%this)
    {
        cancel(%this.HealthRegenerationBar);
        parent::onClientLeaveGame(%this);
    }
};
activatepackage(HealthRegeneration);

function gameConnection::HealthRegenerationBar(%this)
{
cancel(%this.healthRegenerationTick);
if(isObject(%this.player))
{
%health = %this.player.getDatablock().maxDamage - %this.player.getDamageLevel();
%maxDamage = %this.player.getDatablock().maxDamage;
%damage = %maxDamage - %this.player.getDamageLevel();
if(%health < 99)
{
%damage -= 1;
}
%this.player.setDamageLevel(%this.player.getDatablock().maxDamage - %health);
commandToClient(%this,'BottomPrint',"Health: "@%health);
}
%this.healthRegenerationTick = %this.schedule(200,"HealthRegenerationBar");
}

You changed half of the references to %damage back to %health, but left the other ones
That won't work.


Just try what I gave you and see if it does anything wrong

You changed half of the references to %damage back to %health, but left the other ones
That won't work.


Just try what I gave you and see if it does anything wrong
I don't see anything where %health equals to in your code.

I changed all the references to health to damage
I forgot to change one though, I edited my previous post with updated code

Is there any way to stop the bottomprint from flickering?
I don't have any addons that interfere with the bottomprint.


*EDIT: How to make the health regenerate slower?
« Last Edit: September 01, 2012, 08:05:35 PM by tkepahama »