RMMV How to add a direct hit rate (FFXIV-like lesser critical)

Erinblue

Villager
Member
Joined
Jan 9, 2018
Messages
21
Reaction score
3
First Language
Spanish
Primarily Uses
RMMV
What I want to do is to have 2 separate odds for skills landing either direct hit, critical hit oro both, kinda like in Final Fantasy XIV. I managed to do it with Yanfly's Damage Core but I want the code to be flexible so I can make certain skills ensure direct for example.
I tried this but it doesn't work, and as my JS knowledge is a bit poor I don't know exactly where to follow.
Code:
Game_Action.prototype.apply = function(target) {
    var result = target.result();
    this.subject().clearResult();
    result.clear();
    result.used = this.testApply(target);
    result.missed = (result.used && Math.random() >= this.itemHit(target));
    result.evaded = (!result.missed && Math.random() < this.itemEva(target));
    result.physical = this.isPhysical();
    result.drain = this.isDrain();
    if (result.isHit()) {
        if (this.item().damage.type > 0) {
            result.critical = (Math.random() < this.itemCri(target));
            
            result.direct = this.checkDirectHit();
            
            var value = this.makeDamageValue(target, result.critical, result.direct);
            this.executeDamage(target, value);
        }
        this.item().effects.forEach(function(effect) {
            this.applyItemEffect(target, effect);
        }, this);
        this.applyItemUserEffect(target);
    }
};

Game_Action.prototype.checkDirectHit = function() {
    return Math.floor(Math.random() * 100) < this.subject().luk;
};

// From Yanfly's DamageCore
Game_Action.prototype.makeDamageValue = function(target, critical, direct) {
  var item = this.item();
  var a = this.subject();
  var b = target;
  var user = this.subject();
  var s = $gameSwitches._data;
  var v = $gameVariables._data;
  var baseDamage = this.evalDamageFormula(target);
  var value = baseDamage;
  console.log(critical);
  try {
    eval(Yanfly.DMG.DamageFlow);
  } catch (e) {
    Yanfly.Util.displayError(e, Yanfly.DMG.DamageFlow, 'DAMAGE FLOW ERROR');
  }
  return Math.round(value);
};
Any help is appreciated, thanks!
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,086
Reaction score
4,895
First Language
English
Primarily Uses
RMMV
It would help to know what you're trying to do. For most of us, the phrase "direct damage" doesn't mean anything - and you can't presume people have played a specific Final Fantasy to know its mechanics :wink:

However, ultimately you're using Yanfly's Damage Core and you didn't show us anything about that. Modifying the damage by a critical hit is a part of the plugin parameters there (you see eval(Yanfly.DMG.DamageFlow) there).

So show us where you inserted code to modify the damage based on a direct hit in that plugin parameter.
 

Erinblue

Villager
Member
Joined
Jan 9, 2018
Messages
21
Reaction score
3
First Language
Spanish
Primarily Uses
RMMV
Yes, forgot to explain what it's suposed to be sorry. It's basically a second critical, it works exactly the same but rate is based on the luck stat, and the damage multiplier is a fixed x1.25.

And this is what I did on the Damage Core plugin:
JavaScript:
baseDamage = this.modifyBaseDamage(value, baseDamage, target);
baseDamage *= this.calcElementRate(target);

var direct = (Math.floor(Math.random() * 100) < a.luk);

$gameSystem.setNewDamageCap(9999, true);
critical = this.modifyCritical(critical, baseDamage, target);
target.result().critical = critical;
value = baseDamage;

if (baseDamage > 0) {
value = this.applyDamageRate(value, baseDamage, target);
}
if (baseDamage < 0) {
value = this.applyHealRate(value, baseDamage, target);
}
if (critical) {
value = this.applyCriticalRate(value, baseDamage, target);
}
if (direct && a.isActor()) {
value = Math.floor(value * 1.25);
$gameSystem.setNewDamageCap(99999, true);
}
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,086
Reaction score
4,895
First Language
English
Primarily Uses
RMMV
Why are you calculating "direct" again, when you already did it above in your modified apply() method? I don't know what values of luck you're using on your actor to compare it to, but you're giving yourself a double chance of failure.

It looks like you're trying to change things in the base code that are being overwritten by the Damage Core. However...what you have in the post above for the damage flow looks fine to me. If you test with an actor that has 100 luck, you don't see the change in the damage?

You can add some troubleshooting things - after your var direct line, put
Code:
console.log("Direct is ", direct);

Then, while playtesting, press F8 and go to the Console tab and see what it says.

You can add other log commands lower down to make sure your "direct and is an actor" conditional is being gone into.
 

Erinblue

Villager
Member
Joined
Jan 9, 2018
Messages
21
Reaction score
3
First Language
Spanish
Primarily Uses
RMMV
When I try the damage flow code alone it works fine. As you suggested I tested it with console.log commands before, with an actor that has 100 luck the direct variable returns true and the damage is multiplied correctly. So that's a starting point I have.

The thing is that like that I cannot control the direct variable from the outside, that's why I tried to modify the apply() method. I've checked and in there the result.direct can be true when at 100 luck.
And then I added the parameter "direct" to makeDamageValue so I can pass the result.direct. But when calling it from inside the makeDamageValue it returns undefined. That's what I don't get.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,086
Reaction score
4,895
First Language
English
Primarily Uses
RMMV
I don't see where you try to do anything with it inside makeDamageValue, so I can't speak to that.

But I don't understand why you need to do something with it outside of the damage flow parameter. Any code you'd want to use inside makeDamageValue can simply go there.

So, for example, if you wanted to say skill ID 59 will always score a direct hit, you'd modify your line in the damage flow to say
Code:
var direct = Math.floor(Math.random() * 100) < a.luk || this.item().id==59;

And if you had multiple skills like that you can get help making efficient code for it...but I'm not sure why you would need it to be anyplace else. That's kind of the point of that plugin.
 

Erinblue

Villager
Member
Joined
Jan 9, 2018
Messages
21
Reaction score
3
First Language
Spanish
Primarily Uses
RMMV
Maybe I was trying to make something more complex than necessary. For now I'll put a list of skills that are guaranteed to land direct hit and check for that, I like the idea. Thank you a lot for your insight.
 

Latest Threads

Latest Posts

Latest Profile Posts

All the artists on here always share their art, and I wanted to partake in the sharing. I wanted to show off the album art for my game's soundtrack while also showing off this song. I wanted to take a break from all the pianos/strings/jazz. I experimented with some side-chaining techniques to modulate the dub-step like synth.
Crazy idea to help people be more productive. We all upload a photo of someone who is good at nagging, cajoling, guilting, etc. you into doing what you should be doing. Then, after you have posted X amount of times in a defined period, that photo pops up with the text of "Shouldn't you be working on your game?" Just for fun.:wink:
Avery wrote on MouseWorks's profile.
That is a really cute avatar concept that you have there! I like it :3
Well, here's a screenshot of just another game that might never be completed...

quicktrip_xp01.jpg
Fake FullScreen (Download):

Forum statistics

Threads
128,509
Messages
1,195,112
Members
169,083
Latest member
riluohuangsha
Top