RMMV Is there a way to check and count states on a target, without using a million if conditions?

TheTitan99

Veteran
Veteran
Joined
Nov 2, 2015
Messages
217
Reaction score
99
First Language
English
Primarily Uses
RMMV
So, I've made this simple little function:

Code:
//Check conditions.
//Returns a value. The higher the number, the more positive status effects are n it. Lower means more negative effects.
Titan_CheckConditions = function(b) {
    var n = 0;

    //Positive states
    if(b.isStateAffected(42))
        n = n + 1;

    if(b.isStateAffected(43))
        n = n + 2;

    if(b.isStateAffected(44))
        n = n + 1;

    if(b.isStateAffected(45))
        n = n + 2;

    //Negative stats
    if(b.isStateAffected(52))
        n = n - 1;

    if(b.isStateAffected(53))
        n = n - 2;

    if(b.isStateAffected(54))
        n = n - 1;

    if(b.isStateAffected(55))
        n = n - 2;

    //Positive conditions
    if(b.isStateAffected(62))
        n = n + 1;

    if(b.isStateAffected(63))
        n = n + 1;

    if(b.isStateAffected(72))
        n = n + 1;

    if(b.isStateAffected(73))
        n = n + 2;

    //Negative conditions
    if(b.isStateAffected(82))
        n = n - 1;

    if(b.isStateAffected(83))
        n = n - 1;

    if(b.isStateAffected(91))
        n = n - 1;

    if(b.isStateAffected(94))
        n = n - 3;

    if(b.isStateAffected(95))
        n = n - 2;

    return n;
}


Basically, bad states lower the returned number, and good states raise the number. This is useful for, say, enemy AIs, as they can now check to see if they should dispel targets. You don't wanna dispel a poisoned ally if it has a million positive states on it after all!

The only thing is, this code feels super bad. It works, but I feel there's gotta be a better way to do this than a mountain of if conditions! Like, there's gotta be simple loops or something, right?

I think this is the right board for this question.
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
973
Reaction score
566
First Language
Poland
Primarily Uses
RMMV
@TheTitan99
Code:
var positiveStates = []; //put positive states ids
var negativeStates = []; //put negative states ids
for (var i = 0; i <= positiveStates - 1; i++){
    n += 1;
}

for (var i = 0; i <= positiveStates - 1; i++){
    n -= 1;
}

But then, if you want a different values for different states, then

Code:
var positiveStates = []; //put positive states ids
var negativeStates = []; //put negative states ids
for (var i = 0; i <= positiveStates - 1; i++){
    if (b.isStateAffected(positiveStates[i]){
        n += Number($dataStates[positiveStates[i]].meta["buff"]);
    }
}

for (var i = 0; i <= negativeStates - 1; i++){
    if (b.isStateAffected(negativeStates[i]){
        n -= Number($dataStates[positiveStates[i]].meta["debuff"]);
    }
}

and place in your states notetags: https://prnt.sc/xo8lnx

Actually you can stick to the only one notetag, but using two will give you further informations about boosts.
Because of my age I leave that way a hint for myself in case I forgot what function/state etc do
 
Last edited:

TheTitan99

Veteran
Veteran
Joined
Nov 2, 2015
Messages
217
Reaction score
99
First Language
English
Primarily Uses
RMMV
Thank you! There were a few typos in that code, but after fixing those, it works like a charm! Much, much cleaner code.
 

Latest Threads

Latest Profile Posts

Do you like to practice level design? I do hahahaha! It's not from a specific game, it's just some tests...Fase 1.png
I really need a better indicator of where you can jump up and down though I feel... otherwise I like how this turned out for the first part of the first dungeon of the game.
@Shaz needs to make a website for his plugins. (it can be done easily for free with google sites.) I can't find a database of them anywhere!
Dion2.jpg

testing #2

Forum statistics

Threads
109,127
Messages
1,042,377
Members
141,628
Latest member
KaithFoyer
Top