Octopath Traveler's Battle System Plugin Request

@Astfgl66
I eventually got it to work, it seems it only wants to use 1.6.1 when opening through steam (usually I just open it from the project files)
Future reference for those with this issue: https://steamcommunity.com/games/363890/announcements/detail/1694924880247085699


Testing it out it works great!
Anyway could there be icons displayed instead of numbers in brackets?
I was thinking you could set a icon for shield 2, then when its hit with the correct element/weakness the icon would change to a shield 1 icon that was set for it.

I currently have it showing its weakness on turn 0 using states.
I haven't figured out a way to link the "BREAK"/Weakness hit to showing a weakness(State).
Alright, I've made a small update to change the display, redownload the plugin from the pastebin link and set the new parameters to your liking, by default it should now look like this:
Spoiler
gppm9bw.jpg
@Astfgl66

I updated the plugin, made sure the correct version of rpg maker mv was running, but ran into problems.

The icon doesn't want to appear it just stays as brackets, another problem was the shield counter now reaches 0 and has no state effect when hitting it.

Also have any idea how I would link the weakness hit to showing a weakness (state Icon)?
I botched up the name for reading parameters in my plugin.
I use different names while testing and uploading, and forgot to manually change it before putting it on pastebin. I fixed it, redownload.

No idea about displaying weaknesses without a plugin, changing state icons dynamically is probably not that great an idea.
So you'd have to create a whole new display, I don't plan on doing it anytime soon.
@Astfgl66 nice one creating break plugin pal! Mind if I use it? Non-commercial ff7 fan game! Will credit of course.. although I’m also running MV 1.5.1 as most plugins I use are no longer supported and will no doubt break my project xD if I can use is it possible to not show enemies shields in the names ? Thanks 🙂
The terms of use are in the plugin header and in this thread.
It boils down to non commercial use only and credit me. Feel free to use it.

Spoiler
Code:
//===================================================================================
// Astfgl's Shield counter and Break
// Date 19/08/2018
// Free to use non commercially, repost and
// edit, as long as the final product is kept under the same terms of use.
// Credits required, any of Astfgl, Astgfl (Pierre MATEO), Pierre MATEO
// v1.0 19/08: release
// v1.1 21/08 modified shield display modes
// 1.5.1 Compatibility
// Time spent : 3.5h
//====================================================================================

/*:
 * @plugindesc OT Shield and Break System OLD 1.5.1
 * @author Astfgl
 *
 * @param defaultState
 * @text State Id when shield = 0
 * @type number
 * @default 4
 * @desc Which state will be applied when a battler shield reaches 0.
 *
 * @param defaultElemCutoff
 * @text Elemental weakness cutoff
 * @type number
 * @default 1
 * @desc Attacks must have an elemental value strictly superior to this to remove from the shield counter.
 *
 * @param baseIcon
 * @text Base shield Icon
 * @type number
 * @default 16
 * @desc The icon id to display shields.
 *
 * @param mode
 * @text Shield display mode
 * @type number
 * @default 0
 * @desc 0->number in brackets, 1 -> number in icon
 *
 * @help
 *Allows you to set up a shield and break system similar to Octopath traveler's
 *Recommended plugins:
 * - Yanfly's Battle engine core
 * - Yanfly's Element core
 * - Yanfly's Buffs and state core
 *It has not been tested without these plugins and thus may not function.
 *
 *==========================================
 * What it does:
 *==========================================
 *In battle, if an attack hits an elemental weakness,
 *it will decrease a shield counter, once that counter reaches 0
 *a state will be applied to the battler.
 *
 *It will reduce the shield counter by 1 for each element of the attack
 *the recipient is weak to.
 *So if your attack deals fire and ice damage and the enemy is weak to both
 *shields will be reduced by 2.
 *
 *Display of the shield amount is done via the battler name in brackets.
 *
 *==========================================
 * How to use:
 *==========================================
 *Set max shield notetags:
 *
 *Order for max shield calculation:
 *actor, class, equipment, passive states, states then floored
 *Notetags: <mSh: >, Ex: <mSh: num += 5>
 *
 *Each time calculations are made with the num variable.
 *Ex: num += 5 in actor, num *= 2 in class will result in a max shield of 10
 *The same thing but with a state using num = 1 will result in a max shield of 1
 *
 *Enemies are the same except you remove class and equipment calculations
 *
 *If you don't set anything, battlers have a default shield value of 1.
 *
 *If you want it to function like octopath traveler, I recommend
 *using a state with the cannot move property, set to expire in 2 turns
 *and with the following notetag:
 *<Custom Remove Effect>
 *user._sh = user._mSh;
 *</Custom Remove Effect>
 *This will restore shields to maximum when the broken state expires.
 *
 *==========================================
 * Changing break state
 *==========================================
 *If you want to change what state enemies are inflected with upon break use:
 *<DBS: > in an enemy note box
 *Else it will use what's inside plugin parameters
 *
 *==========================================
 * Modifying enemy shields:
 *==========================================
 * Use the following script calls:
 * (battler).modMaxSh(number)
 * This will add number to max shields, after all other calculations.
 * This bonus will never be reset.
 * Use states for temporary modifications for actors.
 *
 * (battler).changeSh(number), this will withdraw number from current shields
 *
 *All parameters and notetags are evaled
*/

(function(){

var defaultState = eval(PluginManager.parameters("AstfglSCB").defaultState);
var defaultElemCutoff = eval(PluginManager.parameters("AstfglSCB").defaultElemCutoff);
var mode = eval(PluginManager.parameters("AstfglSCB").mode)
var shieldIcon = eval(PluginManager.parameters("AstfglSCB").baseIcon)
//Weakness setup
var _aliasGAI = Game_Actor.prototype.initialize
Game_Actor.prototype.initialize = function(actorId) {
    _aliasGAI.call(this,actorId);
    if (this._actorId === 0) {return}
    this._mShB = 0;
    this._mSh = this.getMaxSh();
    this._sh = this._mSh
};

Game_Actor.prototype.getMaxSh = function() {
    var num = 0;
    var a = this;
    var user = this;
    var id = this.actorId();
    if ($dataActors[id].meta.mSh) {
        num = eval($dataActors[id].meta.mSh)
    }
    if ($dataClasses[this._classId].meta.mSh) {
        num = eval($dataActors[id].meta.mSh)
    }
    for (var i = 0; i < this._equips.length; i++) {
        var it = this._equips[i];
        if (it._dataClass === "weapon" && it._itemId !== 0) {
            if ($dataWeapons[it._itemId].meta.mSh) {
                num = eval($dataWeapons[it._itemId].meta.mSh)
            }

        }
        if (it._dataClass === "armor" && it._itemId !== 0) {
            if ($dataArmors[it._itemId].meta.mSh) {
                num = eval($dataArmors[it._itemId].meta.mSh)
            }

        }
    }
    if (this._passiveStatesRaw) {
        for (var i = 0; i < this._passiveStatesRaw.length; i ++) {
            if ($dataStates[this._passiveStatesRaw[i]].meta.mSh) {
                num = eval($dataStates[this._passiveStatesRaw[i]].meta.mSh)
            }
        }
    }
    for (var i = 0; i < this._states.length; i ++) {
        if ($dataStates[this._states[i]].meta.mSh) {
            num = eval($dataStates[this._states[i]].meta.mSh)
        }
    }
    num +=     this._mShB
    num = Math.floor(num)
    if (num === 0 || isNaN(num)) {num = 1}
    return num
}

var _aliasGEI = Game_Enemy.prototype.initialize
Game_Enemy.prototype.initialize = function(enemyId, x, y) {
    _aliasGEI.call(this,enemyId, x, y);
    if (this._enemyId === 0) {return};
    this._mShB = 0;
    this._mSh = this.getMaxSh()
    this._sh = this._mSh;

};

Game_Enemy.prototype.getMaxSh = function() {
    var num = 0;
    var a = this;
    var user = this;
    var id = this._enemyId;
    if ($dataEnemies[id].meta.mSh) {
        num = eval($dataEnemies[id].meta.mSh)
    }
    if (this._passiveStatesRaw) {
        for (var i = 0; i < this._passiveStatesRaw.length; i ++) {
            if ($dataStates[this._passiveStatesRaw[i]].meta.mSh) {
                num = eval($dataStates[this._passiveStatesRaw[i]].meta.mSh)
            }
        }
    }
    for (var i = 0; i < this._states.length; i ++) {
        if ($dataStates[this._states[i]].meta.mSh) {
            num = eval($dataStates[this._states[i]].meta.mSh)
        }
    }
    num += this._mShB;
    num = Math.floor(num)
    if (num === 0 || isNaN(num)) {num = 1}
    return num
}

//Action modifying

var _aliasGAA = Game_Action.prototype.apply
Game_Action.prototype.apply = function(target) {
    _aliasGAA.call(this,target)
    var mod = 0;
    var elements = this.getItemElements();
    for (var i = 0; i < elements.length; i++) {
        if (target.elementRate(elements[i]) > 1) {
            mod +=1;
        }
    }
    target.changeSh(mod);
}

Game_Battler.prototype.changeSh = function(num) {
    if (this._sh === 0) {return}
    this._sh -= num;
    this._sh = this._sh.clamp(0,this._mSh);
    if (this._sh === 0) {
        if (this.isActor()) {if ($dataActors[this.actorId()].meta.DBS) {defaultState = eval($dataActors[this.actorId()].meta.DBS)}}
        else {if ($dataEnemies[this._enemyId].meta.DBS) {defaultState = eval($dataEnemies[this._enemyId].meta.DBS)}}
        this.addState(defaultState)
    };
}


//Modify name function to display shield amount
var _aliasGEN = Game_Enemy.prototype.name
Game_Enemy.prototype.name = function() {
    if ( mode === 1 ) {return _aliasGEN.call(this); }
    return "[" + this._sh + "]" + this.originalName() + (this._plural ? this._letter : '');
}

//Modify battle window draw name function to display shield amount
Window_BattleStatus.prototype.drawActorName = function(actor, x, y, width) {
    width = width || 168;
    this.changeTextColor(this.hpColor(actor));
    if (mode === 1) {
        var fs = this.contents.fontSize
        this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
        this.drawIcon(shieldIcon,x,y+2)
        var wd = this.textWidth(String(actor._sh));
        this.drawText(actor._sh, x + 16 - wd/2, y, 40);
        this.contents.fontSize = fs
        this.drawText(actor.name(), x + 40, y, width - 48);
    } else {
        this.drawText("["+ actor._sh + "]" + actor.name(), x, y, width);
    }
}

//Modify enemy name display
var _aliasWEVS = Window_EnemyVisualSelect.prototype.refresh
Window_EnemyVisualSelect.prototype.refresh = function() {
    this.contents.clear();
    if (!this._battler) return;
    if (!this._showEnemyName) return;
    if (this._battler.isHidden()) return;
    this._requestRefresh = false;
    this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
    var text = this._battler.name();
    var wy = this.contents.height - this.lineHeight();
    if (mode === 1) {
        this.drawIcon(shieldIcon,0,wy+2)
        var wd = this.textWidth(String(this._battler._sh));
        this.drawText(this._battler._sh, 16 - wd/2, wy, 40);
        this.drawText(text, 40, wy, this.contents.width, 'left');
    } else {
        this.drawText(text, 0, wy, this.contents.width, 'center');
    }

};

// Accessory functions
Game_Battler.prototype.modMaxSh = function (num) {
    this._mShB += num;
    this._mSh = this.getMaxSh();
    this._sh.clamp(0,this._mSh);
}

})()

The version spoiler'd here is 1.5.1 compatible.

There are 2 possibilities for showing shield amount, mode 0 is brackets and mode 1 is icons.
I could add an option for not showing numbers for actors or enemies or both. I'll likely patch that in a bit later.
thanks chap! will you update the patch here for that? no rush of course...looking forward to making a fancy 'BREAK' animation now lol
I'll continue using this thread for further releases until I feel like I'm done with it and then make a proper release thread most likely.
@Astfgl66
Along with the weakness display,
Another idea could be a common event linking the two.

The break state used could have a notetag that activates a common event when its inflicted.
If this link happened a lot of things could be possible, even a "BREAK" img.
Even though you did say it wouldn't be the best idea this would be incredibility useful.

EDIT

This can be achieved using the Buffs and States Core using this code in the state
<Custom Apply Effect>

$gameTemp.reserveCommonEvent(x);

</Custom Apply Effect>
The main problem with the weakness display I foresee is saving it for each monster type.
I can see a way of doing it with states, but saving it for every monster type would require an absurd amount of variables and states (1 per weakness of each monster type).
Truly this is something you'd be better off using a plugin for.

And yes I fully intend you to use script calls for visual effects and sounds when breaking an enemy, that's why I linked the script call equivalent of event commands thread in my first post in this thread.

Edit: sneak peek at what's coming next:
Spoiler
YYcCyav.jpg

I had an epiphany and figured out a way that took me much less time than anticipated so I went and did it.
That bat is weak to everything so the display is huge, but it scales with the number of weaknesses don't worry.
@Astfgl66

LOL and I just made a request thread for this!
This battle system is coming along quick, this will make it extremely like Octopath Traveler.
Using Srdude's Custom Battle Popups plugin, and StatePopups I found helps creating the "Break" and "Weakness" Visual part of the system.
Then using common events you can have a flash and sound when a break occurs.
@Astfgl66
Seems really cool when will the update be released?
I've updated this with the weakness display and parameters to allow for shields being used for only actors or enemies.
Get it here.

I think that's it. Barring any additional request or bug reports in the next few day, I'll make a proper plugin release thread and move on.

1.5.1 compatiblity version
Spoiler
Code:
//===================================================================================
// Astfgl's Shield counter and Break
// Date 19/08/2018
// Free to use non commercially, repost and
// edit, as long as the final product is kept under the same terms of use.
// Credits required, any of Astfgl, Astgfl (Pierre MATEO), Pierre MATEO
// Credits goes to yanfly for modified parts of battle engine core
// v1.0 19/08: release
// v1.1 21/08 modified shield display modes
// v1.2 25/08 created weakness display, added parameters for shield mode, made weakness display save
// Time spent : 6h
//====================================================================================

/*:
 * @plugindesc OT Shield and Break System
 * @author Astfgl
 *
 * @param globalMode
 * @text Shield usage
 * @type number
 * @default 0
 * @desc 0-> all, 1-> actors only -> 2 -> enemies only

 * @param defaultState
 * @text State Id when shield = 0
 * @type number
 * @default 4
 * @desc Which state will be applied when a battler shield reaches 0.
 *
 * @param defaultElemCutoff
 * @text Elemental weakness cutoff
 * @type number
 * @default 1
 * @desc Attacks must have an elemental value strictly superior to this to remove from the shield counter.
 *
 * @param baseIcon
 * @text Base shield Icon
 * @type number
 * @default 16
 * @desc The icon id to display shields.
 *
 * @param mode
 * @text Shield display mode
 * @type number
 * @default 0
 * @desc 0->number in brackets, 1 -> number in icon
 *
 * @param showWeaknesses
 * @text Show weaknesses below enemy name
 * @type number
 * @default 1
 * @desc 0-> don't show weaknesses, 1 -> show weaknesses
 *
 * @param wIArray
 * @text Weakness Icon Array
 * @default [0,0,0,0,0,0,0,0,0,0]
 * @desc Icons for each elemental weakness, in order from your elements list in the system tab with a leading "0,".
 *
 * @param defautWeaknessIcon
 * @text Undiscovered Weakness icon
 * @type number
 * @default 16
 * @desc The icon id that will be used to display undiscovered weaknesses.
 *
 *
 * @help
 *Allows you to set up a shield and break system similar to Octopath traveler's
 *Recommended plugins:
 * - Yanfly's Battle engine core
 * - Yanfly's Element core
 * - Yanfly's Buffs and state core
 *It has not been tested without these plugins and thus may not function.
 *
 *==========================================
 * What it does:
 *==========================================
 *In battle, if an attack hits an elemental weakness,
 *it will decrease a shield counter, once that counter reaches 0
 *a state will be applied to the battler.
 *
 *It will reduce the shield counter by 1 for each element of the attack
 *the recipient is weak to.
 *So if your attack deals fire and ice damage and the enemy is weak to both
 *shields will be reduced by 2.
 *
 *Display of the shield amount is done via the battler name in brackets or with an icon.
 *
 *It also creates a weakness icon array below the monster.
 *If the show weakness parameter is set to 1, it will display any element
 *weakness reaching the default cutoff with the icon corresponding to the defined id
 *in the weakness icon array below the battler name.
 *
 *==========================================
 * How to use:
 *==========================================
 *Set max shield notetags:
 *
 *Order for max shield calculation:
 *actor, class, equipment, passive states, states then floored
 *Notetags: <mSh: >, Ex: <mSh: num += 5>
 *
 *Each time calculations are made with the num variable.
 *Ex: num += 5 in actor, num *= 2 in class will result in a max shield of 10
 *The same thing but with a state using num = 1 will result in a max shield of 1
 *
 *Enemies are the same except you remove class and equipment calculations
 *
 *If you don't set anything, battlers have a default shield value of 1.
 *
 *If you want it to function like octopath traveler, I recommend
 *using a state with the cannot move property, set to expire in 2 turns
 *and with the following notetag:
 *<Custom Remove Effect>
 *user._sh = user._mSh;
 *</Custom Remove Effect>
 *This will restore shields to maximum when the broken state expires.
 *
 *==========================================
 * Changing break state
 *==========================================
 *If you want to change what state enemies are inflected with upon break use:
 *<DBS: > in an enemy note box
 *Else it will use what's inside plugin parameters
 *
 *==========================================
 * Modifying enemy shields:
 *==========================================
 * Use the following script calls:
 * (battler).modMaxSh(number)
 * This will add number to max shields, after all other calculations.
 * This bonus will never be reset.
 * Use states for temporary modifications for actors.
 *
 * (battler).changeSh(number), this will withdraw number from current shields
 *
 *All parameters and notetags are evaled
 *
 *==========================================
 * How to setup weakness display array:
 *==========================================
 *
 * The parametert is an array of icon ids with a leading 0.
 * For default projects it would be:
 * [0,physicalIconId,fireIconId,...,darknessIconId]
*/
var Astfgl = Astfgl || {};
Astfgl.enemies = Astfgl.enemies || {};
Astfgl.enemies.disWeak = [];

(function(){
//get parameters value
var defaultState = eval(PluginManager.parameters("AstfglSCB").defaultState);
var defaultElemCutoff = eval(PluginManager.parameters("AstfglSCB").defaultElemCutoff);
var mode = eval(PluginManager.parameters("AstfglSCB").mode)
var shieldIcon = eval(PluginManager.parameters("AstfglSCB").baseIcon)
var showWeaknesses = eval(PluginManager.parameters("AstfglSCB").showWeaknesses)
var wIArray =  eval(PluginManager.parameters("AstfglSCB").wIArray)
var defautWeaknessIcon = eval(PluginManager.parameters("AstfglSCB").defautWeaknessIcon)
var globalMode = eval(PluginManager.parameters("AstfglSCB").globalMode)

//Weakness setup
var _aliasGAI = Game_Actor.prototype.initialize
Game_Actor.prototype.initialize = function(actorId) {
    _aliasGAI.call(this,actorId);
    if (this._actorId === 0) {return}
    if (globalMode !== 2) {
    this._mShB = 0;
    this._mSh = this.getMaxSh();
    this._sh = this._mSh
    }
};

//get max shield value from notetags
Game_Actor.prototype.getMaxSh = function() {
    var num = 0;
    var a = this;
    var user = this;
    var id = this.actorId();
    if ($dataActors[id].meta.mSh) {
        num = eval($dataActors[id].meta.mSh)
    }
    if ($dataClasses[this._classId].meta.mSh) {
        num = eval($dataActors[id].meta.mSh)
    }
    for (var i = 0; i < this._equips.length; i++) {
        var it = this._equips[i];
        if (it._dataClass === "weapon" && it._itemId !== 0) {
            if ($dataWeapons[it._itemId].meta.mSh) {
                num = eval($dataWeapons[it._itemId].meta.mSh)
            }

        }
        if (it._dataClass === "armor" && it._itemId !== 0) {
            if ($dataArmors[it._itemId].meta.mSh) {
                num = eval($dataArmors[it._itemId].meta.mSh)
            }

        }
    }
    if (this._passiveStatesRaw) {
        for (var i = 0; i < this._passiveStatesRaw.length; i ++) {
            if ($dataStates[this._passiveStatesRaw[i]].meta.mSh) {
                num = eval($dataStates[this._passiveStatesRaw[i]].meta.mSh)
            }
        }
    }
    for (var i = 0; i < this._states.length; i ++) {
        if ($dataStates[this._states[i]].meta.mSh) {
            num = eval($dataStates[this._states[i]].meta.mSh)
        }
    }
    num +=     this._mShB
    num = Math.floor(num)
    if (num === 0 || isNaN(num)) {num = 1}
    return num
}

//setup enemies shield
var _aliasGEI = Game_Enemy.prototype.initialize
Game_Enemy.prototype.initialize = function(enemyId, x, y) {
    _aliasGEI.call(this,enemyId, x, y);
    if (this._enemyId === 0) {return};
    if (globalMode !== 1) {
        this._mShB = 0;
        this._mSh = this.getMaxSh()
        this._sh = this._mSh;
    }
    //create known weakness array the first time an enemy is initialized
    if (Astfgl.enemies.disWeak.length === 0) {
        for (var i = 0; i < $dataEnemies.length; i++) {
            var _WI = [];
            for (var i = 0; i < $dataSystem.elements.length; i ++) {
                _WI.push(0);
            }
        Astfgl.enemies.disWeak.push(_WI)
        }
    }

};

//get max enemy shield value from enemy and state notetags
Game_Enemy.prototype.getMaxSh = function() {
    var num = 0;
    var a = this;
    var user = this;
    var id = this._enemyId;
    if ($dataEnemies[id].meta.mSh) {
        num = eval($dataEnemies[id].meta.mSh)
    }
    if (this._passiveStatesRaw) {
        for (var i = 0; i < this._passiveStatesRaw.length; i ++) {
            if ($dataStates[this._passiveStatesRaw[i]].meta.mSh) {
                num = eval($dataStates[this._passiveStatesRaw[i]].meta.mSh)
            }
        }
    }
    for (var i = 0; i < this._states.length; i ++) {
        if ($dataStates[this._states[i]].meta.mSh) {
            num = eval($dataStates[this._states[i]].meta.mSh)
        }
    }
    num += this._mShB;
    num = Math.floor(num)
    if (num === 0 || isNaN(num)) {num = 1}
    return num
}

//store known weaknesses in global array
Game_Enemy.prototype.checkWeaknessDisplay = function (num) {
    if (Astfgl.enemies.disWeak[this._enemyId][num] === 0) {
        Astfgl.enemies.disWeak[this._enemyId][num] = 1
    }
}

//Action modifying
var _aliasGAA = Game_Action.prototype.apply
Game_Action.prototype.apply = function(target) {
    _aliasGAA.call(this,target)
    var mod = 0;
    var elements = this.getItemElements();
    for (var i = 0; i < elements.length; i++) {
        if (target.elementRate(elements[i]) > defaultElemCutoff) {
            mod +=1;
            if (!target.isActor()) {
                target.checkWeaknessDisplay(elements[i])
            }
        }
    }
    target.changeSh(mod);
}

Game_Battler.prototype.changeSh = function(num) {
    if (this._sh === 0) {return}
    if (globalMode === 2 && this.isActor()) {return}
    if (globalMode === 1 && this.isEnemy()) {return}
    this._sh -= num;
    this._sh = this._sh.clamp(0,this._mSh);
    if (this._sh === 0) {
        if (this.isActor()) {if ($dataActors[this.actorId()].meta.DBS) {defaultState = eval($dataActors[this.actorId()].meta.DBS)}}
        else {if ($dataEnemies[this._enemyId].meta.DBS) {defaultState = eval($dataEnemies[this._enemyId].meta.DBS)}}
        this.addState(defaultState)
    };
}

/*
//Modify name function to display shield amount
var _aliasGEN = Game_Enemy.prototype.name
Game_Enemy.prototype.name = function() {
    if ( mode === 0 ) {return _aliasGEN.call(this); }
    return "[" + this._sh + "]" + this.originalName() + (this._plural ? this._letter : '');
}*/

//Modify battle window draw name function to display shield amount
var _aliasWBSDAN = Window_BattleStatus.prototype.drawActorName
Window_BattleStatus.prototype.drawActorName = function(actor, x, y, width) {
    if (globalMode === 2) {_aliasWBSDAN.call(this,actor,x,y,width); return}
    width = width || 168;
    this.changeTextColor(this.hpColor(actor));
    if (mode === 1) {
        var fs = this.contents.fontSize
        this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
        this.drawIcon(shieldIcon,x,y+3)
        var wd = this.textWidth(String(actor._sh));
        this.drawText(actor._sh, x + 16 - wd/2, y, 40);
        this.contents.fontSize = fs
        this.drawText(actor.name(), x + 40, y, width - 48);
    } else {
        this.drawText("["+ actor._sh + "]" + actor.name(), x, y, width);
    }
}

//Modify enemy name display
var _aliasWEVS = Window_EnemyVisualSelect.prototype.refresh
Window_EnemyVisualSelect.prototype.refresh = function() {
    this.contents.clear();
    if (!this._battler) return;
    if (!this._showEnemyName) return;
    if (this._battler.isHidden()) return;
    this._requestRefresh = false;
    this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
    var text = this._battler.name();
    var wy = this.contents.height - this.lineHeight() * 2;
    if (globalMode !== 1) {
    if (mode === 1) {
            this.drawIcon(shieldIcon,0,wy+3)
            var wd = this.textWidth(String(this._battler._sh));
            this.drawText(this._battler._sh, 16 - wd/2, wy, 40);
            this.drawText(text, 40, wy, this.contents.width, 'left');
        } else {
            this.drawText("[" + this._battler._sh + "]" + text, 0, wy, this.contents.width, 'center');
        }
    } else {
        this.drawText(text, 0, wy, this.contents.width, 'center');
    }
  
    if (showWeaknesses === 1) {
        var elemWeak = [];
        for (var i = 1; i < $dataSystem.elements.length; i++) {
            if (this._battler.elementRate(i) > defaultElemCutoff) {
                elemWeak.push(i)
            }
        }
        wy = wy + this.lineHeight();
        if (this.width < 32 * elemWeak.length) {
            this.width = 32 * elemWeak.length
            this.contents.width = 32 * elemWeak.length
        }
        var x = 0;
        for (var i = 0; i < elemWeak.length; i++) {
            var iconId = defautWeaknessIcon;
            if (Astfgl.enemies.disWeak[this._battler._enemyId][elemWeak[i]] === 1) {
                iconId = wIArray[elemWeak[i]];
            }
            this.drawIcon(iconId,x,wy)
            x += 32;
        }
    }

};

//change window size to display the right width for weaknesses icons
Window_EnemyVisualSelect.prototype.updateWindowSize = function() {
    if (showWeaknesses === 1) {
        var elemWeak = [];
        for (var i = 1; i < $dataSystem.elements.length; i++) {
            if (this._battler.elementRate(i) > defaultElemCutoff) {
                elemWeak.push(i)
            }
        }
        var num = elemWeak.length * 32;
    } else {
        num = 0;
    }
    var spriteWidth = this._battler.spriteWidth();
    this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
    if (this._nameTextWidth === undefined) {
      this._nameTextWidth = this.textWidth(this._battler.name());
    }
    var textWidth = this._nameTextWidth;
    textWidth += this.textPadding() * 2;
    var width = Math.max(spriteWidth, textWidth, num) + this.standardPadding() * 2;
    width = Math.ceil(width);
    var height = this._battler.spriteHeight() + this.standardPadding() * 2;
    height = Math.ceil(height);
    height = Math.max(height, this.lineHeight() + this.standardPadding() * 2);
    if (width === this.width && height === this.height) return;
    this.width = width;
    this.height = height;
    this.createContents();
    this._requestRefresh = true;
    this.makeWindowBoundaries();
};

// Accessory functions
Game_Battler.prototype.modMaxSh = function (num) {
    if (globalMode === 2 && this.isActor()) {return}
    if (globalMode === 1 && this.isEnemy()) {return}
    this._mShB += num;
    this._mSh = this.getMaxSh();
    this._sh.clamp(0,this._mSh);
}

//save and lot weakness array
var _aliasDMMSC = DataManager.makeSaveContents
DataManager.makeSaveContents = function() {
    var contents = _aliasDMMSC.call(this)
    contents.astfgl = Astfgl
    return contents
}

var _aliasDMESC = DataManager.extractSaveContents
DataManager.extractSaveContents = function(contents) {
    _aliasDMESC.call(this,contents);
    Astfgl = contents.astfgl
}
})()

Original thread: https://forums.rpgmakerweb.com/threads/octopath-travelers-battle-system-plugin-request.99014/