Magic reflection fix plugin

Danitinkis

Deadly and sexy
Veteran
Joined
Dec 31, 2016
Messages
118
Reaction score
65
First Language
Spanish
Primarily Uses
RMMV
The magic reflection is not good at all. In FF3 (for example), when you use a reflect on a battler and that battler uses a magic skill to himself (like cure), it reflects to an enemy and cannon't be reflected again. However, in RPG Maker MV, the magic skill is reflected to the battler, not the enemy. Here are 2 videos:

FF3 Reflect:
RPG MAKER MV Reflect (Reflect is "Reflejo"):
I want to change the magic reflection of Rpg maker mv to make it like FF3. But i don't know javascript, so i created this thread. If you, the magic javascript plugin creators have any doubt about this effect, tell me.
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
This should do it:
Code:
_BattleManager_invokeMagicReflection = BattleManager.invokeMagicReflection;
BattleManager.invokeMagicReflection = function(subject, target) {
    if (!subject.opponentsUnit().members().contains(target)) {
        subject = subject.opponentsUnit().randomTarget();
    }
    _BattleManager_invokeMagicReflection.call(this, subject, target);
};
Just save it as a .js file and add it as a new plugin.

Note that magic reflection by default only occurs when the skill's Hit Type is set to Magical Attack, not for skills like Heal, which are usually Certain Hits. If you want to be able to reflect other skills as well, also add this snippet:
Code:
Game_Action.prototype.itemMrf = function(target) {
    if (this.isMagical() || $dataSkills[this._item._itemId].meta.EnableMRF) {
        return target.mrf;
    } else {
        return 0;
    }
};
Then you can use the notetag <EnableMRF> in any skill's notebox to reflect it as well.
 

Danitinkis

Deadly and sexy
Veteran
Joined
Dec 31, 2016
Messages
118
Reaction score
65
First Language
Spanish
Primarily Uses
RMMV
This should do it:
Code:
_BattleManager_invokeMagicReflection = BattleManager.invokeMagicReflection;
BattleManager.invokeMagicReflection = function(subject, target) {
    if (!subject.opponentsUnit().members().contains(target)) {
        subject = subject.opponentsUnit().randomTarget();
    }
    _BattleManager_invokeMagicReflection.call(this, subject, target);
};
Just save it as a .js file and add it as a new plugin.

Note that magic reflection by default only occurs when the skill's Hit Type is set to Magical Attack, not for skills like Heal, which are usually Certain Hits. If you want to be able to reflect other skills as well, also add this snippet:
Code:
Game_Action.prototype.itemMrf = function(target) {
    if (this.isMagical() || $dataSkills[this._item._itemId].meta.EnableMRF) {
        return target.mrf;
    } else {
        return 0;
    }
};
Then you can use the notetag <EnableMRF> in any skill's notebox to reflect it as well.
Thank you! But here is a noob question. How can I download the code?
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
Just select the text inside the code box with your mouse cursor and copy it from there (CTRL-C or right click -> Copy). Then paste it into a simple text editor like Notepad and save with the extension .js :)
 

Danitinkis

Deadly and sexy
Veteran
Joined
Dec 31, 2016
Messages
118
Reaction score
65
First Language
Spanish
Primarily Uses
RMMV
@LadyBaskerville I have a problem. When the reflect occurs, the action animation shows at the battler that has the reflect state. Fix it please :rswt
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
Currently I don't see a way to remove that animation (as it is played before the engine even checks if the magic is going to be reflected), but Yanfly's Battle Engine Core would display the animation on the enemy as well, along with a reflection animation on the actor reflecting the magic. If you don't want the rest of the plugin's features, I can split the reflection parts into an extra plugin for you (Credit would still go to Yanfly).
 

Danitinkis

Deadly and sexy
Veteran
Joined
Dec 31, 2016
Messages
118
Reaction score
65
First Language
Spanish
Primarily Uses
RMMV
This is what happens, @LadyBaskerville (i didn't have time to film a video, i had to go):
I didn't understand what you said, but if that solves the problem do it. But, when the battle engine core gets an updtate, what I will do?
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
Ah, my bad - I didn't realize how exactly Yanfly specified the actor to which the animation was reflected. Instead of the first code snippet I posted, use this:
Code:
_BattleManager_invokeMagicReflection = BattleManager.invokeMagicReflection;
BattleManager.invokeMagicReflection = function(subject, target) {
    var tempSubj = this._subject;
    if (!subject.opponentsUnit().members().contains(target)) {
        subject = subject.opponentsUnit().randomTarget();
        this._subject = subject;
    }
    _BattleManager_invokeMagicReflection.call(this, subject, target);
    this._subject = tempSubj;
};
Since you're already using Yanfly's Battle Engine, disregard what I said about splitting the reflection parts into an extra plugin.
 

Danitinkis

Deadly and sexy
Veteran
Joined
Dec 31, 2016
Messages
118
Reaction score
65
First Language
Spanish
Primarily Uses
RMMV
OK! now works perfectly! How can I credit you?
PD: You should add that plugin to your colection! I look barely some of your plugins and they look great!
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
You can credit me as LadyBaskerville if you want, but you don't need to. I'm glad it's working now!
 

Gidan90

Villager
Member
Joined
Mar 30, 2014
Messages
12
Reaction score
0
First Language
Italian
Primarily Uses
Hi, I have another problem. Using reflect with YEP-X-SelectionControl, when I cast magic to all allies, magic is reflected against enemies, but if one enemy remains and was killed from first magic, the second magic does not strike and displays the following error: Cannot read property 'StartAnimation' of null. Can someone fix it?error2.png
 

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

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,078
Members
137,580
Latest member
Snavi
Top