Author Topic: Player Max Health  (Read 1225 times)

Is there a way to make a function that changes a players max health? Something like this.

Code: [Select]
package damage_package
{
function Armor::onAdd( %this, %obj )
{
%obj.maxHealth = %this.maxDamage;
%obj.health = %this.maxDamage;
}

function Armor::onNewDataBlock( %this, %obj )
{
parent::onNewDataBlock( %this, %obj );

%obj.maxHealth = %this.maxDamage;

if ( !strLen( %obj.health ) )
{
%obj.health = %this.maxDamage;
}

if ( %obj.health > %obj.maxHealth )
{
%obj.health = %obj.maxHealth;
}
}

function Player::kill( %this, %damageType )
{
if ( getSimTime() - %this.spawnTime < $Game::PlayerInvulnerabilityTime )
{
return false;
}

if ( !strLen( %damageType ) )
{
%damageType = $DamageType::Self Delete;
}

%this.damage( %this, %this.getHackPosition(), %this.getDataBlock().maxDamage * %this.getSize(), %damageType, "body", true );
}

function Player::damage( %this, %sourceObject, %position, %damage, %damageType, %damageLoc, %parent )
{
if ( %parent )
{
parent::damage( %this, %sourceObject, %position, %damage * %this.getSize(), %damageType, %damageLoc );
return;
}

if ( getSimTime() - %this.spawnTime < $Game::PlayerInvulnerabilityTime )
{
return;
}

if ( !%this.health )
{
return;
}

%mod = 1 - ( ( %this.health - %damage ) / %this.maxHealth );

%this.playPain();
%this.setDamageFlash( %mod );

if ( %mod >= 2 / 3 )
{
%this.emote( painHighImage, true );
}
else if ( %mod >= 1 / 3 )
{
%this.emote( painMidImage, true );
}
else
{
%this.emote( painLowImage, true );
}

%this.health -= %damage;

if ( %this.health < 0 )
{
%this.health = 0;
}

if ( %this.health > %this.maxHealth )
{
%this.health = %this.maxHealth;
}

if ( !%this.health )
{
parent::damage( %this, %sourceObject, %position, ( %this.getDataBlock().maxDamage ) * %this.getSize(), %damageType, %damageLoc, true );
}
}
};

function Player::getSize( %this )
{
return getWord( %this.getScale(), 2 );
}

activatePackage( "damage_package" );

function Player::setHealth( %this, %health )
{
if ( !strLen( %health ) )
{
return false;
}

if ( %health < 0 )
{
%health = 0;
}

if ( %health > %this.maxHealth )
{
%health = %this.maxHealth;
}

%this.health = %health;

if ( !%this.health )
{
%this.kill();
}

return true;
}

function Player::CRPG_setMaxHealth( %this, %maxHealth )
{
if ( !strLen( %maxHealth ) || %maxHealth <= 0 )
{
return false;
}

%this.maxHealth = %maxHealth;

if ( %this.health > %this.maxHealth )
{
%this.health = %this.maxHealth;
}

return true;
}

function Player::CRPG_addHealth( %this, %health )
{
return %this.setHealth( %this.health + %health );
}

Health is a property of the datablock; you can't change a players health without creating a new datablock with that amount of health.
But there are a number of things you can do to make it appear as though you have more or less health; You could scale damage based off the amount of "health" a player has:

Code: [Select]
package fakeMaxHP
{
    function Player::damage(this,%obj,%pos,%damage,%damageType)
    {
        %damage = %damage / (%player.fakeMaxHP / 100);
        Parent::damage(%this,%obj,%pos,%damage,%damageType);
    }
};
ActivatePackage(fakeMaxHP);

Wait, where did you get that code from? That looks 100% like an older version of my custom damage system.

It actually is Port :D I just tweaked it so it would be compatible with my stuff.