Save-Point
KMessageTarget MV 2 Versions - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Plugins and Mods (https://www.save-point.org/forum-74.html)
+---- Forum: RPGMaker MV/MZ Engines (https://www.save-point.org/forum-120.html)
+---- Thread: KMessageTarget MV 2 Versions (/thread-8664.html)



KMessageTarget MV 2 Versions - kyonides - 01-30-2023

KMessageTarget MV
2 Versions

by Kyonides Arkanthes

Introduction

By default the Battle Log doesn't expect you to add a target's name to a skill action message. This plugin changes that to make sure you can certainly read who's the hero's current target.

Please read the instructions embedded in the plugins.

Simple Version

Code:
//===========================================
// * KMessageTargetMV.js - Simple Version
//===========================================
/*:
* @plugindesc This plugin will let you add the enemy's name to a skill's
* action message by using a tag or wildcard.
* @author Kyonides Arkanthes
* @help Date: 2023-01-30
* # * Free as in beer. * #
* The regular expression or regex is %e by default.
*/

function KMessageTarget() {
  throw new Error('This is a static class');
}

KMessageTarget.regex = /%e/i;

Window_BattleLog.prototype.displaySkillTargets = function(subject, item, targets) {
  let target = 0;
  let msg = "";
  for (var i = 0; i < targets.length; i++) {
    target = targets[i];
    if (item.message1) {
      msg = subject.name() + item.message1.format(item.name);
      msg = msg.replace(KMessageTarget.regex, target.name());
      this.push('addText', msg);
    }
    if (item.message2) {
      this.push('addText', item.message2.format(item.name));
    }
  }
}

const KMessageTarget_win_btl_log_displayAction = Window_BattleLog.prototype.displayAction;

Window_BattleLog.prototype.displayAction = function(subject, item, targets) {
  if (DataManager.isSkill(item)) {
    this.displaySkillTargets(subject, item, targets);
  } else {
    KMessageTarget_win_btl_log_displayAction.call(subject, item);
  }
};

Window_BattleLog.prototype.startAction = function(subject, action, targets) {
  let item = action.item();
  this.push('performActionStart', subject, action);
  this.push('waitForMovement');
  this.push('performAction', subject, action);
  this.push('showAnimation', subject, targets.clone(), item.animationId);
  this.displayAction(subject, item, targets);
};

Full Version

Code:
//===========================================
// * KMessageTargetMV.js - Full Version
//===========================================
/*:
* @plugindesc This plugin will let you add the enemy's name to a skill's
* action message by using a tag or wildcard.
* @author Kyonides Arkanthes
* @help Date: 2023-01-30
* # * Free as in beer. * #
*
* The regular expressions or regex are
*  %a for an Actor or Ally
*  %e for an Enemy
*
* Note Tag: _party item_
* It allows your hero uses an item on all of his or her allies while preventing
* the Battle Log from repeating itself over and over again.
*
* You can customize the KMessageTarget.party_as_target string if necessary.
*/

function KMessageTarget() {
  throw new Error('This is a static class');
}

KMessageTarget.item_list = [1, 6];
KMessageTarget.actor_regex = /%a/i;
KMessageTarget.enemy_regex = /%e/i;
KMessageTarget.no_target_item = / on %a/i;
KMessageTarget.party_item = /_party item_/i;
KMessageTarget.party_as_target = "the party";

Window_BattleLog.prototype.displaySkillTargets = function(s_name, item, targets) {
  let target = 0;
  let msg = "";
  for (var i = 0; i < targets.length; i++) {
    target = targets[i];
    if (item.message1) {
      msg = s_name + item.message1.format(item.name);
      msg = msg.replace(KMessageTarget.actor_regex, target.name());
      msg = msg.replace(KMessageTarget.enemy_regex, target.name());
      this.push('addText', msg);
    }
    if (item.message2) {
      this.push('addText', item.message2.format(item.name));
    }
  }
}

Window_BattleLog.prototype.processNames = function(s_name, item, t_name) {
  let msg = TextManager.useItem.format(s_name, item.name);
  if (!KMessageTarget.item_list.includes(item.id)) {
    msg = msg.replace(KMessageTarget.no_target_item, "");
  }
  msg = msg.replace(KMessageTarget.actor_regex, t_name);
  this.push('addText', msg);
}

Window_BattleLog.prototype.displayItemTargets = function(s_name, item, targets) {
  if ( KMessageTarget.party_item.exec(item.note) ) {
    this.processNames(s_name, item, KMessageTarget.party_as_target);
    return;
  }
  let target = 0;
  for (var i = 0; i < targets.length; i++) {
    target = targets[i];
    this.processNames(s_name, item, target.name());
  }
}

Window_BattleLog.prototype.displayAction = function(subject, item, targets) {
  let numMethods = this._methods.length;
  if (DataManager.isSkill(item)) {
    this.displaySkillTargets(subject.name(), item, targets);
  } else {
    this.displayItemTargets(subject.name(), item, targets);
  }
  if (this._methods.length === numMethods) {
    this.push('wait');
  }
};

Window_BattleLog.prototype.startAction = function(subject, action, targets) {
  let item = action.item();
  this.push('performActionStart', subject, action);
  this.push('waitForMovement');
  this.push('performAction', subject, action);
  this.push('showAnimation', subject, targets.clone(), item.animationId);
  this.displayAction(subject, item, targets);
};

Side Note: There should be another regex that I could have used there, yet, I preferred to use a very specific one that people could quickly interpret as an enemy's name if they ever find it in the message box. We could say it's a very friendly reminder of what it actually stands for.

Terms & Conditions

Free as in beer.
Include my nickname in your game credits.
Read the instructions.
Do not repost it.