Lightning Rod (MV Plugin Tips & Tricks)

From Yanfly.moe Wiki
Jump to navigation Jump to search

Welcome to the wiki! This is where you can find resources from Yanfly.moe, Ækashics.moe,
VisuStella, Caz Wolf, Fallen Angel Olivia, Atelier Irina, and other affiliated content creators.


Lightning Rod is an ability in Pokémon that will draw thunder attacks towards a unit. This time, we’ll make it draw those attacks and nullify it, too, using the power of auras!

Required Plugins

The following plugin(s) is required to create this Tips & Tricks effect:

For help on how to install plugins, click here.

For help on how to update plugins, click here.

About

This is a Tips & Tricks effect created for RPG Maker MV. Tips & Tricks are not to be confused with plugins. Instead, they are usually customized code created for the sake of producing unique features/effects that do not require an entire plugin to do.

Yanfly Engine Plugins

This Tips & Tricks effect is made possible due to the Yanfly Engine Plugins library.

Click here if you want to help support Team Yanfly on Patreon.

Instructions

Follow video instructions.

You can grab the copy/paste code here:

Insert the following code into the origin state’s notebox. Change the values to reflect your game’s settings.
<Custom React Effect>
// Check if HP damage is dealt
if (this.isHpEffect() && value > 0) {
  // Get the lightning element's ID
  var lightningId = 9;
  // Get the action's current elements
  var elements = this.getItemElements();
  // Check if the elements contains lightning
  if (elements.contains(lightningId)) {
    // Set damage dealt to 0
    value = 0;
    // Get the parameter to alter
    var paramId = 4;
    // Set how long the buff will last
    var turns = 5;
    // Apply the buff to the target
    target.addBuff(paramId, turns);
    // Play an animation on the target
    target.startAnimation(51);
  }
}
</Custom React Effect>
Insert the following code in the aura effect that alters foes. Change the values to reflect the game’s settings.
<Custom Action Start Effect>
// Get the current action.
var action = user.currentAction();
// Check if the action exists and targets an opponent.
if (action && action.isForOpponent()) {
  // Get the lightning element ID.
  var lightningId = 9;
  // Get the Lightning Rod origin state ID.
  var lightningRod = 229;
  // Get the action's elements.
  var elements = action.getItemElements();
  // Check if the elements contain Lightning.
  if (elements.contains(lightningId)) {
    // If the do, create a new pool.
    var pool = [];
    // Get the opponent's unit's alive members.
    var group = user.opponentsUnit().aliveMembers();
    // Loop through each one.
    for (var i = 0; i < group.length; ++i) {
      // Get the currently looped member.
      var member = group[i];
      // Check if the member exists and is a Lightning Rod origin.
      if (member && member.isStateAffected(lightningRod)) {
        // Add that member to the pool.
        pool.push(member);
      }
    }
    // Check if the pool's size is larger than 0.
    if (pool.length > 0) {
      // Get a random Lightning Rod origin from the pool.
      var rod = pool[Math.floor(Math.random()* pool.length)]
      // Set the action's target to the Lightning Rod origin.
      action.setTarget(rod.index());
    }
  }
}
</Custom Action Start Effect>
Insert the following notetags in the aura effect that alter allies.
<Null Physical Taunt>
<Null Magical Taunt>
<Null Certain Taunt>

Enjoy!