Basically what I want to do is: actor 1 enters the battle, he uses a skill that costs 10 mana, I want this skill to refund that 10 mana back at the end of the turn but only the first time it's used per battle. A second use of the skill would not refund that 10 mana back in the same battle. How would I go about doing this? Is it a damage formula thing? I should also mention that I'm using yanfly's action sequences if that makes this any easier.
Skill that refunds it's own mana cost but only the first time it's used?
RPG Maker MV SupportDo you use more yanfly events? YEP_BaseTroopEvents might be the solution.
You can do this:
Reserve a switch for this skill, lets call it switch X for this example
In the template troop defined in the plugin.
In this troop you need to make 1 even page triggered at turn 0 (before battle starts) turning off switch X.
Now, when go to the skill that you want to refund and make it trigger a new common event.
In this common event, check if the switch if off. If so, turn the switch on and give the casting player 10 MP.
You can do this:
Reserve a switch for this skill, lets call it switch X for this example
In the template troop defined in the plugin.
In this troop you need to make 1 even page triggered at turn 0 (before battle starts) turning off switch X.
Now, when go to the skill that you want to refund and make it trigger a new common event.
In this common event, check if the switch if off. If so, turn the switch on and give the casting player 10 MP.
Thank you for the reply. Turns out all I had to do to get the effect I wanted was actually to remove a line of code from another unrelated plugin that I was using for this skill.
First, pick an unused game switch (in this example it will be switch with id 1) and use following damage formula:
x is your actuall damage formula.
and after the battle ends set Switch ID#1 to OFF.
(Not tested, because I'm at hospital on phome)
Code:
$gameSwitches.value(1) ? a.gainMp(10); $gameSwitches.setValue(1, true); x : x
x is your actuall damage formula.
and after the battle ends set Switch ID#1 to OFF.
(Not tested, because I'm at hospital on phome)
You can do this without using Plug-ins or Coding as well, by using a Common Event that has a conditional branch to do with a new Switch you create for the Skill.
Attach a Common Event to the Skill in question:
Conditional Branch ~ When Switch "New Switch for Skill (NSS)" is On:
-
else (when NSS is Off):
- Actor 1 Change MP +10 MP
- Turn NSS On
end
- -
The drawback is you'd have to put in a common event in all of your battles (or after them) to turn off NSS again once the fight is over.
And you'd have to make the skill unique to each Actor, so if you wanted multiple Actors to know it then they'd have to have different entries in the Skill Database (so you can change the line "Actor 1 Change MP +10 MP" to Actor 2 or 3 or 4 or what have you, and apply different switches to them of course).
So it's probably easier with plug-ins, but it's definitely doable without too!
Attach a Common Event to the Skill in question:
Conditional Branch ~ When Switch "New Switch for Skill (NSS)" is On:
-
else (when NSS is Off):
- Actor 1 Change MP +10 MP
- Turn NSS On
end
- -
The drawback is you'd have to put in a common event in all of your battles (or after them) to turn off NSS again once the fight is over.
And you'd have to make the skill unique to each Actor, so if you wanted multiple Actors to know it then they'd have to have different entries in the Skill Database (so you can change the line "Actor 1 Change MP +10 MP" to Actor 2 or 3 or 4 or what have you, and apply different switches to them of course).
So it's probably easier with plug-ins, but it's definitely doable without too!
If you're still looking for a solution, I've had an idea using Yanfly's YEP_SkillCore and YEP_BuffsStatesCore that should work in a way where skill can be independently used by all battlers, without causing too much clutter in battle events or damage formulas.
First, you create a new state. You can customize it however you want, but it needs to not have an auto-removal timing, be removed on battle end and not be removed by restriction.
Give it a Custom Turn End Effect from the BuffsStateCore, like this:
This will refund the mana cost at the end of the turn, but only if there is mana to be refunded, which will only be after the first use of the skill.
You can remove the line
Second, you give the skill a Custom Execution Effect from the SkillCore, like this:
Here you replace the 5 with the index of the state you created in the first step.
If you don't want to use Skill Core (or can't), you can replicate the Custom Execution Effect using an Action Sequence, like this:
Also replace both 5's here with the appropriate state index.
First, you create a new state. You can customize it however you want, but it needs to not have an auto-removal timing, be removed on battle end and not be removed by restriction.
Give it a Custom Turn End Effect from the BuffsStateCore, like this:
Code:
<Custom Turn End Effect>
if (user.manaRefund > 0) {
user.gainMp(user.manaRefund);
user.startDamagePopup();
user.manaRefund = 0;
}
</Custom Turn End Effect>
You can remove the line
user.startDamagePopup(); if you don't want to display a popup for the refunded mana.Second, you give the skill a Custom Execution Effect from the SkillCore, like this:
Code:
<Custom Execution>
var stateId = 5; // index of the state you created
if (!user.isStateAffected(stateId)) {
user.manaRefund = item.mpCost;
user.addState(stateId);
}
</Custom Execution>
If you don't want to use Skill Core (or can't), you can replicate the Custom Execution Effect using an Action Sequence, like this:
Code:
if !user.isStateAffected(5)
eval: user.manaRefund = item.mpCost;
add state 5: user
end
Oh! Silly me, you can actually do this with a State instead of a Switch to make it much easier!
--
Create a new State that does nothing and gets removed on Battle End.
Then insert this Common Event onto the Skill in question:
Conditional Branch ~ When Actor 1 is affected by New State:
-
else (when Actor 1 is not affected by New State):
- Actor 1 Change MP +10 MP
- Apply New State to Actor 1
end
--
It really is as simple as that!
You'd still have to make each version of the Skill unique to each Actor in the Database if you wanted multiple Actors to learn the Skill. But this is a nice and clean way to do it without any plug-ins or coding or damage formula'ing too.
Wow. Great idea!
Thanks for saying!
Original thread: https://forums.rpgmakerweb.com/threads/skill-that-refunds-its-own-mana-cost-but-only-the-first-time-its-used.151849/