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
Regular
Joined
Jul 2, 2014
Messages
12,706
Reaction score
11,298
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
Regular
Joined
Jul 2, 2014
Messages
12,706
Reaction score
11,298
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
Regular
Joined
Jul 2, 2014
Messages
12,706
Reaction score
11,298
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 Profile Posts

Huge breakthrough! I finally fixed the dimensions on the WEBM used in the cinematic that ends the demo and introductory segment in MC:RIS, around the one-minute mark:



(There's some audio desync because the capture is an MP4.)
Kudos to everyone making game jam games, because this month has been hell for my development time. I have made a cutscene, 2 sprites, and 1 tile.

I guess I've made conceptual progress in hammering out combat roles and having fixes to be implemented (though I haven't done that yet)
Yeah, it’s a status #3, but it’s just to let y’all know I think I’m gonna have to do a twofer on the Advent compilation tomorrow. I feel like butt. Have a fever. I want to descend into my crypt.
I hope Baldur's Gate 3 wins BIG at TGA tonight. Tales of Arise was the last game to inspire me and BG3 has MASSIVELY surpassed that!
One day someone will build independent items for MZ. ONE DAY!

Forum statistics

Threads
136,818
Messages
1,270,385
Members
180,579
Latest member
AxlCrow1
Top