MV YEP_StealSnatch - Enemies stealing Weapons and Armor

Hello!


Yanfly has a Tips & Tricks video using their Steal & Snatch plugin that explains how to have enemies steal Items from the Party, while also allowing for the Party to steal those same Items back.
Unfortunately, the video only accounts for Items and not, say– Weapons, or Armor.

I’ve researched a few threads on this issue, but both came to a dead-end.
(The second thread is close, but still doesn’t allow for the Party to steal the Weapon back.)

So I was wondering if anyone would be willing to tweak Yanfly’s original code used in the “Enemy Thieves Remade” video, but instead of stealing Items, the enemies are able to steal both Weapons and Armor (including currently equipped)? And the Party can steal those Weapons and Armor back?

If it has to be two separate skills, one for Weapons and one for Armor, that’s perfectly fine!


Thanks in advance!


Resources:

Yanfly’s Steal & Snatch Plugin:

Yanfly’s “Enemy Thieves Remade” Tips & Tricks:
Request Thread 1:
Request Thread 2:
try this. ive gave it a cursory test, but it looks like it works from what ive seen. thisll let you steal the currently worn equipment off of actors and let you steal it back

Spoiler: Yoink
Code:
<After Eval>
if (user.isEnemy()) {
    // Determine the success rate of stealing.
    var successRate = .5;
    // Check to see if the steal passes.
    if (Math.random() < successRate) {
      // Create an empty pool for what are valid equips.
      var equips = [];
      // Let's get the length of the all items in the actor's equips.
      var total = target._equips.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 equip = target._equips[i];
        // Check to see if the equip slot isnt empty
        if (equip._itemId != 0) {
          // If it isn't add it to the legal pool.
          equips.push(equip);
        }
      }
      // Check if there are enough items.
      if (equips.length > 0) {
        // Get a random equip from the item pool.
        var random = equips[Math.randomInt(equips.length)];
        // Find the actor's equip slot that matches
        random = target._equips.indexOf(random);
        // Find the equip inside actor's equip list
        equip = target._equips[random];
        // Check equip type
        if (equip._dataClass == "armor"){
          // Have the actor unequip equip.
          equip = $dataArmors[equip._itemId];
          target.changeEquip(random, null);
          // Remove one equip from party
          $gameParty.loseItem(equip, 1);
          // Create a message to let the player know what item was stolen.
          var text = user.name() + ' stole ' + equip.name + ' from '+target.name()+'!';
          // Let's play a sound effect!
          SoundManager.playEquip();
          // Create the stolen item with a 50% rate to steal it back
          var stealableItem = {
            type: 'armor',
            id: equip.id,
            rate: 0.5,
            isStolen: false,
            isDrop: false
          }
        }
      
        else{
          // Have the actor unequip equip.
          equip = $dataWeapons[equip._itemId];
          target.changeEquip(random, null);
          // Remove one equip from party
          $gameParty.loseItem(equip, 1);
          // Create a message to let the player know what item was stolen.
          var text = user.name() + ' stole ' + equip.name + ' from '+target.name()+'!';
          // Let's play a sound effect!
          SoundManager.playEquip();
          // Create the stolen item with a 50% rate to steal it back
          var stealableItem = {
            type: 'weapon',
            id: equip.id,
            rate: 0.5,
            isStolen: false,
            isDrop: false
          }
        }
        //  Add the stealable item to the enemy's pool
        user._stealableItems.push(stealableItem);
      } else {
        // Create a message to let the player know what item was stolen.
        var text = target.name()+' has nothing to steal!';
        // Let's play a sound effect!
        SoundManager.playBuzzer();
      }
    } 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 wait time
    var wait = 90;
    // Center the text
    text = '<CENTER>' + text;
    // Display the text.
    BattleManager.addText(text, wait);
}
</After Eval>
try this. ive gave it a cursory test, but it looks like it works from what ive seen. thisll let you steal the currently worn equipment off of actors and let you steal it back

Spoiler: Yoink
Code:
<After Eval>
if (user.isEnemy()) {
    // Determine the success rate of stealing.
    var successRate = .5;
    // Check to see if the steal passes.
    if (Math.random() < successRate) {
      // Create an empty pool for what are valid equips.
      var equips = [];
      // Let's get the length of the all items in the actor's equips.
      var total = target._equips.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 equip = target._equips[i];
        // Check to see if the equip slot isnt empty
        if (equip._itemId != 0) {
          // If it isn't add it to the legal pool.
          equips.push(equip);
        }
      }
      // Check if there are enough items.
      if (equips.length > 0) {
        // Get a random equip from the item pool.
        var random = equips[Math.randomInt(equips.length)];
        // Find the actor's equip slot that matches
        random = target._equips.indexOf(random);
        // Find the equip inside actor's equip list
        equip = target._equips[random];
        // Check equip type
        if (equip._dataClass == "armor"){
          // Have the actor unequip equip.
          equip = $dataArmors[equip._itemId];
          target.changeEquip(random, null);
          // Remove one equip from party
          $gameParty.loseItem(equip, 1);
          // Create a message to let the player know what item was stolen.
          var text = user.name() + ' stole ' + equip.name + ' from '+target.name()+'!';
          // Let's play a sound effect!
          SoundManager.playEquip();
          // Create the stolen item with a 50% rate to steal it back
          var stealableItem = {
            type: 'armor',
            id: equip.id,
            rate: 0.5,
            isStolen: false,
            isDrop: false
          }
        }
     
        else{
          // Have the actor unequip equip.
          equip = $dataWeapons[equip._itemId];
          target.changeEquip(random, null);
          // Remove one equip from party
          $gameParty.loseItem(equip, 1);
          // Create a message to let the player know what item was stolen.
          var text = user.name() + ' stole ' + equip.name + ' from '+target.name()+'!';
          // Let's play a sound effect!
          SoundManager.playEquip();
          // Create the stolen item with a 50% rate to steal it back
          var stealableItem = {
            type: 'weapon',
            id: equip.id,
            rate: 0.5,
            isStolen: false,
            isDrop: false
          }
        }
        //  Add the stealable item to the enemy's pool
        user._stealableItems.push(stealableItem);
      } else {
        // Create a message to let the player know what item was stolen.
        var text = target.name()+' has nothing to steal!';
        // Let's play a sound effect!
        SoundManager.playBuzzer();
      }
    } 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 wait time
    var wait = 90;
    // Center the text
    text = '<CENTER>' + text;
    // Display the text.
    BattleManager.addText(text, wait);
}
</After Eval>
This works perfectly, thank you for the help! 👋
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/yep_stealsnatch-enemies-stealing-weapons-and-armor.165907/