Enemy Thieves (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.


Ever wanted to create an effect where enemy thieves can steal from the player party? Using this tips & tricks video tutorial, you can!

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.

Copy and Paste version of the code along with explanations of what each line does~

<After Eval>
if (user.isEnemy()) {
  // Determine the success rate of stealing.
  var successRate = 0.5;
  // Check to see if the steal passes.
  if (Math.random() < successRate) {
    // Create an empty pool for what are valid items.
    var items = [];
    // Let's get the length of the all items in the player's party.
    var total = $gameParty.items().length;
    // A for-loop is used to check each of those items.
    for (var i = 0; i < total; ++i) {
      // Define each item for checking.
      var item = $gameParty.items()[i];
      // Check to see if the item is NOT a key item.
      if (item.itypeId !== 2) {
        // If it isn't a key item, add it to the legal pool.
        items.push(item);
      }
    }
    // Check if there are enough items.
    if (items.length > 0) {
      // Get a random number based on the size of the item pool.
      var random = Math.floor(Math.random() * items.length);
      // Get a random item by using that random number.
      var item = items[random];
      // Have the player party lose 1 of that item.
      $gameParty.loseItem(item, 1);
      // Create a message to let the player know what item was stolen.
      var text = user.name() + ' stole ' + item.name + ' from the party!';
      // Let's play a sound effect!
      SoundManager.playEquip();
    }
  } else {
    // The steal attempt has failed. Make a message to indicate it.
    var text = user.name() + ' failed to steal an item!';
    // Play a sound effect to indicate failure.
    SoundManager.playBuzzer();
  }
  // Get the battle log menu from the battle scene.
  var window = SceneManager._scene._logWindow;
  // Make that text show up in the battle log. Let's center it, too.
  window._lines.push(text + '<CENTER>');
  // And finally, let's refresh that battle log window to display it.
  window.refresh();
}
</After Eval>

Enjoy the effect!