MV Attempt to make a Skill that replicates skills.

Im trying to make a skill (We'll call it Qkill) that copies and performs the last skill an ally or enemy has used in combat, whatever the most recent skill before Qkill is selected was, gets used.
I wrote this but I dont know if its right, I have a few other things going on in this skill.

<Instant Cast>



<Custom Requirement>

value = $gameVariables.value(6) < 7;

</Custom Requirement>



<After Eval>

$gameVariables.setValue(6, $gameVariables.value(6) + 1);

</After Eval>



<Custom Action>

if (BattleManager._actionHistory && BattleManager._actionHistory.length > 0) {

var lastAction = BattleManager._actionHistory[BattleManager._actionHistory.length - 1];

var skill = lastAction.item();

if (skill && skill.id !== this.item().id) {

var targetIndex = lastAction._targetIndex >= 0 ? lastAction._targetIndex : 0;

BattleManager.forceAction(user, skill.id, targetIndex);

BattleManager._phase = 'input';

} else {

value = false;

}

} else {

value = false;

}

</Custom Action>



I was told to make this plugin to call upon a certain state so that it would work properly

(() => {
const _Game_Battler_useItem = Game_Battler.prototype.useItem;
Game_Battler.prototype.useItem = function(item) {
BattleManager._actionHistory = BattleManager._actionHistory || [];
BattleManager._actionHistory.push(this._actions[0]);
_Game_Battler_useItem.call(this, item);
};
})();


Please help.

I've moved this thread to Javascript/Plugin Support. Thank you.


Please mention the plugins that you are using to make this work. <Instant cast>, <custom requirement>, and <after eval> can be easily identified as being notetags for a few yanfly plugins, but where did <custom action> come from?

Also please use the [code][/code] tags when providing code here. Part of the automatic formatting text goes through is the removal of indenting, which makes it harder to read code
Thank you for your assistance, but I've decided to scrap the idea due to balance issues. A replication skill is too strong to balance around for my game's design and I've opted to remove it from my game.

Thank you for your speed and efficiency as always, Robro33. Love you, king.

Original thread: https://forums.rpgmakerweb.com/threads/attempt-to-make-a-skill-that-replicates-skills.179158/