check if class is member of party

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
Hello,
I need to check if a special class (lets say fighter) is member of the party. Not just if a special actor has the class fighter, but if in general a fighter is part of the group.

Anybody knows how to implement this?
Thanks!
 

Llareian

Jack of All Trades, Master of None
Veteran
Joined
Jan 26, 2017
Messages
604
Reaction score
1,421
First Language
English
Primarily Uses
RMMV
You need to use a script call, for example, inside an event conditional branch "script" box.

If you're checking this outside combat,
$gameParty.members().some(function(member){return member.isClass($dataClasses[X])});

If you're checking inside combat,
$gameParty.battleMembers().some(function(member){return member.isClass($dataClasses[X])});

If you're checking either inside or outside combat, and you only want to check if there's an ALIVE party member with that class,
$gameParty.aliveMembers().some(function(member){return member.isClass($dataClasses[X])});

Replace X with the classID for fighter.
 

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
Thanks for your quick answer! It works perfect. In my case it's important that the party member is alive. Thanks also for that point.
 

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
Guys,
there is another points where I need your help.

I took @Llareian formula to check if there is class-ID 2 in the group and if this char is alive. Next step is I have to get the name of this char.
I tried it like this:
script.png

It starts with Llareins formula
then I have a loop which adds 1 to var n each time
then the formula checks if actor number n class-ID = 2 (the number of the class I'm looking for)
if it's 2 or n is equal or greater then 5 (I only have maximum of 4 party members) the loop breaks
finally a text message asks if party member n should smash the wall

In praxis it doesnt work. The text message doesnt show the name of the char but only [n].

What could be the reason for this error? Thanks for your help?
 

Gamefall Team

Nebula Games Leader
Veteran
Joined
Jan 10, 2017
Messages
348
Reaction score
473
First Language
Italian
Primarily Uses
RMMZ
@freebooter I think that your error is this:
You write $dataClasses[0002], that is wrong because this statement will return an undefined value.
The right one is $dataClasses[2] without any 0.
 

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
@Gamefall Team: nope, that wasn't the problem. I changed it, but error still exists.
I checked the variable n and it is always 5 when the loop breaks. Means that something goes wrong when var Actor is checked with $game_actors[n].class.id
But I cannot figure out what is wrong ...
 

Gamefall Team

Nebula Games Leader
Veteran
Joined
Jan 10, 2017
Messages
348
Reaction score
473
First Language
Italian
Primarily Uses
RMMZ
@freebooter Uh, I didn't notice that, you should type it this way:

Code:
$gameActors.actor($gameVariables.value(varId))._classId
On your side, it should be:
$gameActors.actor($gameVariables.value(9))._classId
This is the JS code.
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
@freebooter what are you trying to do with the name once you have it? when you are asking for help, be clear about what it is you are trying to accomplish. we need to know what you want to do with the name when you have it so we know how to store it; when we know this information, we can provide the best solution for acquiring and storing the information.
 

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
Thanks @Gamefall Team , now I get the correct number.

@dbchest , once I have the name I want to use it in a text message. But this still doesnt work. I tried it with:

\N[9] breaks down the wall

"9" is the number of the variable where the number of the actor is stored. But all I get is an empty space where there should be the name of the actor. I also tried it with the name of the variable, which is "n":

\N[n] breaks down the wall

But then, instead of the name, I get just: [n]

Any ideas what went wrong?
Thanks for help!
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
@freebooter \N[actor id] is used to display the name of an actor, based off their id in the database. when processing these escape codes within the message window, the system compares regular expressions to find matches. this means it is impossible to specify a variable id within \N[actor id] and hope to retrieve the variable's value. instead, we will make use of \V[variable id], which is used for doing just that. instead of storing and referencing ids, we will store the actor's name itself into the variable and display it with \V[variable id].

use a conditional to determine whether a party member is the desired class:
Code:
$gameParty.members().filter(function(actor) { return actor.isClass($dataClasses[classId]) }).length > 0;
if this condition is true, store the actor's name into the variable you want, using the script option within the Control Variables command:
Code:
$gameParty.members().filter(function(actor) { return actor.isClass($dataClasses[classId]) })[0].name();
when you are ready to display the actor's name, simply place that variable's id into your message window's \V[variable id] reference.

the world keeps spinning. :D
 

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
Thanks, works great!

But as I not only have to know if a class is member of the party but also if this member is alive (as no dead member can take an action), I took this formula:

$gameParty.aliveMembers().some(function(member){return member.isClass($dataClasses[X])});

Where you proposed that formula:

$gameParty.members().filter(function(actor) { return actor.isClass($dataClasses[classId]) }).length > 0;

Can you explain to me the difference between those formulas besides the alive-part? Thanks.
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
i may be wrong, but i think actors who faint during battle are revived to 1HP at the battle's end. if this is true and you are performing this conditional via event commands, then you should not need to explicitly reference alive members; members should be fine. BUT! since the alive members function will perform that additional check as a reassurance, it is probably the best option for you.

the difference between the .filter and .some functions is that the .filter function will return an array containing the elements which return as true. the .some function is essentially the true / false value of the conditional and will return true as long as one element passed the test. if you want to optimize the code for your particular situation, consider the following:

conditional
Code:
$gameParty.aliveMembers().some(function(actor) { return actor.isClass($dataClasses[classId]) });
assigning the actor name to a variable
Code:
$gameParty.aliveMembers().filter(function(actor) { return actor.isClass($dataClasses[classId]) })[0].name();
 

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
ok, so that means with .filter I could get the exact number of party members who have the classID I'm looking for, where .some just tells me if there is at least one?

Edit: And btw what is the difference between "actor" and "member". I see you used both of these terms.
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
pretty much, but you would have to add .length to the end of the script to return the quantity. .filter is going to return an array containing all the elements. calling .length on that array will tell you how many there are inside it.
 

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
I see, thanks for explaining.

I have a follow-up question to the things we already solved:
In the example we had before "Breaking Walls" was a passiv skill. So it was ok just to check if there is a fighter in the group and whats his name (always the first fighter in the row would break a door). But what if "Breaking Walls" is an active skill, means the player has to activate the skill in the menu (not just pushing the action-button when the sprite stands near a breakable wall)?

If "Breaking Wall" is an active skill and there are more than one fighter in the group, I had to know whom of them activated the skill. Is there a way to get the name of the "active" actor, or something like that? Thanks.
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
Code:
$gameParty.menuActor();
this will return the last actor to be selected within the menu processing.

using the code above in conjunction with the functions we discussed earlier, you can easily access the same relevant information from the latest menu actor.
 
Last edited:

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
ok, again I used var "n" and tried to get the name of the last active actor, means the one who activated the skill.
Therefore I set
n = $gameParty.aliveMembers().filter(function(actor) { return $gameParty.menuActor(); })[0].name();

Using \V[9] (9 is the number of var "n") in the text message I get the name of the actor. But I always get the name of actor number 1. Also if the skill was activated by actor 2
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
there is no need to filter through the entire party. just set the variable to the latest menu actor. perform your conditional to ensure there is at least one alive actor in the party for the desired class, but instead of grabbing the first actor in the party using the .filter function we discussed before, use the latest menu actor instead:

replace this:
Code:
$gameParty.aliveMembers().filter(function(actor) { return actor.isClass($dataClasses[classId]) })[0].name();
with this:
Code:
$gameParty.menuActor().name();
 

freebooter

Veteran
Veteran
Joined
Oct 20, 2017
Messages
104
Reaction score
5
First Language
German
Primarily Uses
RMMV
Thanks, this is all new to me, but I think I get it ... slowly.

I implemented it without the conditional because if the guy uses the skill, he has to be alive.
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
perfect. i am glad we got you there.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,975
Members
137,563
Latest member
cexojow
Top