gheed

Warper
Member
Joined
Nov 25, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
What would be the easiest way to go about limiting the number of battles an actor can participate in?
The way it works is that when you go into the dungeon you have x amount of BP(battle points or whatever you want to call it). After a battle is resolved(win or run away) you lose 1BP and if a character has 0BP then that character will complain about being tired and leave the active party until you leave the dungeon.

So far I set up a post battle common event which checks for character being in the party and if so then it reduces MP by one(I don't use MP for skills or anything else so I decided to use it for BP instead), sets a variable to actor's MP, checks if it's zero and if so displays a message and after that I'm stuck.
I thought that Yanfly's Party System plugin would help but after looking at the plugin commands I realized that it does not. It doesn't have commands to put an actor into the reserve party and while it does have lock commands, to prevent a party member from being moved around, the locked character has to be in the active party so even if I could move the tired character into the reserve there'd be no way for me to make sure that the player doesn't just swap the character back in.

If there's a plugin or some other way to do what I want to do(put characters in reserve and lock them in there until their MP is above 0) I'd appreciate some help, hope it's not too difficult to implement. Thanks in advance.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,861
Reaction score
14,512
First Language
English
Primarily Uses
RMMV

I've moved this thread to Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.



Doesn't the plugin let you use plugin commands to move actors to different locations in the party?
 

gheed

Warper
Member
Joined
Nov 25, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
Oh, my bad. I thought it was more of a general question which is why I posted it in the general MV forum thing. I'm all good with a solution not involving any plugins, I mentioned the party system one when going through what I tried to do as a reference.

I thought so too but sadly it only has commands to lock actors(has to be in active party, can't move around), unlock, require(has to be in the party but can be moved around), max party size and hiding/enabling party menu buttons. There is one extension plugin which doesn't seem to have commands I need and is about switching mid battle which is different in the first place.

Now that I think about it I guess I could set up a switch for every character that should be in the party and simply remove those characters when their BP drops to zero and re-add them after the dungeon is over. Should work in theory but doesn't seem like the best way to do it so I'd rather do that as a last resort. Though I'd have to check somehow if the party even has party members because I could see the party being empty, after everyone runs out of BP, and the player just walking around with an empty event, not sure how I'd do that.
 
Last edited:

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
164
Reaction score
189
First Language
Danish
Primarily Uses
RMMV
I thought that Yanfly's Party System plugin would help but after looking at the plugin commands I realized that it does not. It doesn't have commands to put an actor into the reserve party and while it does have lock commands, to prevent a party member from being moved around, the locked character has to be in the active party so even if I could move the tired character into the reserve there'd be no way for me to make sure that the player doesn't just swap the character back in.
I am pretty sure that a locked character does not have to be in the active party. However, it is true that the plugin does not have a way to put an actor in to the reserve party. You can do that with the following script if you use Yanfly's Party System:
Code:
var ACTOR_ID = 1;
if($gameParty._battleMembers.contains(ACTOR_ID)){
   var index = $gameParty._battleMembers.indexOf(ACTOR_ID);
   $gameParty._battleMembers[index] = 0;
}

As you mentioned yourself you have to check if the party even has members otherwise you could run into bugs. You can use the following script to check if the battle party is empty:
Code:
$gameParty._battleMembers.reduce((sum, e) => sum + e) == 0
 

gheed

Warper
Member
Joined
Nov 25, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
I am pretty sure that a locked character does not have to be in the active party. However, it is true that the plugin does not have a way to put an actor in to the reserve party. You can do that with the following script if you use Yanfly's Party System:
Code:
var ACTOR_ID = 1;
if($gameParty._battleMembers.contains(ACTOR_ID)){
   var index = $gameParty._battleMembers.indexOf(ACTOR_ID);
   $gameParty._battleMembers[index] = 0;
}

As you mentioned yourself you have to check if the party even has members otherwise you could run into bugs. You can use the following script to check if the battle party is empty:
Code:
$gameParty._battleMembers.reduce((sum, e) => sum + e) == 0
Thanks. True, you can lock an actor in reserve and it works. When looking at plugin's description it said
* Locked Actors cannot be moved out of their current
position and must be in the party.
so that's why I thought so but I'm glad it works.

Code that removes actors from the party seems to work pretty well.
Messed around a bit and ended up with this, which seems to go through all the IDs which is nice and compact. Is it possible to somehow implement the i variable into the plugin call to lock actors too? I don't mind doing it manually, not like I have hundreds of actors but still.
JavaScript:
var i;
for (i = 1; i < 15; i++) {
  if($gameParty._battleMembers.contains(i)){
    $gameActors.actor(i).gainMp(-1);
    if($gameActors.actor(i).mp == 0){
        var index = $gameParty._battleMembers.indexOf(i);
        $gameParty._battleMembers[index] = 0;
        }
    }
}

The second code, which checks for party members, gives me an error about = > being an unexpected token though.
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
164
Reaction score
189
First Language
Danish
Primarily Uses
RMMV
The code to lock an actor is the following:
Code:
$gameParty.lockActor(actorId)
So your modified version would look like this:
Code:
for (var i = 1; i < 15; i++) {
   if($gameParty._battleMembers.contains(i)){
      $gameActors.actor(i).gainMp(-1);
      if($gameActors.actor(i).mp == 0){
         var index = $gameParty._battleMembers.indexOf(i);
         $gameParty._battleMembers[index] = 0;
         $gameParty.lockActor(i);
      }
   }
}

The second code, which checks for party members, gives me an error about = > being an unexpected token though.
I guess you are using an old version of MV then? The following should do the same:

Code:
$gameParty._battleMembers.reduce(function(sum, e) { return sum + e }) == 0
 

gheed

Warper
Member
Joined
Nov 25, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
The code to lock an actor is the following:
Code:
$gameParty.lockActor(actorId)
So your modified version would look like this:
Code:
for (var i = 1; i < 15; i++) {
   if($gameParty._battleMembers.contains(i)){
      $gameActors.actor(i).gainMp(-1);
      if($gameActors.actor(i).mp == 0){
         var index = $gameParty._battleMembers.indexOf(i);
         $gameParty._battleMembers[index] = 0;
         $gameParty.lockActor(i);
      }
   }
}


I guess you are using an old version of MV then? The following should do the same:

Code:
$gameParty._battleMembers.reduce(function(sum, e) { return sum + e }) == 0
Thank you very much! It's really nice being able to do all that stuff with a single common event with 12+ lines of code as opposed to checking everything manually with multiple common events which is what I initially did.

In case someone comes across this thread looking to do a similar thing then you need to get Yanfly's post battle common event plugin and party system and put those two pieces of code in a common event that runs after each battle. Script for the first code and conditional for the second one(they can be together in a single common event but you could also run another common event from this one if you want to separate them for some reason).
For the first code you will want to replace "i < 15" with number of actors you have +1(so if you have 16 actors then put in 17) and the rest is automatic. For the second code it's just a conditional and from there you do game over or teleport to town or whatever.

You can also make a common event to unlock everyone later on with this(replace 15 with how many actors you got +1, like above)
JavaScript:
for (var i = 1; i < 15; i++) {
        $gameActors.actor(i)._locked = false;
}

If for some reason you can't use yanfly plugins you could event it which will take longer with something like this:
1. every battle gives an invisible state that does nothing to your entire party
2. parallel event checks every actor for that state. if present on an actor then remove that state, reduce mp by one, assign mp to a variable, check if it's zero and if so remove from the party. You can use another variable for actor Id so that you can copy paste and change less stuff( like when you change mp you can use a variable for the actor id that way you won't have to change it later). You'll still have to change some stuff though for each iteration.
3. after checking everyone run "$gameParty.members().length === 0" as a conditional. It will continue if everyone is gone from the party
4. once you leave the dungeon, run common event to add your actors back(make sure not to re-initialize so that they don't reset to level 1) and restore their hp/mp. You'll need a switch for every actor who should be in the party and add back based on that.
It's quite tedious but if you have no other choice I hope this helps. I might've forgotten some finer details but I think I got the general outline more or less so from there it shouldn't be difficult to come up with stuff.
 

Latest Threads

Latest Posts

Latest Profile Posts

Working on animation. Trying to see if I can apply it meaningfully to my games!
ddwk.png

working on the sprite for Devali <3
My Game Development Livestream

Of course, so, someone had covid at work today and I was exposed to them, so, I'm stuck at home for...TWO WEEKS!

Forum statistics

Threads
110,371
Messages
1,052,714
Members
143,405
Latest member
Balthor
Top