Restoring Lost Items After a Defeat

residntevl

Blideo games
Veteran
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
  • 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>
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?
  • 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:

Zed_Walker

Warper
Member
Joined
Aug 29, 2019
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
oh thanks for that i really appreciate it ..... I wanted it for my own game but i wasnt able but thanks to you , now i can !
 

Zed_Walker

Warper
Member
Joined
Aug 29, 2019
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hey but i have a problem of my own so could you help me ??
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
If you have a problem following this tutorial, you should state what it is so you can be helped. If you have a problem with something else, you need to post it in the Support forum for the engine you're using, as asking it here would be hijacking the thread.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
[dpost]Zed_Walker[/dpost]
If you want to add something, use the Edit button on your earlier post and add the additional info or query.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,986
Members
137,561
Latest member
visploo100
Top