Party Member Script to check for class X and level X?

Greetings all,

I want to run a couple conditional branches to check if any party member is class X, if so then check if that specific party member is level X, if neither is true do nothing. I need to use a script call to accomplish this.

I can not use any event options or scripts that rely on actors because I am using another script that allows copied actors. I am attempting to create a common event that will transform a copied actor by changing their appearance and class. Because they are copied I have no way of knowing their actual actor ID during game play.

Any information is appreciated, and I thank you for everyone's time

EDIT: Both of the following plugins copy actors and at the moment I have not decided which to use. It all depends on this event I am creating.

http://himeworks.com/2016/01/instance-actors/ or https://forums.rpgmakerweb.com/index.php?threads/capture-enemies.57771/
something like this? The first example would be if any actor in your party is classId X AND level X
JavaScript:
for (let i = 0; i < $gameParty._actors.length; i++) {
  if ($gameActors.actor($gameParty._actors[i])._classId == X && $gameActors.actor($gameParty._actors[i]._level == X)) {
    // do whatever you want here
  }
}

the example below would be if any actor is classId X OR level X, i'm not entirely sure which you wanted so here's both.

JavaScript:
for (let i = 0; i < $gameParty._actors.length; i++) {
  if ($gameActors.actor($gameParty._actors[i])._classId == X || $gameActors.actor($gameParty._actors[i]._level == X)) {
    //do whatever you want here
  }
}

I assume its the first one you wanted, i wouldn't know of a method to handle this without scripting it.. hope this helps :]

If you're unsure of how to script what you need done I could probably finish it up for you with more info

I guess you could also do a set of conditional branches... like 4 of em and set them to this script for each party member.

JavaScript:
Conditional Branch for party member 1
$gameActors.actor($gameParty._actors[0])._classId == X && $gameActors.actor($gameParty._actors[0])._level == X

Conditional Branch for party member 2
$gameActors.actor($gameParty._actors[1])._classId == X && $gameActors.actor($gameParty._actors[1])._level == X

Conditional Branch for party member 3
$gameActors.actor($gameParty._actors[2])._classId == X && $gameActors.actor($gameParty._actors[2])._level == X

Conditional Branch for party member 4
$gameActors.actor($gameParty._actors[3])._classId == X && $gameActors.actor($gameParty._actors[3])._level == X

if these don't work then i might need to see the plugin you're using, never dealt with that one before
@Ritter Thanks for your quick reply and all the work you have already put into the answer, The first script you posted is what I was after, you mentioned finishing the script if I was unsure how to proceed from here?

If you're unsure of how to script what you need done I could probably finish it up for you with more info

I was planning on using Hime's Level Up Events Plugin to activate a common event that checked the actors for a specific class and level when they leveled up, but the plugin uses notetags on the actors and they are not copied onto the copied actors. If the notetags could be applied to class instead everything would be fine.
Is there a way you can call your script whenever any actor levels up, heal and restore their HP and MP fully and then check the class ID and Level with the script you provided above. If both class and level are true using the conditional branches of the common event I would alter their face set and class (my game is front-view battles with no followers) so no need to alter their sprites. I then tint the screen dark and toggle between two pictures for a few times display a message and return the screens tint to normal. The tinted screen and pictures are all cosmetic and is how I convey to the player that the actor is transforming.

This may be more than you bargained for but I posted my common event below and maybe is will be possible for you to script the whole thing and run it when actors level up? I couldn't find a way to have the whole event show in a single window so I have multiple attachments below but they are in numerical order. I hope that is not too annoying.

I think it would be easier to tweak the Level Up Plugin to allow notetags on class but I have very little knowledge on scripting and I could be wrong.

Here is a link to Himes Level Up Event Plugin: http://himeworks.com/2015/10/level-up-events/

I have also edited my first post to display links for plugins that copy actors, I only plan on using one of them but which depends on this script and my events.

Thank you again for your time, if this turns out to be too much I understand, just let me know and thank you for everything!

EDIT: So I thought I could copy and paste the code into a conditional branch script call but it looks like I have to type it all into it instead. That is fine, but there is only a single line, do I type the whole thing onto the line as is? I am questioning the placement of the " } " symbols.
Well if editing the level up common event plugin works for you thats an easy one to do, if this doesn't work i can look into another method.

Open the plugin using a text editor, notepad or notepad++ will do the trick and replace the function Game_Actor.prototype.levelUpEventId with the code below. should do the trick. This should allow you to put the note tag in class instead of actor.

JavaScript:
  /* Returns level up event ID. Lazy-load as needed */
  Game_Actor.prototype.levelUpEventId = function() {
    if (this._levelUpEventId !== undefined) {
      return this._levelUpEventId;
    }
    this._levelUpEventId = 0;
    var res = $.Regex.exec($dataClasses[this.actor().classId].note);
    if (res) {
      this._levelUpEventId = Math.floor(res[1]);
    }
    return this._levelUpEventId;
  }
This edit would make it so whatever class your actor currently is when it levels up it will execute the common event inside that classes note tag.

EDIT: So I thought I could copy and paste the code into a conditional branch script call but it looks like I have to type it all into it instead. That is fine, but there is only a single line, do I type the whole thing onto the line as is? I am questioning the placement of the " } " symbols.

if you were going to do that you should use the conditional branch code i showed you in my first post as i'm pretty sure you can't do a loop in a conditional branch condition. it might be worthwhile to test this edit to the level up common event plugin first.
if you were going to do that you should use the conditional branch code i showed you in my first post as i'm pretty sure you can't do a loop in a conditional branch condition. it might be worthwhile to test this edit to the level up common event plugin first.
It's an eval so you could do it if you put everything on one line, but... just don't. If you want something loop-like in a conditional branch script call you could use the .every or .some method on arrays, like $gameParty.members().some(who => who.level >= 5) for example (checks if any actor is level 5 or greater).
I will attempt your conditional branch script after we have the plugin working. I was so sure your first script was what I needed, but I'm glad you had thought ahead. Thank you.

For the plugin I copied and pasted the code, I used notepad and I am sure I pasted it onto the correct line of code. I created a brand new common event that just displays a text message and a SE. I remembered to place the note onto the proper class and give it the ID of the new common event. The plugin is turned on. Nothing happened. Maybe I am still doing something wrong, I checked for more instances of Game_Actor.prototype.levelUpEventId but only found the one instance. I highlighted it and pasted overtop of it.

Code:
  }

  /* Returns level up event ID. Lazy-load as needed */
  Game_Actor.prototype.levelUpEventId = function() {
    if (this._levelUpEventId !== undefined) {
      return this._levelUpEventId;
    }
    this._levelUpEventId = 0;
    var res = $.Regex.exec($dataClasses[this.actor().classId].note);
    if (res) {
      this._levelUpEventId = Math.floor(res[1]);
    }
    return this._levelUpEventId;
  } = function() {
    if (this._levelUpEventId !== undefined) {
      return this._levelUpEventId;
    }
    this._levelUpEventId = 0;
    var res = $.Regex.exec(this.actor().note);
    if (res) {
      this._levelUpEventId = Math.floor(res[1]);
    }
    return this._levelUpEventId;
  }
})(TH.LevelUpEvents);

EDIT: I should also mention I am not testing the plugin changes with a copied actor, I figured it was best not to do that yet. Also i I don't know if it helps but I just tested the actor note tag function and it does not work, which is ok with me, if we can get the plugin to function with class instead.
do you want the plugin to work for both class and actor? because you pasted it in wrong :mrsatan:

you can just delete the original function and replace it with the one i gave you if all you need is class note tag instead of actor. if its both then that could probably clash lol.

More specifically you were supposed to overwrite this code as well not just the one line. all this code here that follows what i gave you is breaking it.

JavaScript:
= function() {
    if (this._levelUpEventId !== undefined) {
      return this._levelUpEventId;
    }
    this._levelUpEventId = 0;
    var res = $.Regex.exec(this.actor().note);
    if (res) {
      this._levelUpEventId = Math.floor(res[1]);
    }
    return this._levelUpEventId;
  }

Here's what mine looks like

JavaScript:
  Game_Actor.prototype.canRunLevelUpEvent = function() {
    if (DataManager.isBattleTest()) {
      return false;
    }
    return true;
  }
 
  /* Returns level up event ID. Lazy-load as needed */
  Game_Actor.prototype.levelUpEventId = function() {
    if (this._levelUpEventId !== undefined) {
      return this._levelUpEventId;
    }
    this._levelUpEventId = 0;
    var res = $.Regex.exec($dataClasses[this.actor().classId].note);
    if (res) {
      this._levelUpEventId = Math.floor(res[1]);
    }
    return this._levelUpEventId;
  }
})(TH.LevelUpEvents);

I included the function above it and the code which follows as well to show proper placement.
@Ritter I figured it was something I did that was wrong. I only need the class script you gave me, I'm not worried about the actor portion of the code at all.
It took me awhile but I have everything excact in the code and my test event worked. Now I will attempt to apply the conditional branch script to a common event and trigger it by leveling up, if that works Ill try it with a copied actor. Thank you for your time and patience Ritter, I appreciate it greatly!

EDIT: @Ritter So we have the conditions set so the event is only triggered when class X reaches level X and when the actor levels it calls the event but I need a script to change the newly leveled actors class and face set. Is this possible?
ohh sorry i got sidetracked most of the day writing a plugin :mrsatan:

Add this $gameVariables.setValue(12, this.actor().id) line to this function where i did.. then use the code that follows in your common event. change the 12 to whatever game variable you want to store your actors id to.

JavaScript:
  /* Returns level up event ID. Lazy-load as needed */
  Game_Actor.prototype.levelUpEventId = function() {
    if (this._levelUpEventId !== undefined) {
      return this._levelUpEventId;
    }
    $gameVariables.setValue(12, this.actor().id);
    this._levelUpEventId = 0;
    var res = $.Regex.exec($dataClasses[this.actor().classId].note);
    if (res) {
      this._levelUpEventId = Math.floor(res[1]);
    }
    return this._levelUpEventId;
  }

you can use the following within your common event to change the class and faceset where you need to.

Code:
$gameActors.actor($gameVariables.value(12)).changeClass(n, keepExp)
$gameActors.actor($gameVariables.value(12)).setFaceImage("name", index)
change the variables here as well if you're not using variable 12.
in the first line the n is the classId and keepExp is true or false.
in the second line the "name" is the "name" of your faceset and index is which face to use from the image, probably starts with 0 for the first image. never used this before lol.

so what we're doing here is since you don't always know the id of the actor we store it to a variable when you level up this way you can use it in the common event, and the value will be overwritten the next time its used. this should work fine if you're not leveling up multiple actors at the same time. if so then another method would need to be used :mrsatan:
Thanks for explaining exactly what the script is doing. I think I understand how to apply it, I'll give it a try and probably get back to you tomorrow. Thank you again for your time.

this should work fine if you're not leveling up multiple actors at the same time. if so then another method would need to be used

My battles are set to be one on one and so as long as I don't allow experience to be shared with the party it should be fine.

EDIT: One last thing before I forget, what would the script for the newly leveled actor to recover all HP and MP fully be? Also I decided to use Variable 12 also.

EDIT 2: I inputted the script into the common event. I encountered an error. I posted the error message below. So I figured it was a plugin problem and turns out it was 4 of Yanfly's plugins. Repel Lure Encounter, Equipment Requirement, Equipment Core and Attach Augments are not compatible. That last one I wanted to use.

EDIT 3:
So the event works with your script added, at least the first branch for party member 0. I tested it on copied a copied actor and nothing happened. The copy should have the same class, but perhaps the issue is the note tags are not copied? I will try it with the other plugin that copies actors tomorrow. Maybe I will have better luck. I really hope my assumption is wrong.
Well for restoring the actors Hp and Mp I'll attach an image.
I'm gonna need to see how you used the script calls because that error message doesn't tell me enough.

So i tested stuff with Hime's Instance Actors and was able to get things working pretty easily, the actorId is stored to the variable which means i can do stuff with it as needed in a common event. I was able to change the faceset of the actor and the class using the code above in a common event that was executed upon leveling after smashing a couple bats.

I think it would help to see where your common event is at now to know where something went wrong.

also if nothing at all happened its also possible the edit you made to the level up event plugin threw an error at you, i'd check in console and see if there was a TypeError.
@Ritter glad it worked for you at least. I was hoping it was just something I did wrong. I attached some screenshots below with the level up plugin and 70-73 are my test event. If you need anything else just ask and as always thank you for your time.
Well i only really see one thing, you forgot to put "quotes" around your faceset name. Also if your actor is always the first in your party the $gameActors.actor($gameParty._actors[0]) method you're using there looks fine. The variable is probably still needed for convenience with increasing hp and mp upon levelup, chances are its the faceset name. Make sure you put the name "Exactly" as the filename is named. Leave off the .png though. It seems like you're getting thrown an error because the common event can't find the image you specified.

$gameActors.actor($gameVariables.value(12)).setFaceImage("magmataurface", 0)
OR
$gameActors.actor($gameVariables.value(12)).setFaceImage("Magmataurface", 0)

case sensitive. fix that issue everywhere you use the .setFaceImage line and you should be good to go.
@Ritter everything seems to work including the HP and MP effect! Can't believe that part was so easy after everything else. Thank you so much!

I also can't believe the issue was with case sensitivity. I even caught my self with the Skorchtaur name later in the script and corrected it thinking about case sensitivity. I reapplied the quotes too.

As for the conditional branch script, I could event it out for each party slot but the battles are one on one, and you raised the possibility of an issue with multiple actors leveling at one time. I figured this was the safest way to do use the common event and the party can still gain experience and level if i choose to implement that later, they just can't transform unless they level from battling (party slot 0).

Do you think the problem I had with the other plugins related to the case sensitivity or is it just the plugins are not compatible?

One last thing before I close the thread, Do you happen to know a way to call the variable using a text code? I want to use it so I can display the proper names during the common event.

Once again thank you for your time and patience, I learned quite a bit.
The other plugins were likely just catching the error in the common event, probably nothing to worry about on that end. It wasn't so much case sensitivity as it was not using quotes, you're supposed to feed that function a "string" when you tell it what the face image is and since you fed it a value without quotes it was looking for what that value is defined as, and in this case it would be undefined. In order to feed the function something that isn't a string you would first need to define a variable (which contains a string) to be used in the call.

but anyway

For displaying the name the easiest route to take would probably be to add another variable to use and throw in this line here.

JavaScript:
  /* Returns level up event ID. Lazy-load as needed */
  Game_Actor.prototype.levelUpEventId = function() {
    if (this._levelUpEventId !== undefined) {
      return this._levelUpEventId;
    }
    $gameVariables.setValue(12, this.actor().id);
    $gameVariables.setValue(13, this.actor().name);
    this._levelUpEventId = 0;
    var res = $.Regex.exec($dataClasses[this.actor().classId].note);
    if (res) {
      this._levelUpEventId = Math.floor(res[1]);
    }
    return this._levelUpEventId;
  }

This new line for variable 13 would store the actors name to a variable to be used in the common event show text. We're creating a new variable to be used for this because the other variable only stores the Id, there's other ways to do this but this is a simple way to handle it, just one more line to throw into that function :mrsatan:

then inside your show text you would want to do something like:

Looks like \V[13] is yeeting!

this would make it say Looks like (whatever your character name is) is yeeting!
@Ritter I think I may not of been very clear in the request. This seems to pull the actors name from the data base, but this actor has been renamed but when tested it still uses the database name.
ohh so then you could do this inside your common event, maybe it'll have the proper name?

◆Control Variables:#0013 = $gameActors.actor($gameVariables.value(12))._name

it should return the current name of the target actor

don't forget to delete the $gameVariables.setValue(13, this.actor().name) line from the plugin as that could cause issues if left there.
ohh so then you could do this inside your common event, maybe it'll have the proper name?

@Ritter No luck, it still shows the name from the database. I put the control variable at the start of my common event. I attached a screenshot below.
How/where are you changing the name of the actor?
@Ritter Now that was the question to ask. I solved the issue myself and everything works now. The name input was at the end of a troop event. I was using the following script.

Code:
var newActor = InstanceManager.addActor(3)
$gameParty.addActor(newActor.id)

SceneManager.push(Scene_Name);
SceneManager.prepareNextScene(newActor.id, 8);

The issue I was having was actor 8 did not exist yet. I increased my available actors in the database to 8 and that was all I had to do. I think actor 8 serves as a proxy of sorts?

Original thread: https://forums.rpgmakerweb.com/threads/party-member-script-to-check-for-class-x-and-level-x.122836/