- 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:
