Author Topic: Player variables  (Read 3074 times)

Can someone tell me all the player 'variables' such as Health, Energy, etc.?
I'm trying to figure out what other depletable variables to add to a 'refresh' item.

Do a dump of a clients player object to see all the functions and variables you can use.
Type this in the console to do that:
findClientByName(enternamehere).player.dump();

For health:

.getDamageLevel()  (higher = less health, once this reaches the datablock's maxDamage value, the player dies)
Gets the current damage the player has taken.
.setDamageLevel(number)
Sets the current damage the player has taken.
.setHealth(number)  (event function, but can be used without events)
Sets the players health.
.addHealth(number)  (event function, but can be used without events)
Heals the player.
.getDatablock().maxDamage
This is the player's maximum health, do not change it.

For energy:

.getEnergyLevel()  (opposite of health, higher = more energy, can only be as high as the datablock's maxEnergy value, cannot use jets at 0, and cannot use certain features depending on other datablock values)
Gets the player's current energy.
.setEnergyLevel(number)
Sets the player's current energy.
.getDatablock().maxEnergy
Gets the player's maximum energy, do not change this.


I'm pretty sure there aren't any other 'depletable variables' aside from health and energy.

To heal both of these, would be as simple as:
%obj.setDamageLevel(0);
%obj.setEnergyLevel(%obj.getDatablock().maxEnergy);

what happens if you change the variables? would it throw up an error or just go with the new value?

what happens if you change the variables? would it throw up an error or just go with the new value?
It'll change it for every player using that datablock.

It'll change it for every player using that datablock.
So how would you change the maximum health for one player?

So how would you change the maximum health for one player?
This is what I'm wondering. Hmmm...

So how would you change the maximum health for one player?

Either you could decrease the damage taken a certain amount upon receiving damage, or you could use the following solution, which allows you to use .setHealth(value); and .setMaxHealth(value); on players.

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::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::addHealth( %this, %health )
{
return %this.setHealth( %this.health + %health );
}

function Player::getHealth( %this )
{
return %this.health;
}

function Player::getMaxHealth( %this )
{
return %this.maxHealth;
}

Either you could decrease the damage taken a certain amount upon receiving damage, or you could use the following solution, which allows you to use .setHealth(value); and .setMaxHealth(value); on players.
-snip-

You're a genius! Could that work for energy too?

Either you could decrease the damage taken a certain amount upon receiving damage, or you could use the following solution, which allows you to use .setHealth(value); and .setMaxHealth(value); on players.

-snip-

Hang on, I'm really new at this...
What code would I use to make it get the player's current max health, and set their new max health to their old max health+25?

You're a genius! Could that work for energy too?
Um, no not exactly.

The difference between health and energy is a lot of the health stuff is built into scripted functions where a lot of the energy stuff is built into the engine.

Um, no not exactly.

The difference between health and energy is a lot of the health stuff is built into scripted functions where a lot of the energy stuff is built into the engine.
Ah, ok. Hmmmm... That would be interesting if we ever managed to pull that off.

Hey Port, I think this code here would be pretty darn useful for RPGs, do you think we should release it sometime? I added a function for addMaxHealth (to simplify some stuff), and I'm trying to add events for it.
Never mind that, it's probably already been privately released.
« Last Edit: March 23, 2012, 03:05:14 PM by YourBuddyBill »

Um, no not exactly.

The difference between health and energy is a lot of the health stuff is built into scripted functions where a lot of the energy stuff is built into the engine.
But Jorgur has found a way to modify a single player's max health and max energy.

But Jorgur has found a way to modify a single player's max health and max energy.
That's true, he did! I should ask him about that...

Anyways, screw the 'releasing' part, unless I happen to release the thingy I'm using it for.

I added a function for addMaxHealth

The one I provided is a minimal version. The version I use normally allows for out-of-mini-game damage, shield power, invincibility and overheal. I could post that one too if you want it.

Hey Port, I think this code here would be pretty darn useful for RPGs, do you think we should release it sometime?

and I'm trying to add events for it.

Well, this could definitely be done, however this does overwrite a few default functions. It does an almost exact imitation of the default behavior, however it also causes the unfortunate side effect that any add-on which modifies damage functions executed before this will break.