Giving the items back?

Fugama

Means well, but messes up sometimes.
Veteran
Joined
Jun 7, 2014
Messages
158
Reaction score
90
First Language
Fake English
Primarily Uses
RMMV
The situation is different, but essentially what I wanna do is take the yanfly enemy thief code and have it store a list of what's been stolen, and then have a function that takes that list and returns those items to the players inventory. How do? Yanfly code pasted below

Code:
<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>
 
Last edited by a moderator:

Fugama

Means well, but messes up sometimes.
Veteran
Joined
Jun 7, 2014
Messages
158
Reaction score
90
First Language
Fake English
Primarily Uses
RMMV
I found a previous entry that lets me save arrays and strings and such (which helps I think) However I'm not sure if there's a way for me to run the item gain code in like.... a batch based on the array size? 
 

Fugama

Means well, but messes up sometimes.
Veteran
Joined
Jun 7, 2014
Messages
158
Reaction score
90
First Language
Fake English
Primarily Uses
RMMV
Okay I figured it out after a long night of not sleeping. First, toss this code I got from another thread here into a plugin and slightly edited.


(function(){ var _GS_init = Game_System.prototype.initialize;
Game_System.prototype.initialize = function()
{ _GS_init.call(this); // Makes sure to do the stuff that was in the function before
this._stolenIds = []; // Adds in our own array.
this._myObject = {}; // Adds in a JS Object.
this._myNum = 0; // Adds in a Number.
this._myStr = ""; // Adds in a String.
this._myBool = true; // Adds in a boolean (true/false).
}


})();


Next up the edited version of the skill code from Yanfly


<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();
// 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);
//Push to list
$gameSystem._stolenIds.push(item.id)
// 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>


and then finally once you wanna return the items run this in a script event (if someone more JS savvy would like to edit this into a plugin command, well that'd be nice)

Code:
// for loop the item command
  for (i = 0; i < $gameSystem._stolenIds.length; i++) {
    $gameParty.gainItem($dataItems[$gameSystem._stolenIds[i]], 1)
}
                                              
  // reset the variable after returning the items
  $gameSystem._stolenIds = [];
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top