Event to detect if battler is certain class [rpgmmv]

Hello! I'm looking for help in making an event that will detect if a battler (current battle party member) is of a certain class. Looking to do this on the field, not in battle. I'm ok with using script calls but am not sure of the syntax to do it with. I'm sure it would probably have to be done this way, but would need help with formatting. I'm more familiar with using "$game.Actor" but will have lots of actors and only want to check the current party, I remember ruby had commands like "$game_party.members[1]" however I do not know what to do in JS. Any help would be appricated! Again, I am hoping to look at each of the party members, and not just all the actors.

Problem: want an event to detect if battlers (active party members) are a certain class, and if they are to turn on a switch.

Desired result: When player enters an area, the event looks at battlers (active party members) and goes through them and if a certain class is active, a switch is turned on.

I think it would look something like

if battler 1 is class 6
switch on
else
if battler 2 is class 6
switch on
else
if battler 3 is class 6
switch on
else
if battler 4 is class 6
switch on
else
end

Again, thank you for your time, if I need to clarify anything, just let me know.
Try this in conditional branch: $gameActors.actor(actorId)._classId === id

It worked for me.

Script Call Shortcut:
Code:
var battler = [1,2,3,4];
var actorId = 0;
for (i = 0; i < battler.length; i++  ) {
    actorId = $gameParty.battleMembers()[battler[i] - 1].actorId();
    if (  $gameActors.actor(actorId)._classId === 6 && $gameActors.actor(actorId).isAlive() ) {
        $gameSwitches.setValue(18, true);
        break;
    }
}

The above code gets the actorIds of battlers 1,2,3,4 (or whichever battler no you're interested in), then checks their classId. eg. If you're only interested in 1,3,4, then change it to [1,3,4]
Hi there @dahlys , thank you for your response!

I appreciate your post but unfortunately am not looking to detect by actor id. I could do a conditional branch for every actor each time
I want to do this event, but am hoping to find a way to detect by just the current battle party members, so that I would just need 4 conditions and its only affected by the active party members.

for instance the actor script call looks at every individual actor, and would make for a lot of branches, but like with ruby, there was a script call to inspect party member 1,2,3,4 and only them. Making it a lot more clean cut. I don't know if MV has this but I'm hoping there is! 🙂 Thanks again.

You did teach me a new trick with the "actorIds = [1,2,3,4];" though , I had never used that before and will be able to make use of it in the future!
So if you have 8 party members, you only want to look at the first 4 in the lineup? What if only one of those has class 6, but they're dead - do you still want to turn on the switch?

Is it the same switch for all party members, or is there a specific switch for each actor, or for each party member?
Hello @Shaz , Yes I am looking to detect only the top/active party members, reserves would not be counted towards this. So yes, only the first 4 out of said 8 party members (the active ones). And that is a great question about being dead. If you happen to know how, I would love to also include a requirement of the party member being alive. But that is not a requirement and I could probably learn how to do that later. (thank you for offering)

and for the second question, yes the same switch for all members. Nothing special for different members, but thank you for asking.

If I may offer an example: an event that is parallel and will only activate the switch or self switch if an active party member has said class. Then a chest will appear, a passage becomes accessible, gathering spot activates, etc. If the active party members are not the class, the event just ends/erases.
Put this in a script call. It turns on switch 18 if any of the alive battle members has class 6, and turns it off if none of them have:

Code:
$gameSwitches.setValue(18, $gameParty.battleMembers().some(function(actor) { return actor.isAlive() && actor._classId === 6; }))

Of course, change 18 to whatever switch you actually want to use.
Hey, I updated the script call above for party members. It also checks if they're alive and lets you select which party member you want to check.
Shaz's code is faster if you're checking the whole active battler party.
Put this in a script call. ...
@Shaz Awesome this works after several tests, even including giving the class to a non active battle member and the event did not fire, just like requested, thank you for your time and professionalism, I will report the thread.

Hey, I updated ...
@dahlys That's amazing work, and I learned a lot from looking at your calls and syntax. Thank you for helping a poor sod out 🙂!
@HeathRiley Haha, thanks! I'm also a beginner at javascript syntax. I just learned .some from above...
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/event-to-detect-if-battler-is-certain-class-rpgmmv.84907/