Class Specific Events

Hey guys. New here, so I apologise if this ends up in the wrong section.


So I'm wondering if RMVXA allows class specific events... since at some point of the game, I allow the players to choose whichever class that they want, and I also have events that only involve that specific class (mainly ability gain through events). I know how to target specific actors, but since I don't know which actor will end up as which class, I can't make class specific events that way...


If I'm not mistaken, there's a long way to do this; conditional branches allow me to check the class of a specific actor, but repeating this for every single event will probably be a hassle... is there a shorter way to do this?


I hope I'm clear enough on what my problem is. 🙁  Can't seem to find a better phrasing for everything. If you guys need clarification feel free to reply.
In the script part of the conditional branch:


$game_party.members.any? {|actor| actor.class_id == 5}


replacing 5 with the class you're interested in.


This condition will be true if ANY of your current party members is class 5.
Thank you, but what I want the event to do is not only check if there's a specific class in that party, but also the event to only target the actor with that class. Is that possible?
You can use Control Variables, again with the Script part, and a command like this:


v = $game_party.members.select {|actor| actor.class_id == 5}; v.empty ? 0 : v[0]


This will set a variable to the actor id if there is an actor with that class.  If there is no actor with that class, it returns 0.  If there are several actors with that class, it will return the id of the first one.


Then you can use the variable in conditional branches.


If there is code you want to run for a number of events, you can put the common code into a common event, and then just call the common event from the map events.  That will save you running the same logic in each event.
You can use Control Variables, again with the Script part, and a command like this:


v = $game_party.members.select {|actor| actor.class_id == 5}; v.empty ? 0 : v[0]


This will set a variable to the actor id if there is an actor with that class.  If there is no actor with that class, it returns 0.  If there are several actors with that class, it will return the id of the first one.


Then you can use the variable in conditional branches.


If there is code you want to run for a number of events, you can put the common code into a common event, and then just call the common event from the map events.  That will save you running the same logic in each event.

Ugh, I'm horrible at coding. I think it might help if I explain what I need a bit clearer...


See, my class system works like this: For a character to gain skills, they have to talk to an NPC, go through a trial, and if they succeed, they'll get the skill. Of course, I don't want them to be taught the wrong skills, so I need an event to do this:


1) Automatic check if actors are a particular class


2) Remove all party members except for that specific actor (to transfer them to another map for the trial)


If this is going to take too much script, I'll have to play around with switches, which I think is also going to be a lot of work...


Also, if I use the script you gave me, how do I set the variable ID?
Control Variables.  
Control Variables.  

Okay well, I'm trying it out but the script doesn't fit into the variable's script space...
Then you'll probably have to use the script call box on event page 3. Do $game_variables[x] =  $game_party.members.select {|actor| actor.class_id == 5}; v.empty ? 0 : v[0]
That also probably won't fit on a single line.  Make sure the line breaks come after the { symbol so it knows there's more to come, or it'll crash.
That also probably won't fit on a single line.  Make sure the line breaks come after the { symbol so it knows there's more to come, or it'll crash.
Code:
$game_variables[x] =  $game_party.members.select {
|actor| actor.class_id == 5
}; 
v.empty ? 0 : v[0]

Is this correct? I apologise for all the noob questions, I don't have the faintest idea when it comes to scripting. I'm imitating the line break from scripts I've seen before.
that won't work, because v isn't defined. 


If you have the newest version of Ace that gives you a longer line in the script box, do this:

Code:
v = $game_party.members.select {|a| a.class_id == 5}
$game_variables[x] = v.empty? ? 0 : v[0]

If you can't fit that on 2 lines (you have the older version with the smaller script box), copy and paste it in, then show a screenshot of what it looks like so I have an idea where to put the breaks.

Original thread: https://forums.rpgmakerweb.com/threads/class-specific-events.67472/