- Joined
- Jul 30, 2012
- Messages
- 37
- Reaction score
- 29
- First Language
- English
- Primarily Uses
- RMMV
Have you ever been playing a game with a feature that returns you to some safe place after battle?
What about maybe you're in a Dream Sequence and you lose the fight. You also lose all the really powerful healing items you said you'd never use until you really had to use them.
With this neat trick you can allow the items used in combat to be restored the player in the event of a Battle Loss.
Requirements
Yanfly Auto Passive States
SRD Battle End Events
Any other Dependencies (such as Yanfly's Core Engine/SRD Core Engine) should be added to your project as well.
Steps
Next we add the code for the Lose Condition. Upon a loss, we will restore all items that were consumed in battle back to the player. Safety valves are pretty neat, yeah?
*For the sake of redundancy, you can add $gameParty.leader()._itemsUsed = []; into a win condition to wipe the array of items. This is redundant as the array is wiped at the start of each battle.
**If you are not using SRD_BattleEndEvents and you do not use any random encounters in your game, you may instead opt to add the Lose Common Event to the Lose Condition under Battle Processing in the events that call it.
***This will not work if you are using Independent Items with Yanfly's Item Core.
What about maybe you're in a Dream Sequence and you lose the fight. You also lose all the really powerful healing items you said you'd never use until you really had to use them.
With this neat trick you can allow the items used in combat to be restored the player in the event of a Battle Loss.
Requirements
Yanfly Auto Passive States
SRD Battle End Events
Any other Dependencies (such as Yanfly's Core Engine/SRD Core Engine) should be added to your project as well.
Steps
- Create a Passive State in the States tab. You may name it whatever you wish.
- In your plugin manager add the state to the list of Actor Passives in YEP_AutoPassiveStates.
- Inside the state you just created, add this code:
Code:
<Custom Battle Effect>
// Reset the Array at the start of battle.
// Store the items used into the Leader's Actor Variable.
$gameParty.leader()._itemsUsed = [];
</Custom Battle Effect>
<Custom Action Start Effect>
// Check if the user is using an item.
if (user.currentAction()._item._dataClass === 'item') {
// Check if the item is a consumable which can be lost
if ($dataItems[user.currentAction()._item._itemId].consumable === true) {
// Add the item into the Array
$gameParty.leader()._itemsUsed.push(user.currentAction()._item._itemId);
}
}
</Custom Action Start Effect>
- Create a common event for the lose condition. Name it whatever you want.
- In your plugin manager add the common event ID to the Lose Common Event parameter in SRD_BattleEndEvents.
- Inside of the common event you just created, add this in a Script Call event:
Code:
for (var i = 0; i < $gameParty.leader()._itemsUsed.length; i++) {
$gameParty.gainItem($dataItems[$gameParty.leader()._itemsUsed[i]], 1, false);
}
// Clear the Array
$gameParty.leader()._itemsUsed = [];
*For the sake of redundancy, you can add $gameParty.leader()._itemsUsed = []; into a win condition to wipe the array of items. This is redundant as the array is wiped at the start of each battle.
**If you are not using SRD_BattleEndEvents and you do not use any random encounters in your game, you may instead opt to add the Lose Common Event to the Lose Condition under Battle Processing in the events that call it.
***This will not work if you are using Independent Items with Yanfly's Item Core.
Last edited:


