Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Effective way to modify basic script

nickaqua

Villager
Xy$
0.00
I'm currently learning .Js right now and tried to modify menu right now

straight to the problem : lets say , in drawActorSimpleStatus , its a function that draw all the status the actor has (name, level , class , hpbar , mpbar) in the default menu

let's say I wanted to make the menu didnt draw any hpbar or mpbar , so I'm aliasing drawActorSimpleStatus and write all the code before except for hpbar and mpbar , thus the game wont show hpbar on mpbar.

but the problem is , drawActorSimpleStatus is used everywhere , not just menu. let's say in healing skill target from menu. I wanted the hpbar and mpbar are shown when doing targeting but not shown in menu, but then again they are using same function, so what is an effective way into this kind of problem? (also for other function, mostly the basic funciton)

also people said that modifying direct script like this is bad because it will affect a lot of other , its like you complete 1 task but ruining other 3 tasks. what is the good approach for this kind of problem? creating another function that mostly do the same? or ?
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
A few things to note.

  1. Yes, modifying the core scripts will possibly affect any other plugin you may use.
  2. Creating a new .js file and copying the methods/functions you want to change is the solution
  3. Learning Javascript is different than learning MV's codebase.
That being said I would recommend creating the new .js file before you attempt to change the behavior of your project.

Okay, so now for the dirty stuff

drawActorSimpleStatus is used everywhere you're correct about that. That being said there are two ways to go about this, the best way would be to create an entirely new method and use that where you want to by replacing the the drawActorSimpleStatus in the other window classes.

New Method with no HP or MP bars
JavaScript:
Window_Base.prototype.drawStatusNoHpMp= function(actor, x, y, width) {
    var lineHeight = this.lineHeight();
    var x2 = x + 180;
    var width2 = Math.min(200, width - 180 - this.textPadding());
    this.drawActorName(actor, x, y);
    this.drawActorLevel(actor, x, y + lineHeight * 1);
    this.drawActorIcons(actor, x, y + lineHeight * 2);
    this.drawActorClass(actor, x2, y);
};
For example you want to change it when the skill is being used correct? In this case, changing the Window_SkillStatus refresh function is what needs to be done.

The original method from SkillStatus, which I believe is used for when using skills for healing.
JavaScript:
Window_SkillStatus.prototype.refresh = function() {
    this.contents.clear();
    if (this._actor) {
        var w = this.width - this.padding * 2;
        var h = this.height - this.padding * 2;
        var y = h / 2 - this.lineHeight() * 1.5;
        var width = w - 162 - this.textPadding();
        this.drawActorFace(this._actor, 0, 0, 144, h);
// Notice here is where the old method is. Replace it with the new method.
        this.drawActorSimpleStatus(this._actor, 162, y, width);
    }
};
So how do you put this in your own file, simply create the new file and copy both of those methods in the new file. If you have any conflicts with other plugins you will have to figure out which ones and alias them accordingly but that is another topic.
 
Top