RMMV How to link a passive state to a slot position?

MaxLionheart

Veteran
Veteran
Joined
Aug 23, 2015
Messages
112
Reaction score
34
First Language
French
Hey everyone!

In my game, the slot position of a character is important and I need each slot position to have a certain passive state applied to the character in that slot. For example, the character in the slot position 1 needs to have state x, and the character in the slot position 4 needs to have state y. Also, the player can switch characters during battle, using Yanfly's ActorPartySwitch.

For example: if Bob is my party leader (in position 1) and has the state x, when he switches with Mike (who's currently on the bench), I need Mike to have the state x when he enters. And if Bob rejoins the fight later but is placed in the slot 4, he should have state y and not state x on him.

I thought about placing in the character's notetag a conditional passive state based on its slot ID. However, I don't know to code it.

In Yanfly's AutoPassiveStates, he allows us to create custom conditions. The example he gives is:

<Custom Passive Condition>
if (user.hp / user.mhp <= 0.25) {
condition = true;
} else {
condition = false;
}
</Custom Passive Condition>

So my question is: is there a way to make a custom passive condition based on slot id (the position of the character in the party)? If so, I could give each character 4 passive states (one for each of the 4 positions in the active party), and each state would only activate if the character is in the correct position (so only one state at a time would be active, and that state would follow the characters switching during battle).

I thought about using rows since I can apply a passive state to each row, however characters that are swapped in during the battle do not necessarily arrive at the same row as the one that just left.

Thank you in advance!!


Edit: I found this to figure out what actor is in what position.

$gameParty.members()[0]._actorId - will return the Id of the actor that is the first party member.

$gameParty.members()[1]._actorId - it will return the id of the actor that is the second party member.

It's not what I need, but it shows it's possible. I tried to figure out how to make a condition like "if character is in position 1", but I don't know how to code in java so I haven't been able to find something yet.
 
Last edited:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
604
Reaction score
315
First Language
German
Primarily Uses
Hey there,

As for the condition, you can check a battlers position in their party with
user.index()
which gives you the party position (starting at 0) or null if the battler is not in the party.
(So for example if (user.index() === 0) would check if the user is the first party member)


Edit: Overlooked that the plugin already updates passive states when the party changes, the plugin below is redundant in this case.
By default, passive states are only updated when the users stats or traits might have changed. If you use other conditions for your passive states they might only show up with a delay since the game will not blindly refresh them.

This usually should not be an issue, but if you want to update your actors immediately when your party members change you can do that with a plugin:

Code:
/*:
* @plugindesc Refresh party members when party changes
*/
(function() {
   
    var lastAddActor = Game_Party.prototype.addActor;
    Game_Party.prototype.addActor = function(actorId) {
        lastAddActor.call(this, actorId);
        this.onPartyChange();
    };
   
    var lastRemoveActor = Game_Party.prototype.removeActor;
    Game_Party.prototype.removeActor = function(actorId) {
        lastRemoveActor.call(this, actorId);
        this.onPartyChange();
    };
   
    var lastSwapOrder = Game_Party.prototype.swapOrder;
    Game_Party.prototype.swapOrder = function(index1, index2) {
        lastSwapOrder.call(this, index1, index2);
        this.onPartyChange();
    };
   
    var lastOnBattleStart = Game_Party.prototype.onBattleStart;
    Game_Party.prototype.onBattleStart = function() {
        lastOnBattleStart.call(this);
        this.onPartyChange();
    };
   
    var lastOnBattleEnd = Game_Party.prototype.onBattleEnd;
    Game_Party.prototype.onBattleEnd = function() {
        lastOnBattleEnd.call(this);
        this.onPartyChange();
    };
   
    Game_Party.prototype.onPartyChange = function() {
        this.allMembers().forEach(member => member.refresh());
    };

})();
 
Last edited:

MaxLionheart

Veteran
Veteran
Joined
Aug 23, 2015
Messages
112
Reaction score
34
First Language
French
Wow thank you very much for your help!

I'm trying to test what you just said. I created a status with the following in the note box (I want the first character to have a passive physical taunt):

<Custom Passive Condition>
if (user.index() === 0) {
condition = true;
} else {
condition = false;
}
</Custom Passive Condition>

<Physical Taunt>

And as I soon as I hit new game or that I load a game, the game crashes, and it shows:

1615221006948.png

Do you have any idea what I'm doing wrong? It's not your plugin that causes the problem, as enabling or disabling it still makes the game crash. It's also not the addition of the "Physical Taunt" that makes the game crash, as I tried with and without it.

Thanks!
 
Last edited:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
604
Reaction score
315
First Language
German
Primarily Uses
As for the error message I stumbled across this post which suggests to update Yanflys plugins.
Although the condition seem to work just fine for me. You should be able to see the stack info where the error came from if you press F8 for the developer console.
 

MaxLionheart

Veteran
Veteran
Joined
Aug 23, 2015
Messages
112
Reaction score
34
First Language
French
Thanks for the tip. I've been searching for nearly an hour now, and I've found the culprit... It seems that there is some bad interraction between the custom state we created and the plugin YEP_PartySystem (the one required to have another key plugin, YEP_X_ActorPartySwitch). When I turn off the PartySystem plugin (and ActorPartySwitch, which is dependent on the first one), everything works fine (except that obviously, I can't change my party members during the fight!).

Otherwise, when all plugins are activated and the game crashes, the log shows this:

1615258092853.png

(It says 580 errors, but it seems to be always the same thing repeating...)

Now I don't know why it talks about the CoreEngine plugin or the YEP_Z_ActionBegining plugin, because only turning on/off the Party system plugin make a difference. If I turn off YEP_Z_ActionBegining, I'll get the same errors, but the log will say that another plugin is problematic.

I also updated all my plugins just to make sure the crash wasn't caused by an old version (and I bought Yanfly's plugins, so technically I should have access to the last versions Yanfly made).

It's starting to get way more complicated than I anticipated... If you have any idea, I'd appreciate to hear your thoughts... but otherwise I'll try thinking of an alternative...

Anyway, thanks again!
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
604
Reaction score
315
First Language
German
Primarily Uses
I would have to guess here since I can't look up the plugin right now, but if the problem is somehow related to user.index() and the edit from the opening post worked, you could try that instead:

Edit: I found this to figure out what actor is in what position.

$gameParty.members()[0]._actorId - will return the Id of the actor that is the first party member.

$gameParty.members()[1]._actorId - it will return the id of the actor that is the second party member.

The easiest way would probably be to check if the party member and the "user" are identical:
if ($gameParty.members()[0] === user)
Alternatively, you can of course compare any property of your party members with those of the user too:
if ($gameParty.members()[0]._actorId === user._actorId)
if ($gameParty.members()[0].actorId() === user.actorId())



These should normally have the same effect as the previous method (at least for the players party)

Edit:
Now I don't know why it talks about the CoreEngine plugin or the YEP_Z_ActionBegining plugin, because only turning on/off the Party system plugin make a difference. If I turn off YEP_Z_ActionBegining, I'll get the same errors, but the log will say that another plugin is problematic.
The same function (Yanfly.Util.displayError) is provided by several of Yanflys plugins, so if you disable one source, the game ends up using another.
According to Yanflys website the problem is that the function used in older plugin versions is no longer compatible with a newer MV version (because of the missing isDevToolsOpen function).
 
Last edited:

MaxLionheart

Veteran
Veteran
Joined
Aug 23, 2015
Messages
112
Reaction score
34
First Language
French
Thanks again for your input.

I tried the three lines you told me and each provoked the same crash as yesterday.

Is it possible that we just encountered a bug in one of Yanfly's plugins that was never reported to him before? Hmmm...

Anyway, what I'm really trying to achieve is to have the party member in 1st position to have a physical taunt on him, and the party member in the 4th position to have a magical taunt. And if these characters swap out of the battle, the character coming in must have the buff relevant to his position.

EDIT: I've just found a way to make this work! (Don't ask why this solution works and the one discussed earlier doesn't, I have no clue!)

I created two states (one for position 1 and another for position 4) like this:

<Custom Row Condition>
if ($gameParty.members()[0] === user) {
condition = true;
} else {
condition = false;
}
</Custom Row Condition>

(I changed 0 for 3 for the state for position 4)

Then, in the plugin "Row Formation", I gave the two buffs I created to row 1 (all my characters are on row 1).

And now it works! Character in position 1 will always the state for its position, and thanks to the plugin you made in post 2, the state will be applied to the new guy coming in. And since everybody is always on row 1 and the player can't change that, there won't be any confusion based on the rows.

So yeah, it works now :) Pretty happy!

Thank you so much for your help Another Fen!
 
Last edited:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
604
Reaction score
315
First Language
German
Primarily Uses
Small correction: I overlooked that the passive states plugin already updates state conditions when the party changes, so the plugin from post 2 is absolutely redundant in this case.

---

I know you are satisfied with the result you found, but one more theory about the error:
Generally:
- Actors are only created when they are first used ($gameActors.actor(id) is called)
- $gameParty only saves the ids of its members and uses $gameActors.actor(id) to look up the actual actors when necessary

The problem arises if $gameActors.actor(id) is called while that actor is created.
In your example, what may have happened is that the party contained an actor that has not been "touched" yet. So when it finally is created:
1) $gameActors.actor realizes that the actor has not been created yet and creates a new actor
2) While the actor is created the game will check its passive state conditions
3) Passive state conditions refer to $gameParty.members
4) $gameParty.members calls $gameActors.actor(id) to look up the party members
5) Because the actor creation is not yet finished, jump to 1)
This will repeat until the game shuts it down with an error.

I don't know if this is the case (although it was in some other scenarios in the past), you might be able to fix that by making sure the actor is created before adding them to the party:
Code:
/*:
* @plugindesc Create Actors when adding them to the party
*/
(function() {
 
    var lastAddActor = Game_Party.prototype.addActor;
    Game_Party.prototype.addActor = function(actorId) {
        $gameActors.actor(actorId);  // Create actor if not yet transpired
        lastAddActor.call(this, actorId);
    };

})();
Although this may or may not work depending on how the party is changed.


Another way might be using a switch in your passive state condition that you check and activate at the start and deactivate at the end. This may not be the best solution, but it could catch repeated checks of your passive condition before the first check was finished.


Glad to hear it works now. :)
 
Last edited:

MaxLionheart

Veteran
Veteran
Joined
Aug 23, 2015
Messages
112
Reaction score
34
First Language
French
I appreciate your enthusiasm to solve this mystery :)

I gave your plugin a try and recreated the state that made the game crashed, and unfortunately, the crash still occured. One thing I noticed though is that when I launched the game, before creating a new game or loading a file, the console already warned me of two errors (before, there was none until I loaded a file or created a game). The console showed:


Uncaught ReferenceError: GameParty is not defined
at test.js:6
at test.js:12

(I named your plugin test)

Not sure what to do with that, but I thought you might interested to know.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
604
Reaction score
315
First Language
German
Primarily Uses
Oh, woops, that's because I messed up the naming... :)
It should spell Game_Party instead, fixed the code above.

Still no guarantee it works for your specific setup unfortunately.

Edit: Alternatively one could try to catch not yet created actors in the passive state condition itself, for example:

<Custom Passive Condition>
if (user.isActor() && !$gameActors._data[user.actorId()]) {
condition = false;
else if (user.index() === 0) {
condition = true;
} else {
condition = false;
}
</Custom Passive Condition>

Edit2: Used wrong notetag, but the code should be good. Might not be compatible with actor cloning plugins though.
 
Last edited:

MaxLionheart

Veteran
Veteran
Joined
Aug 23, 2015
Messages
112
Reaction score
34
First Language
French
Ah! You nailed it! Your solution in the edit of your last post worked without any additional plugin, and the console showed no error.

Good job! :)
 

Latest Threads

Latest Profile Posts

e8K8iHS.png

I need to focus on some other stuff for now, so i won't be working on the other expressions for a while, but i wanted to share anyway <3
She also has a name now: Devali, or Dev(i) for short :)
So I think that almost four years after ghosting the forums is a good time to come back
finally redesigned one of the major antagonist of my game, Pro... aka Prometheus.

Forum statistics

Threads
110,316
Messages
1,052,300
Members
143,355
Latest member
richosamson8945
Top