KMessageTarget MV

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.

Simple Version

JavaScript:
//===========================================
// * 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

JavaScript:
//===========================================
// * 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.
Seems to be incompatible with YEP Battle Engine.

YEP_CoreEngine.js:1098

TypeError: Cannot read property 'length' of undefined
at Window_BattleLog.displaySkillTargets (KMessageTargetMV.js:36)
at Window_BattleLog.displayAction (KMessageTargetMV.js:74)
at Function.BattleManager.actionDisplayAction (YEP_BattleEngineCore.js:2779)
at Function.BattleManager.processActionSequence (YEP_BattleEngineCore.js:2346)
at Function.BattleManager.processActionSequence (YEP_X_ActSeqPack1.js:882)
at Function.BattleManager.processActionSequence (YEP_X_ActSeqPack2.js:575)
at Function.BattleManager.processActionSequence (YEP_X_ActSeqPack3.js:473)
at Function.BattleManager.processActionSequence (VE_Throwable_BECPatch.js:11)
at Function.BattleManager.processActionSequence (YEP_DamageCore.js:1007)
at Function.BattleManager.processActionSequence (YEP_ElementCore.js:439)
You see, I'd never state nor expect that my plugin is compatible with any YEP stuff at all.
You see, I'd never state nor expect that my plugin is compatible with any YEP stuff at all.
To clarify, I'm not assuming that you would make your plugins compatible with YEP stuff at all even though it probably severely limits the usefulness of the plugin since many devs probably use YEP plugins. I'm just providing feedback on my experience using your plugin that I thought would be helpful to the plugin developer as well as other users on this site who may be interested in knowing that this plugin isn't compatible with YEP stuff.

ATT_Turan made a similar snippet that achieves the same effect and is compatible with YEP stuff. Feel free to DM and I'll send the link.
First of all it's DISRESPECTFUL to post other people's plugins or links to them on a scripter's topic, don't you think? Please remove the link, just the link.

Thanks for trying to offer some feedback here, but I don't care much about it when talking about MV. The reason is very simple: I've noticed that plugins that work well with native nw.js quickly break if you upgraded it manually. That's why I won't try to offer alternate versions.

Original thread: https://forums.rpgmakerweb.com/threads/kmessagetarget-mv.154542/