KMessageTarget MV 2 Versions
#1
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.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }




Users browsing this thread: 1 Guest(s)