(Relatively) Simple Steal System Plugin for MZ

Update 05/09/2023 - This plugin is outdated and superceded by my much less buggy and much easier to use new steal plugin AUTMOUSE_Steal.js. Please use it instead.
---------------------------

Hello everyone. This is the first plugin I am releasing. I made it using CoffeeScript and have tested it on both an active project and a fresh project.

This plugin allows you to set up a steal skill that is powered by a common event. You create you steal lists per enemy using note tags. I went looking for a steal system but couldn't find any that were not part of larger systems so I decided to make my own.

It was hard! I learned so much, and I think it is a pretty useful little plugin. Let me know if you have questions. I am going to make a video tutorial for it this weekend. I am also thinking of making a video for those who are interested in making plugins using CoffeeScript. CoffeeScript is Ruby like and may be easier for some than js. It is for me.

JavaScript:
// Generated by CoffeeScript 2.7.0

//=============================================================================
// Simple Steal System for RPG Maker MZ
// penny_steal.js
// Copyright (c) 2022
//=============================================================================
/*:
* @target MZ
* @plugindesc Allows for the creation of a steal or mug skill.
* @author Penny Gautreaux
*
* @help AMMZ_Steal.js
*
* This plugin is some assembly required.
* Create a steal skill and configure it however you like.
* In the damage formula use the following:
* $gameVariables.setValue(20, b.enemyId()); ammzSteal.target = b; ammzSteal.user = a; (a.atk * 4 - b.def * 2) * 0.5
* Replace the number 20 with the number you set to targetVariable parameter
* The damage at the end (a.atk * 4 - b.def * 2) * 0.5 is optional.
* Change or remove it to change or remove damage output from the skill.
* the stuff before the final semicolon is required!
* Under actions have the skill run a common event.
*
* The Common Event should be set to Trigger None
* In the common event set the variable you used for Parameter targetItemVariable
* to choose a random number between 0 and 3
* The add a script event on page three with the following in the script:
* ammzSteal.steal()
*
* Next create two states a rareStealState and a alreadyStolenFrom state.
* You can call them whatever but make sure they correspond to the id you set in
* the parameters, e.g. if parameter says 32 it needs to be state 32.
*
* Rare stealing is ignored by default but you can enable by having an item or equip
* apply the state to the character using the steal skill.
*
* Lastly put notetags on every entry in your Enemies database.
* Even things that are not really enemies. It will crash if you don't
*
* <stealList:x,x,x,x> where x is a database id for an item.
* or
* <rareStealList:y,y,y,y> where y is a database id for an item that you want to be on the rare steal list.
*
* Examples
* <stealList:-1,-1,-1,-1> means nothing to steal
* <stealList:7,7,7,7> means only stealable item is item 7 in the database
* <rareStealList:23,23,24,24> means item 23 or 24 in the database may be stolen but only if rare steal is on.
*
*
*
* -License
* This plugin is distributed under the MIT license.
* Feel free to use it.
* http://opensource.org/licenses/mit-license.php
*
* @param targetVariable
* @type number
* @desc Choose a variable that will hold the id of the target of the skill.
* @text Variable to store target ID to.
* @default 20
*
* @param targetItemVariable
* @type number
* @desc Choose a variable that will hold the id of item being stolen.
* @text Variable to store stolen item ID to.
* @default 19
*
* @param rareStealState
* @type number
* @desc State that enables stealing from the rare steal list.
* @text Rare Steal State
* @default 33
*
* @param alreadyStolenFromState
* @type number
* @desc state for enemies that says they have already been stolen from.
* @text Already stolen from state
* @default 32
 */
var ammzSteal;

ammzSteal = ammzSteal || {};

ammzSteal.parameters = PluginManager.parameters('AMMZ_Steal');

ammzSteal.stealList = [null];

ammzSteal.rareStealList = [null];

ammzSteal.tempArray = [null];

ammzSteal.tempArray2 = [null];

ammzSteal.rareStealState = 33;

ammzSteal.alreadyStolenFromState = 32;
(function () {
  ammzSteal.setupSteal = function () {
    var counter, enemy, i, j, k, len, len1, len2, purse, ref, ref1, results;
    // Create an array of strings from meta tags in database
    counter = 1;
    for (i = 0, len = $dataEnemies.length; i < len; i++) {
      enemy = $dataEnemies[i];
      if (enemy !== null) {
        ammzSteal.tempArray.push(enemy.meta.stealList.split(','));
        ammzSteal.tempArray2.push(enemy.meta.rareStealList.split(','));
      }
    }
    ref = ammzSteal.tempArray;

    // Add enemy purses to Steal List
    for (j = 0, len1 = ref.length; j < len1; j++) {
      purse = ref[j];
      if (purse !== null) {
        ammzSteal.stealList.push(purse);
      }
    }
    ref1 = ammzSteal.tempArray2;

    // Add enemy purses to Rare Steal List
    results = [];
    for (k = 0, len2 = ref1.length; k < len2; k++) {
      purse = ref1[k];
      if (purse !== null) {
        results.push(ammzSteal.rareStealList.push(purse));
      } else {
        results.push(void 0);
      }
    }
    return results;
  };

  ammzSteal.steal = function () {
    // Get steal list from enemy
    ammzSteal.whichMonster = $gameVariables.value(parseInt(ammzSteal.parameters.targetVariable));
    ammzSteal.whichItem = $gameVariables.value(parseInt(ammzSteal.parameters.targetItemVariable));
    ammzSteal.rareStealState = parseInt(ammzSteal.parameters.rareStealState);
    ammzSteal.alreadyStolenFromState = parseInt(ammzSteal.parameters.alreadyStolenFromState);
    if (ammzSteal.user.isStateAffected(ammzSteal.rareStealState)) {
      ammzSteal.item = ammzSteal.rareStealList[ammzSteal.whichMonster][ammzSteal.whichItem];
    } else {
      ammzSteal.item = ammzSteal.stealList[ammzSteal.whichMonster][ammzSteal.whichItem];
    }
    ammzSteal.stealChance = Math.randomInt(101);
    if (ammzSteal.target.isStateAffected(ammzSteal.alreadyStolenFromState)) {
      $gameMessage.add("The enemy doesn't have anything else to steal.");
    } else if (ammzSteal.stealChance <= 50) {
      if (ammzSteal.item !== -1) {
        $gameParty.gainItem($dataItems[parseInt(ammzSteal.item)], 1);
        $gameMessage.add('You stole a ' + $dataItems[parseInt(ammzSteal.item)].name + '!');
        ammzSteal.target.addState(ammzSteal.alreadyStolenFromState);
      } else {
        $gameMessage.add("Nothing to steal...");
      }
    } else {
      $gameMessage.add('You were unable to grab anything.');
    }
  };

}).call(this);
I finished up the video instructions.
Great start to your plugin development journey! Implementing steal functionality via the damage formula seems overly-complicated, but we all had to begin somewhere and I'm sure you'll refine it as you learn more. 🙂
I don’t know how to get the target of the skill without the damage formula. I will keep learning and figure it out though! Thank you so much for the encouragement. 🙂
I don’t know how to get the target of the skill without the damage formula.
Instead of making all of your code in standalone functions, tie them into the game engine.

Tell the user to put a notetag on the skill that can steal things (e.g. <steal>).

Then copy the Game_Action.prototype.apply function into your plugin file.

Add a part in there, perhaps immediately after the for loop that calls applyItemUserEffect() and have it check the current action ("this") for the presence of the steal tag.

If it's there, call your steal function. You can pass in the current target - target - and the battler using the skill - this.subject() - and the user of the plugin doesn't need to finagle anything in the damage formula or any common events.

Similarly, no need for the user to take up state slots in their database. Just create a variable on the battler, like
Code:
target.stolenFrom=true;

and do it internally.

* Lastly put notetags on every entry in your Enemies database.
* Even things that are not really enemies. It will crash if you don't

I'm not sure what "things that are not really enemies" means, but this is again a lot of work put on the user. It's a simple if check for you to see whether a notetag exists before you try to access it. The user shouldn't need to do all that.
Love the video tutorial. Made it very clear how to set up and use the plugin.
Instead of making all of your code in standalone functions, tie them into the game engine.

Tell the user to put a notetag on the skill that can steal things (e.g. <steal>).

Then copy the Game_Action.prototype.apply function into your plugin file.

Add a part in there, perhaps immediately after the for loop that calls applyItemUserEffect() and have it check the current action ("this") for the presence of the steal tag.

If it's there, call your steal function. You can pass in the current target - target - and the battler using the skill - this.subject() - and the user of the plugin doesn't need to finagle anything in the damage formula or any common events.

Similarly, no need for the user to take up state slots in their database. Just create a variable on the battler, like
Code:
target.stolenFrom=true;

and do it internally.



I'm not sure what "things that are not really enemies" means, but this is again a lot of work put on the user. It's a simple if check for you to see whether a notetag exists before you try to access it. The user shouldn't need to do all that.
Thank you so much for this! It is a little more than I understand at a quick glance but I am sure it will help me make a better version of this plugin and better plugins in general once I understand it better.

Original thread: https://forums.rpgmakerweb.com/threads/relatively-simple-steal-system-plugin-for-mz.153818/