Script call to level a certain class?

Hello,

i'm looking for a Scriptcall to level a certain class on item use. For example an item that levels the black mage class by 1 for a certain character.

I already looked in the script call list but have not found anything.

I'm using the Visustella core engine and class change plugin - i don't know it that changes any scriptcalls for classes.

Thanks in advance!

Have a nice day!
Hello,

i'm looking for a Scriptcall to level a certain class on item use. For example an item that levels the black mage class by 1 for a certain character.

I already looked in the script call list but have not found anything.

I'm using the Visustella core engine and class change plugin - i don't know it that changes any scriptcalls for classes.

Thanks in advance!

Have a nice day!

Here is just an example of what you can do:
Required: VisuMZ_1_ClassChangeSystem
+One Database Item
+One Common Event

Spoiler: Create Common Event
1690706642617.png

Code:
let accuBase = 0;
for (let i = $gameActors.actor(1)._classLevel[2]; i < $gameActors.actor(1)._classLevel[2] + 1; i++) {
    accuBase += $gameActors.actor(1).expForClassLevel(2, i + 1);
  }
$gameActors.actor(1)._exp[$gameActors.actor(1).getMulticlassAtTier(2)?.id] = accuBase;

Spoiler: Create Item
1690706739809.png

As targeting isn't relevant, I've set the scope to all allies(wont affect actual target-- see below)
Set Effects with the Common Event we just made.
Add notetag:
Code:
<JS Item Enable>
 enabled = $gameParty.members()[0] == $gameActors.actor(1) &&
 $gameActors.actor(1).multiclass(2) !== null;
</JS Item Enable>
As long as the party leader is our target actor, and subclass isn't empty -- the item will be available to use.
Other suggested uses:
Code:
<JS Item Enable>
 enabled = $gameActors.actor(1).isBattleMember() &&
 $gameActors.actor(1).multiclass(2) !== null;
</JS Item Enable>
As long as our target actor is part of the Battle Party(Active Members), and subclass isn't empty -- the item will be available to use.

Code:
<JS Item Enable>
 enabled = $gameParty.members().includes($gameActors.actor(1)) &&
 $gameActors.actor(1).multiclass(2) !== null;
</JS Item Enable>
As long as our target actor is part of the Party(Active or Inactive), and subclass isn't empty -- the item will be available to use.

BONUS:
Spoiler: Sub Job EXP Display
1690707726576.png

VisuMZ_2_ClassChangeSystem > Window Settings > JS: Extra Data >
Replace Code:
Code:
// Declare Arguments
const actor = this._actor;
const classID = arguments[0];
const tier = arguments[1];
const settings = arguments[2];
const rect = arguments[3];
const padding = 8;
const targetClass = $dataClasses[classID];
const wordWrap = Imported.VisuMZ_1_MessageCore;
const removeIcons = true;
const fontSize = 22;

// Create Coordinates
let x = rect.x + (this.itemPadding() * 4);
let y = rect.y + (this.lineHeight() * 3.25);
let width = rect.width - (this.itemPadding() * 8);

// EXP
let text = '\\C[16]%1:\\C[0] \\FS[%3]%2'.format(TextManager.exp, actor._exp[actor.getMulticlassAtTier(tier)?.id], fontSize || 22);
this.drawTextEx(text, x, y, width)
y += this.lineHeight();

// Skill Type Access
if (settings.AddedStypes && ((y + this.lineHeight()) <= (rect.y + rect.height))) {
    let stypes = targetClass.traits.
        filter(trait => trait.code === Game_BattlerBase.TRAIT_STYPE_ADD).
        map(trait => $dataSystem.skillTypes[trait.dataId]).
        join(', ');
    let text = '\\C[16]%1:\\C[0] \\FS[%3]%2'.format(TextManager.skill, stypes, fontSize || 22);
    if (removeIcons) text = text.replace(/\\I\[(\d+)\]/gi, '');
    if (wordWrap) text = '<WordWrap>' + text;
    this.drawTextEx(text, x, y, width);
    y += this.lineHeight();
}

// Weapon Access
if (settings.EquipWeapons && ((y + this.lineHeight()) <= (rect.y + rect.height))) {
    let stypes = targetClass.traits.
        filter(trait => trait.code === Game_BattlerBase.TRAIT_EQUIP_WTYPE).
        map(trait => $dataSystem.weaponTypes[trait.dataId]).
        join(', ');
    let text = '\\C[16]%1:\\C[0] \\FS[%3]%2'.format(TextManager.weapon, stypes, fontSize || 22);
    if (removeIcons) text = text.replace(/\\I\[(\d+)\]/gi, '');
    if (wordWrap) text = '<WordWrap>' + text;
    this.drawTextEx(text, x, y, width);
    y += this.lineHeight();
}

As mentioned, this is just an example -- find your own creativity to suit your project!
Wow, thank you so much for that detailed answer and the examples. This helps me so much, especially understanding the way this game and the coding works.
You are my hero of the week! Followed you on YT and i'm curios about the other vidoes!
The code somehow does not work as intended. It only works for the class with ID 2. But it totally screws up on all other classes... Any idea why?
I tried it in my common event and also reacreated your item, both do not work.
I leveled class ID 2 black mage to level 4 with your item. WOrked fine and as it should be. Changed to Class 3 White mage and used the item and it also leveled to level 4. Used it a few times more and nothing changed at all. Changed class used item and class immediately level 4 again. very strange...
The code somehow does not work as intended. It only works for the class with ID 2. But it totally screws up on all other classes... Any idea why?
I tried it in my common event and also reacreated your item, both do not work.
I leveled class ID 2 black mage to level 4 with your item. WOrked fine and as it should be. Changed to Class 3 White mage and used the item and it also leveled to level 4. Used it a few times more and nothing changed at all. Changed class used item and class immediately level 4 again. very strange...
The code you were given uses a hardcoded class ID of 2. If you want it to work on the current class whatever its ID is, you'll have to use an actual class ID property instead of a number.
accuBase += $gameActors.actor(1).expForClassLevel(2, i + 1);
Is this the reference for the class ID?

so if i put the ID in a variable first like this:
var classid = $gameActors.actor(1)._multiclasses[1];

and alter the line like this:
accuBase += $gameActors.actor(1).expForClassLevel(classid, i + 1);

It should work for the equipped class right?
No. I see four places in the common event code where the number 2 is used.

And it's also in the JS Item Enable, if you're using that.
The code somehow does not work as intended. It only works for the class with ID 2. But it totally screws up on all other classes... Any idea why?
I tried it in my common event and also reacreated your item, both do not work.
I leveled class ID 2 black mage to level 4 with your item. WOrked fine and as it should be. Changed to Class 3 White mage and used the item and it also leveled to level 4. Used it a few times more and nothing changed at all. Changed class used item and class immediately level 4 again. very strange..
Was just an example based on your initial request. Ill be away for a while and can't help u now. Both @Trihan and @ATT_Turan are knowledgeable gentlemen, perhaps they can help you when they have time. If not, I'll get back to you when I can.
accuBase += $gameActors.actor(1).expForClassLevel(2, i + 1);
Is this the reference for the class ID?

so if i put the ID in a variable first like this:
var classid = $gameActors.actor(1)._multiclasses[1];

and alter the line like this:
accuBase += $gameActors.actor(1).expForClassLevel(classid, i + 1);

It should work for the equipped class right?
In order for that to work, you'd need to define "classid" as it doesn't exist in the context of a common event. In the preceding line you could do

JavaScript:
const classid = $gameActors.actor(1)._classId;

Also since $gameActors.actor(1) is being used multiple times, it might be neater to put it in an alias, like

JavaScript:
const actor = $gameActors.actor(1);

Then you'd replace any instance of $gameActors.actor(1) with actor.
I tried it like this and several alterations but it wont quite work:

let accuBase = 0;
const classid = $gameActors.actor(1)._multiclasses[1];

for (let i = $gameActors.actor(1)._classLevel[classid]; i < $gameActors.actor(1)._classLevel[classid] + 1; i++) {
accuBase += $gameActors.actor(1).expForClassLevel(classid, i + 1);
}
$gameActors.actor(1)._exp[$gameActors.actor(1).getMulticlassAtTier(classid)?.id] = accuBase;


It happens nothing at all now. Console does not show any errors, so the code seems correct.

For my understanding:
we define the needed variables accuBase and classid
during the loop i grows till it is exactly the level from the class with id classid
then we set accuBase to the amount of exp needed for that level + 1
Last part we should set the actual exp value to that amount via the accuBase variable

Is this about right? i don't find the error... it seems right to me...
When you post code, please use the CODE tags (the </> in the edit bar).

It keeps your lines, indentations, and braces working correctly.

const classid = $gameActors.actor(1)._multiclasses[1];
This does not match the line of code Trihan gave you. The whole point is that you need to be referencing a number. That number is the ID of the class you're trying to level up.

You can leave it as a typed number, the way NaososX showed you, or you can put it in a variable so you can copy and paste this code for different classes and just change one number. But you didn't copy and paste what Trihan said to do, so you're not setting the variable to a number - you're setting it to a CLASS object.

for (let i = $gameActors.actor(1)._classLevel[classid]; i < $gameActors.actor(1)._classLevel[classid] + 1; i++) {
I know it was in the example that NaososX gave you, but as he said that was just an example for you to work off of. In your specific case, there's no point in using a for loop. You're not doing something to multiple classes, you're doing it one time. There's no reason to have several lines of code to make a loop that runs once.

All you actually need to do for what you're asking is this:
Code:
let classId = 2;
$gameActors.actor(1)._exp[$gameActors.actor(1).getMulticlassAtTier(classId)?.id]=$gameActors.actor(1).expForClassLevel(classId, $gameActors.actor(1)._classLevel[classId]);

That will level up class 2 one time. If you want to level up a different class, change the number after let classId

If you want it slightly more readable:
Code:
let classId = 2;
let actor = $gameActors.actor(1);
actor._exp[actor.getMulticlassAtTier(classId)?.id]=actor.expForClassLevel(classId, actor._classLevel[classId]);

That would also allow you to change the targeting on the fly, if you make your item usable on any given actor, you can use the event command to get the targeted actor ID into a variable first.

In that case, you'd change the second line to say let actor = $gameActors.actor($gameVariables.value(X)); where X is the ID of the variable.
This does not match the line of code Trihan gave you. The whole point is that you need to be referencing a number. That number is the ID of the class you're trying to level up.

yeah it does not match, because that would return me the value from the primary class, which I do not want. My line returns me the class ID from the secondary class.


Code:
Code:
let classId = 2;
let actor = $gameActors.actor(1);
actor._exp[actor.getMulticlassAtTier(classId)?.id]=actor.expForClassLevel(classId, actor._classLevel[classId]);
Sadly that does not level my class with class ID 2. Once again no error message on console but no change in class levels whatsoever.

I really appreciate all your support and help. I did not know that here was a code edit for posts, i will use them next time. I do know java but javascript is similar but different, so i'm not totally familiar with all the code setup.
I have a common event set up, where you can choose the actor you want to level the secondary class and a loop if you want to do more than 1 level for said class. The only struggle is to actually raise the level. I know the lines to get primay class ID, secondary Class ID, the class Level for each of them but not how to raise the level.
I know the lines to get primay class ID, secondary Class ID, the class Level for each of them but not how to raise the level.
That would be this line, right?
Code:
actor._exp[actor.getMulticlassAtTier(classId)?.id]=actor.expForClassLevel(classId, actor._classLevel[classId]);
Set the actor's experience in the specified class to what that class needs for the next level.

So I'm not sure from your post what the problem is. The initial code that NaososX gave you should work, and you said it did work for that specific class. If you need to make it work for different classes, you just change the number 2 from his code to whatever the class ID should be (or use a variable if that's appropriate).

That line to set the experience has been there all along...I'm just not sure what you're saying isn't working. If you can show us what you currently have, say what you want it to do, and what it isn't doing correctly, we can help you.
1690837747672.png

1690837958919.png

I tried to use the item with both codes now, and nothing happens at all. Secondary Class has ID2 and gets no level whatsoever on item use. Actor ID is 1.
I tried to modify NaoSox Code to assign the currently equipped class in secondary slot but that did not work. The code looks like this and it still only works on class with ID2.

let accuBase = 0; let classid = $gameActors.actor(1)._multiclasses[1]; for (let i = $gameActors.actor(1)._classLevel[classid]; i < $gameActors.actor(1)._classLevel[classid] + 1; i++) { accuBase += $gameActors.actor(1).expForClassLevel(classid, i + 1); } $gameActors.actor(1)._exp[$gameActors.actor(1).getMulticlassAtTier(classid)?.id] = accuBase;
What I want it to do is increase the level of the secondary class by one on each use.

If you need any more infos, just tell me. Thanks once again for the help.
I don't understand what @NaosoX is doing with the getMulticlassAtTier() method.

It's not in the plugin documentation, so I don't know exactly what it does...but if he's ultimately retrieving an id from it, I don't know why it can't just use classId again. That would make sense to me, that _exp is an array of how much experience you have by class ID.

I wonder if that's returning some value you don't want, which is why it's always applying to class 2.

If you change the last line to say _exp[classid] what happens?
Can only test in the evening after work.
But I realized in the morning while still fresh that it only works with class because one of these number 2 is mandatory. Meaning I only have to try each alteration and one should work as intended.
And I think that you are right and it quite possibly is the tier which is in fact a 2nd tier class.
let accuBase = 0; let classid = $gameActors.actor(1)._multiclasses[1]; for (let i = $gameActors.actor(1)._classLevel[classid]; i < $gameActors.actor(1)._classLevel[classid] + 1; i++) { accuBase += $gameActors.actor(1).expForClassLevel(classid, i + 1); } $gameActors.actor(1)._exp[$gameActors.actor(1).getMulticlassAtTier(2)?.id] = accuBase;

This Script now works perfectly. It levels the secondary class whatever it is by one level exactly.
I made a choice question to level once again and put together another common event for this using the same code and nothing happens. Do i have to refresh the variables or something like that?

Other than that the player just may have to just use the item over and over again.

Thanks at everyone for the help. You guys are great and really made my week by providing support.
For anyone curious:
I would have to go into class screen everytime between item uses to update the class level. With this code it happens automatically and you can use the item over and over during one common event to level up a few times.

let accuBase = 0; let classid = $gameActors.actor(1)._multiclasses[1]; for (let i = $gameActors.actor(1)._classLevel[classid]; i < $gameActors.actor(1)._classLevel[classid] + 1; i++) { accuBase += $gameActors.actor(1).expForClassLevel(classid, i + 1); } $gameActors.actor(1)._exp[$gameActors.actor(1).getMulticlassAtTier(2)?.id] = accuBase; $gameActors.actor(1).refresh();

$gameActors.actor(1).refresh();
I highlighted the important part.
Looks like you guys have made good progress together ❤️
Good job

Original thread: https://forums.rpgmakerweb.com/threads/script-call-to-level-a-certain-class.159841/