Better Way To "Freeze" a Player's HP?

p0_boy

anti-kumbaya
Veteran
Joined
Mar 26, 2019
Messages
64
Reaction score
29
First Language
English
Primarily Uses
RMMV
I am working on a game that uses an ABS plugin, so all of the action takes place on-map.

There are points when I need to "freeze" the player's HP, and prevent it from suffering damage.

I am currently using a script that uses a variable to store the player's HP:

Code:
    var xActor = $gameActors.actor($.xActorID);
    $.xHPFreeze = xActor.hp;
and then a function that "maintains" the player's HP:

Code:
    $.fRHP = function() {
        if ($.xHPFreeze != undefined) {
            var cActorHP = $gameActors.actor($.xActorID);
            if (cActorHP.hp < $.xHPFreeze) {
                var xHP = ($.xHPFreeze - cActorHP.hp);
                cActorHP.gainHp(xHP);
            };
        };  
    };
It works, it just feels clunky.

Is there a better way to go about doing this?

Is it possible instead to attach a switch to the function that monitor's a player's HP, which can be enabled / disabled to allow / deny damage?

I am sorry if this is a basic question, I am still learning my way around RPG Maker.

Thanks!
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,610
Reaction score
5,080
First Language
English
Primarily Uses
RMVXA
I would probably overwrite or alias the executeHpDamage method (Game_Action.prototype.executeHpDamage), assuming that damage still flows through that method in your ABS. Have it check for whether the battler's HP should be frozen (you could do this with a database state, or by adding a new property to battlers in code), and if so, either exit the method early or have it skip the "target.gainHp(-value);" line.
 

p0_boy

anti-kumbaya
Veteran
Joined
Mar 26, 2019
Messages
64
Reaction score
29
First Language
English
Primarily Uses
RMMV
I would probably overwrite or alias the executeHpDamage method (Game_Action.prototype.executeHpDamage), assuming that damage still flows through that method in your ABS. Have it check for whether the battler's HP should be frozen (you could do this with a database state, or by adding a new property to battlers in code), and if so, either exit the method early or have it skip the "target.gainHp(-value);" line.
Wavelength- thank you for the advice / help!
 
Last edited:

p0_boy

anti-kumbaya
Veteran
Joined
Mar 26, 2019
Messages
64
Reaction score
29
First Language
English
Primarily Uses
RMMV
I would probably overwrite or alias the executeHpDamage method (Game_Action.prototype.executeHpDamage), assuming that damage still flows through that method in your ABS. Have it check for whether the battler's HP should be frozen (you could do this with a database state, or by adding a new property to battlers in code), and if so, either exit the method early or have it skip the "target.gainHp(-value);" line.
So, based on your advice- I wrote this, and tacked it on to the end of my plug-in:

Code:
    var execHpDamage = Game_Action.prototype.executeHpDamage;

    Game_Action.prototype.executeHpDamage = function(target,value) {
       
        if ($gameSwitches.value($.xSwitch) != true && target != $gameActors.actor($.xActorID)) {
            execHpDamage.call(this, target, value);
        };
   
    };
$.xSwitch is the switch that indicates whether the HP Freeze is on (true) or off (false).
$.xActorID is the ID of the Character who should have their HP Frozen.

It kinda works, except that when HP Freeze is on, nobody's HP receives damage!

Any clue on what I am doing wrong?

Thanks again for your help!
 
Last edited:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,610
Reaction score
5,080
First Language
English
Primarily Uses
RMVXA
I think there's a logic error in your check. You are asking for the Switch to be NOT True (thus False) and also for the Actor to NOT be the designated Frozen HP Battler, in order for any given battler to take damage. In other words, if either condition is not met, damage will not be taken. However, if you are simply setting one switch in your game to designate that freeze functionality is on or off, then any time this switch is set to True, the first part of the condition will not be satisfied, and the second part won't matter (because the entire condition will be false, therefore what's inside the branch won't run).

Changing the condition to the following might work:
Code:
if (!($gameSwitches.value($.xSwitch) === true && target === $gameActors.actor($.xActorID))) {
            execHpDamage.call(this, target, value);
        };
With all that being said, if there are multiple battlers that can ever go into this HP Freeze status, then I think a better approach would be to use a Database State (the syntax is: xxxxx.isStateAffected(stateId) where xxxxx is a reference to a battler object such as $gameActors.actor(2) ), or to define an extra Property for battlers (done easily by aliasing Game_Battler.prototype.initMembers - check that method to see the format used) to designate whether they're HP Frozen or not. The advantage of such an approach is that it's much more scalable: you'll never need to do anything on the back end if you decide that more battlers can enter this status, and you won't need to set a game-wide Switch based on whether any of those many battlers are in the status or not.
 

p0_boy

anti-kumbaya
Veteran
Joined
Mar 26, 2019
Messages
64
Reaction score
29
First Language
English
Primarily Uses
RMMV
Wavelength- thank you, so much!

I was going blind just looking over my script trying to figure out why it wasn't working.

I haven't looked at .isStateAffected yet, but for Game_Battler.prototype.initMembers- is defining an extra property as simple as just adding my own ._HpFrozen attribute (and then using that instead of the switch)?

For example:

Code:
var GB_initMembers = Game_Battler.prototype.initMembers;

Game_Battler.prototype.initMembers = function() {
   
    GB_initMembers.call(this);
   
    this._HpFrozen = false;
   
};
And then just, $gameActors.actor($.xActorID)._HpFrozen = true; and checking that instead of $.xSwitch in
Game_Action.prototype.executeHpDamage?

Many thanks!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Haired slime? Trying some different styles of art. Maybe I can make some resources with this new kind of painting.......
i love my game very much
Uh, I'm probably overthinking this, but I think that some of my music sounds kinda...bad?
The melodies are just sort of awkward, and don't flow.
I'm really not sure what to do. Why am I even worrying about this? I don't even have a battle system yet!
And the Lord said, let there be lighting effects! And there were lighting effects! And it was good...ish? Might tweak this some more.
Today was a day of good things! Thank you fate! I pray to the darkness that those that read this will enjoy a good day as well! Power to the gam mak.

Forum statistics

Threads
105,723
Messages
1,015,909
Members
137,401
Latest member
Rubbun
Top