| Blockland Forums > Modification Help |
| Player variables |
| << < (2/4) > >> |
| jes00:
--- Quote from: Chrono on March 23, 2012, 03:50:52 AM ---It'll change it for every player using that datablock. --- End quote --- So how would you change the maximum health for one player? |
| YourBuddyBill:
--- Quote from: jes00 on March 23, 2012, 06:56:06 AM ---So how would you change the maximum health for one player? --- End quote --- This is what I'm wondering. Hmmm... |
| Port:
--- Quote from: jes00 on March 23, 2012, 06:56:06 AM ---So how would you change the maximum health for one player? --- End quote --- 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: ---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; } --- End code --- |
| YourBuddyBill:
--- Quote from: Port on March 23, 2012, 09:47:47 AM ---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- --- End quote --- You're a genius! Could that work for energy too? |
| YourBuddyBill:
--- Quote from: Port on March 23, 2012, 09:47:47 AM ---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- --- End quote --- 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? |
| Navigation |
| Message Index |
| Next page |
| Previous page |