Is there a way to make a function that changes a players max health? Something like this.
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 );
}