residntevl

Blideo games
Veteran
Joined
Jul 30, 2012
Messages
38
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,544
Reaction score
14,852
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,333
Reaction score
11,758
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.
 

Latest Threads

Latest Profile Posts

When there's a will, there's a lifehack. :ninja:

Before i mess with battle UI further, does it look decent enough? :hswt:
Free MZ? That's good. I should go try it out then.
Let's see if I can make it in time xD
Knipsel.PNG

Forum statistics

Threads
112,523
Messages
1,068,911
Members
146,204
Latest member
Sailiv
Top