MV Set skillType name to .equips()[0].name SOLVED

Rewriting this because I made some progress:

Hello, I am hoping to set some of the skill type names in my game to be a direct reference to the weapon equipped. Something like having the skill type name be = user.equips()[0].name

I have set the skill type names to be \V[112], and I currently have the variable updated in my battle system every time a new turn takes place, so this works for combat. However I have not worked near as much with the menu scene, so I am unsure where to place the code to run whenever an actor's skill list window is selected.

This is what I have for the combat side of things, which runs once per turn start.

JavaScript:
var activeFighterID = BattleManagerTBS.activeEntity()._battler._actorId;
var value = activeFighterID;
$gameVariables.setValue(15, value);
if ($gameActors.actor($gameVariables.value(15)).equips()[0]) {

$gameVariables.setValue(112, $gameActors.actor($gameVariables.value(15)).equips()[0].name);


Window_MenuActor in rpg_windows.js seems to be the right place to put the script, however this.actor returns "this.actor is not a function"

Feels like I am almost there but still missing something.
JavaScript:
function Window_MenuActor() {
$gameVariables.setValue(112, this.actor().equips()[0].name);
    this.initialize.apply(this, arguments);
}
im not familiar with the the plugin mentioned, but id figure poking around Window_ActorCommand.addSkillCommands() could be valid. you could modify it a bit to change the name of your weapon skill types as theyre added to the actor menu.

Spoiler: default function
Code:
Window_ActorCommand.prototype.addSkillCommands = function() {
    var skillTypes = this._actor.addedSkillTypes();
    skillTypes.sort(function(a, b) {
        return a - b;
    });
    skillTypes.forEach(function(stypeId) {
        var name = $dataSystem.skillTypes[stypeId];
        this.addCommand(name, 'skill', true, stypeId);
    }, this);
};
Hey Robro, I think I actually just got it.

Not really using a plugin for this outside of an escape codes one, just messing around with javascript.

Solution was changing the following line in rpg_windows.js to this:

Code:
Window_SkillType.prototype.setActor = function(actor) {
$gameVariables.setValue(112, actor.equips()[0].name);
    if (this._actor !== actor) {
        this._actor = actor;
        this.refresh();
        this.selectLast();
    }
};

Just had to get the formatting right. I think I should put this change in a separate plugin in case MV updates and overwrites the edit. I could do this by simply pasting that line into a new .js file and activating it at the bottom of my plugin list, yea?

Yes indeed! Success! Critical hit!

1711347693130.png


Oh wait it crashed, welp back to the coalmines. Think I might need to nest the setVariable function to only run if the slots checked are actually equipped. Shouldn't be too tough.

updated code:

JavaScript:
Window_SkillType.prototype.setActor = function(actor) {
    

if (actor.equips()[0]) {   
$gameVariables.setValue(112, actor.equips()[0].name);
}
if (actor.equips()[1]) {   
$gameVariables.setValue(113, actor.equips()[1].name);
}
if (actor.equips()[2]) {   
$gameVariables.setValue(114, actor.equips()[2].name);
};


    if (this._actor !== actor) {
        this._actor = actor;
        this.refresh();
        this.selectLast();
    }
};

Works like a charm. I just reduced my total skill type qty from over 1000 to under 60. Hopefully this clears some of the slowdown I have been experiencing.
I think I should put this change in a separate plugin in case MV updates and overwrites the edit. I could do this by simply pasting that line into a new .js file and activating it at the bottom of my plugin list, yea?
You dont want to make changes to the core files for a number of reasons. its always safer to introduce the changes as external plugins

Works like a charm. I just reduced my total skill type qty from over 1000 to under 60. Hopefully this clears some of the slowdown I have been experiencing.
good work. each weapon was planned to have their own skilltype and subsequent skills? glad you found a way to condense those.

What kind of slowdowns have you been experiencing and where? i wouldnt imagine the command list generation would cause slowdowns if you had 1000 skill types unless each actor had access to hundreds of them at a time.
It might have some startup impact since plugins tend to look at database entries to set game objects when the game is opened, but midgame slowdown because of that seems a bit off to me since afaik, most functions that look at skill types look at an actor's available skill types instead of the whole array of all types
From the editor when opening up skilltypes to assign it takes a few seconds to load, as well as when starting the game. This occurred after I increased the skilltype limit to 2000. Going to be able to reduce it to around 200-250 now so this should take care of those two examples somewhat at the least.

I had wanted it easier for the player to tell which weapon they were selecting to use skills from in battle, so the original plan was a new skill type per weapon. Reducing it to a single type with a variable for the name is a solution I had in mind from the start, but not one I knew how to perform initially.

Outside of that, the only slowdowns I have noticed are when opening the menu, which is likely due to a faulty script I tried to repair (I made it worse, but at least it functions in the interim now), and something related to AI pathing for the custom battle system I use. Those are threads for another day however.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/set-skilltype-name-to-equips-0-name-solved.167144/