Advertisement
ezmash

Kill Counter (MV)

Feb 15th, 2016
2,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==============================================================================
  2. // Kill Counter
  3. // by Shaz
  4. // Last Updated: 2016.02.15
  5. //==============================================================================
  6.  
  7. /*:
  8.  * @plugindesc Allows you to track number of enemies killed
  9.  * @author Shaz
  10.  *
  11.  * @help
  12.  * This plugin allows you to track, in a variable, the number of a certain
  13.  * type of enemy killed.  It only increments to the maximum number of enemies
  14.  * required.
  15.  *
  16.  * Plugin Commands:
  17.  * StartKillCounter enemyId variableId maxRequired - tracks kills in specified variable
  18.  * EndKillCounter enemyId - stops counting kills
  19.  *
  20.  * enemyId - the id (no leading zeros) of the enemy to be counted
  21.  * variableId - the id (no leading zeros) of the variable to hold the kill count
  22.  * maxRequired - how many enemies are required, in total - default is 0, which
  23.  *               means no limit
  24.  */
  25.  
  26. (function() {
  27.   var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  28.   Game_Interpreter.prototype.pluginCommand = function(command, args) {
  29.     switch(command.toUpperCase()) {
  30.       case 'STARTKILLCOUNTER':
  31.         $gameParty.startKillCounter(eval(args[0]), eval(args[1]), eval(args[2] || 0));
  32.         break;
  33.       case 'ENDKILLCOUNTER':
  34.         $gameParty.endKillCounter(eval(args[0]));
  35.         break;
  36.       default:
  37.         _Game_Interpreter_pluginCommand.call(this, command, args);
  38.     }
  39.   };
  40.  
  41.   var _Game_Party_initialize = Game_Party.prototype.initialize;
  42.   Game_Party.prototype.initialize = function() {
  43.     _Game_Party_initialize.call(this);
  44.     this._killCounter = [];
  45.   };
  46.  
  47.   Game_Party.prototype.startKillCounter = function(enemyId, variableId, maxRequired) {
  48.     if (!this._killCounter)
  49.       this._killCounter = [];
  50.  
  51.     if (!maxRequired)
  52.       maxRequired = 0;
  53.  
  54.     if (enemyId > 0)
  55.       this._killCounter[enemyId] = [variableId, maxRequired];
  56.   };
  57.  
  58.   Game_Party.prototype.endKillCounter = function(enemyId) {
  59.     if (this._killCounter && enemyId > 0)
  60.       this._killCounter[enemyId] = null;
  61.   };
  62.  
  63.   Game_Party.prototype.incrementKillCounter = function(enemyId) {
  64.     if (this._killCounter && enemyId > 0 && this._killCounter[enemyId]) {
  65.       killVar = this._killCounter[enemyId][0];
  66.       killLimit = this._killCounter[enemyId][1];
  67.       if (killVar && (killLimit === 0 || killLimit > $gameVariables.value(killVar)))
  68.         $gameVariables.setValue(killVar, $gameVariables.value(killVar) + 1);
  69.     }
  70.   }
  71.  
  72.   var _Game_Enemy_performCollapse = Game_Enemy.prototype.performCollapse;
  73.   Game_Enemy.prototype.performCollapse = function() {
  74.     _Game_Enemy_performCollapse.call(this);
  75.     $gameParty.incrementKillCounter(this._enemyId);
  76.   }
  77.  
  78. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement