MZ A way for enemies to steal from the player.

I've seen Yanfly provide a way to make this work in his plugin for MV. But nobody's even asked for this for MZ. I did send a request to VisuStella to replicate this feature in their plugin, but it's been a while since I asked and they still haven't done it so far. Is there some other method to do this in the meantime?
Put this code in the "Steal" skill(s)'s notes:
Code:
//For enemies
<JS Post-Apply>
  if (user.isEnemy()) {
    const successRate = 0.5;
    if (Math.random() < successRate) {
      let items = [];
      const total = $gameParty.items().length;
      for (let i = 0; i < total; ++i) {
        const item = $gameParty.items()[i];
        if (item.itypeId !== 2) {
          items.push(item);
        }
      }
      if (items.length > 0) {
        const random = Math.randomInt(items.length);
        const item = items[random];
        $gameParty.loseItem(item, 1);
        $gameVariables.value(2).push(item.id);
        var text = user.name() + ' stole ' + item.name + ' from the party!';
        AudioManager.playSe({name: "item-02", volume: 90, pan: 0, pitch: 100});
      }
    } else {
      var text = user.name() + ' failed to steal an item!';
      AudioManager.playSe({name: "miss_new", volume: 90, pan: 0, pitch: 100});
    }
    const window = SceneManager._scene._logWindow;
    if (text) {
      window.addStealText(text + '<CENTER>');
      interpreter.wait(800);
    }
  }
</JS Post-Apply>

You can replace "item-02" and "miss_new" with your own sfx.
The code is working, but the message for when an enemy successfully steals an item doesn't show up, nor does any sound play. That isn't the case if the enemy fails, however.
The message is on the top of the screen:
Screenshot 2025-08-13 134645.png


As for the sounds, like I said, you'll have to replace "item-02" and "miss_new" with the names of your own sfx.
I've seen Yanfly provide a way to make this work in his plugin for MV. But nobody's even asked for this for MZ.
just as a note, Trihan has a thread for visustella ports of yanfly's tips and tricks. no idea if he did them all, but the thief one was already there
just as a note, Trihan has a thread for visustella ports of yanfly's tips and tricks. no idea if he did them all, but the thief one was already there
Yo, that's super nice! Thanks for sharing.
The message is on the top of the screen:
View attachment 347343

As for the sounds, like I said, you'll have to replace "item-02" and "miss_new" with the names of your own sfx.
I believe I had the sound replacing "item-02" correct. Yet the message didn't pop up along with the sound still not playing.
Doesn't matter though, the link Robro33 provided has what I was looking for and it works well. Thanks for your help either way.

Original thread: https://forums.rpgmakerweb.com/threads/a-way-for-enemies-to-steal-from-the-player.179558/