Jathan

Veteran
Veteran
Joined
Jun 10, 2020
Messages
46
Reaction score
22
First Language
English
Primarily Uses
RMMV
I tried asking for this before on my last account but I don't think anyone really understood what I was asking back then so if you need any clarification feel free to ask.

Basically what I need is a plug-in that allows me to create a second but also separate death or "K.O." state. The second one would be caused and cured in different ways than the standard variation. This second one should be caused when a character's MP hits 0.

So in summation what I need is a plug-in that adds a secondary K.O. State that only takes effect when the character's MP hits 0 (we'll call this Unconscious). It should be separate from the standard K.O State (we'll call this death) which takes effect when HP hits 0. The goal here is to have two separate K.O. states that are caused and cured in different ways. For example Death would be cured by say, a stimulant, and Unconscious would be cured by, for example smelling salts or something like that.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
618
Reaction score
260
First Language
English
Primarily Uses
RMMV
This isn't a full plugin and I might have missed an important detail, plus it's untested, but... I think it should work.

JavaScript:
(function(){
    const STATE = 10; // replace with the ID of your MP death state
    const old_isAllDead = Game_Unit.prototype.isAllDead;
    Game_Unit.prototype.isAllDead = function() {
        return old_isAllDead.call(this) || this.aliveMembers().every(function(who) {
            return who.isStateAffected(STATE);
        });
    };
    const old_refresh = Game_Battler.prototype.refresh;
    Game_Battler.prototype.refresh = function() {
        Game_BattlerBase.prototype.refresh.call(this);
        if (this.mp === 0) {
            this.addState(STATE);
        } else {
            this.removeState(STATE);
        }
    };
})();
 

Jathan

Veteran
Veteran
Joined
Jun 10, 2020
Messages
46
Reaction score
22
First Language
English
Primarily Uses
RMMV

Thanks I'll get to testing it out right away and let you know if it works properly.
 

Jathan

Veteran
Veteran
Joined
Jun 10, 2020
Messages
46
Reaction score
22
First Language
English
Primarily Uses
RMMV
@Solar_Flare Okay so I put that plug-in in and maybe I just screwed up the writing or something but now anytime I test a battle phase it starts the battle and immediately goes to the victory scene. I made sure to turn off all other plug-ins before applying the new plug-in so I'm not sure what happened.

It's most likely a result of previous codes overlapping so I'm going to try testing it with a newer project real quick.
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
618
Reaction score
260
First Language
English
Primarily Uses
RMMV
Perhaps that's because of the bug I spotted after posting which would've caused all enemies with no MP to insta-die.

I had a chance to do further testing since I posted it, so how about you try this version? Now with proper plugin parameters.

JavaScript:
/*:
@plugindesc Make additional states count for party death
@author Solar Flare Games

@param deathStates
@text Death States
@desc A list of states that will be considered for determining whether the party is defeated.
@type state[]
@default []

@param lowMpState
@text Low MP State
@desc A state that will be added when a character's MP reaches 0. It won't count for party death by default.
@type state
@default 0

@help

This plugin allows you to set additional states to count for the purpose of
determining defeat. If every member of the party or troop is afflicted by
one of these states, they will be considered defeated.

Additionally you can set a state to be added when MP becomes zero. If you wish,
you can also set this state as a death state, so that characters and enemies
are defeated when their MP is exhausted. Characters with no MP will never be
afflicted by this state.

*/

Utils.parseRecursive = function(val) {
    try {
        if(!Array.isArray(val) && typeof(val) !== 'object') {
            val = JSON.parse(val);
        }
        if(Array.isArray(val)) {
            for(var i = 0; i < val.length; i++) {
                val[i] = Utils.parseRecursive(val[i]);
            }
        } else if(typeof(val) == 'object') {
            for(var key in val) {
                if(val.hasOwnProperty(key)) {
                    val[key] = Utils.parseRecursive(val[key]);
                }
            }
        }
        return val;
    } catch(e) {
        return val;
    }
};

(function(){
    const params = PluginManager.parameters('SFG_AltDeathState');
    const deathStates = Utils.parseRecursive(params.deathStates);
    const lowMpState = Number(params.lowMpState) || 0;
  


    const old_isAllDead = Game_Unit.prototype.isAllDead;
    Game_Unit.prototype.isAllDead = function() {
        return old_isAllDead.call(this) || this.aliveMembers().every(function(who) {
            return deathStates.some(state => who.isStateAffected(state));
        });
    };

    const old_refresh = Game_Battler.prototype.refresh;
    Game_Battler.prototype.refresh = function() {
        old_refresh.call(this);
        if(this.mmp > 0 && this.mp === 0) {
            this.addState(lowMpState);
        } else {
            this.removeState(lowMpState);
        }
    };
})();

Call the file SFG_AltDeathState.js.

For your use case, add the same state to both plugin parameters. You don't need to look up the ID, as the plugin parameter will show the state selector. You can also add other game over states if you want, for example if you had a petrification state.

Terms:

  • Usable in commercial or non-commercial games
  • Feel free to modify it to your needs
  • No need to credit me in your game credits, but don't remove me from the Author field.
 
Last edited:

Jathan

Veteran
Veteran
Joined
Jun 10, 2020
Messages
46
Reaction score
22
First Language
English
Primarily Uses
RMMV
@Solar_Flare

So I finally got around to testing the new file and for some reason the actors won't fall after hitting 0 MP. I put the state in both parameters like you said.
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
618
Reaction score
260
First Language
English
Primarily Uses
RMMV
Just noting (in case anyone else grabbed this) that I edited in a few bugfixes to the code.
 

Jathan

Veteran
Veteran
Joined
Jun 10, 2020
Messages
46
Reaction score
22
First Language
English
Primarily Uses
RMMV
@Solar_Flare Okay so they died now but for some reason the item I made to cure it isn't working they just die all over again. I'm thinking maybe it's not healing any MP so I'll try to fix that first but it it's weird because it's no different from the item that heals the standard death state except it's balanced towards MP instead. It's probably a hardwired thing

Edit: I just edited the cure I made for the MP death to also cure MP by 10% of their Max MP and it still doesn't help. For some reason once they die from losing all their MP curing it seems impossible.
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
618
Reaction score
260
First Language
English
Primarily Uses
RMMV
Hmm. The plugin is set to remove the state when their MP is no longer 0... I'll investigate why this might not be working, but I imagine setting your cure item to also remove the state should work even without a further fix on my part.
 

Jathan

Veteran
Veteran
Joined
Jun 10, 2020
Messages
46
Reaction score
22
First Language
English
Primarily Uses
RMMV
I figured it out. It works fine now. Thanks for the help man.
 

Latest Threads

Latest Posts

Latest Profile Posts

Changed my avatar, goodbye Alan Sugar, hello George Carlin (one of my favorite human beings ever)
If you still don't subscribe our Polish channel please consider it :)
1.png
Who wants to see my review of the worst star wars movie? This movie has all the excitement of being on Jury Duty of the most boring case ever about trade negotiations.
A lot to learn to make a game. Can I handle it?
I've been working on status effects since last thursday, and today I finished the core mechanic of Zombie, Teleport, Curse and Recall. Zombie and Curse are lacking a few things to make them complete atm. Teleport though is the "HAHA" spell for some of my mobs, but can "NOPE" at them with Recall.

Forum statistics

Threads
115,169
Messages
1,087,780
Members
149,712
Latest member
Darksynergy
Top