RMMZ Which js file and which bit of code to edit to change the minimum damage?

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,044
Reaction score
853
First Language
French
I know that this works:

Math.max(a.atk-b.def,Math.randomInt(3)+1)

But personally I think it eats a lot of space in a box that is already not very big to begin with.
I was wondering if it's not possible to edit directly the js files so that the minimum damage is, say, random 1-4 instead of 0. Any clues?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,347
Reaction score
2,475
First Language
English
Primarily Uses
RMMZ
I would do this in Game_Action.prototype.makeDamageValue:

after the line value = this.applyGuard(value, target); add

JavaScript:
if (value === 0) {
    value = Math.randomInt(4) + 1;
}
 

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,044
Reaction score
853
First Language
French
Thanks for your reply.

For some strange reason, it doesn't seem to work.
I added this bit from rmmz_objects.js:

Code:
Game_Action.prototype.makeDamageValue = function(target, critical) {
    const item = this.item();
    const baseValue = this.evalDamageFormula(target);
    let value = baseValue * this.calcElementRate(target);
    if (this.isPhysical()) {
        value *= target.pdr;
    }
    if (this.isMagical()) {
        value *= target.mdr;
    }
    if (baseValue < 0) {
        value *= target.rec;
    }
    if (critical) {
        value = this.applyCritical(value);
    }
    value = this.applyVariance(value, item.damage.variance);
    value = this.applyGuard(value, target);


    if (value === 0) {
    value = Math.randomInt(4) + 1;
    }


    value = Math.round(value);
    return value;
};
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,118
Reaction score
611
First Language
English
Primarily Uses
RMMV
I'm not sure why you care about the length of your damage formula...it's not limited to the amount you see in the text box, they can be quite long.

It is also not good coding habits to modify the source code directly. It is better practice to create a plugin. That's actually what I do for my standard damage formulas, I just made a function in JavaScript, saved it as a plugin, then my damage formulae just say TurDamage(a, b);
 

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,044
Reaction score
853
First Language
French
How can I make a plugin that performs this then?

if (value === 0) {
value = Math.randomInt(4) + 1;
}
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,347
Reaction score
2,475
First Language
English
Primarily Uses
RMMZ
Actually now that I think about it, put that after the call to Math.round because it may not be 0 after calling applyVariance. My bad!

Also Indinera if you look up my topic "The anatomy of a plugin" it tells you how to structure a plugin file that you can put that code into.
 

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,044
Reaction score
853
First Language
French
Actually now that I think about it, put that after the call to Math.round because it may not be 0 after calling applyVariance. My bad!

I had the same idea and tried it too, but unfortunately it didn't seem to change the damage to something else than 0.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,810
Reaction score
14,622
First Language
English
Primarily Uses
RMVXA
It might be the triple equal signs. When I was doing coding it was == for equals. Try that.
 

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,044
Reaction score
853
First Language
French
It's not a problem with the formula. I tried this and it didn't show 600 as damage.

value = this.applyVariance(value, item.damage.variance);
value = this.applyGuard(value, target);
value = Math.round(value);
value = 600;
return value;
 

Traverse

Veteran
Veteran
Joined
Jul 3, 2014
Messages
193
Reaction score
125
First Language
English
Primarily Uses
It's not a problem with the formula. I tried this and it didn't show 600 as damage.
That modification definitely works the way it should in MV.

So unless MZ drastically changed something in the damage calculation process from MV, I would guess that you have a plugin somewhere that is either overwriting or bypassing the default logic for damage calculation.

In which case, that one would be the .js file you need to look at modifying.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,347
Reaction score
2,475
First Language
English
Primarily Uses
RMMZ
Oh, yeah, I thought it would go without saying that my solution would only work if you weren't using any plugins that overwrite the makeDamageValue function. :p
 

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,044
Reaction score
853
First Language
French
Oh, yeah, I thought it would go without saying that my solution would only work if you weren't using any plugins that overwrite the makeDamageValue function. :p

I tried that too, checked if visustella core and battle core had smth similar but couldn't find it.
Does anything from tier 1 VS rewrites it?
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,500
Reaction score
726
First Language
indonesian
I tried that too, checked if visustella core and battle core had smth similar but couldn't find it.
Does anything from tier 1 VS rewrites it?
We won't be able to know... since VisuStella code is obfuscated so human cannot read that easily...
but seeing what you edit did not affect anything... i suspect VisuStella modify that method thus making your changes obselete...

you could try aliasing though...
maybe something like this?
Code:
var vsAliasGameActionMakeDamageValue = Game_Action.prototype.makeDamageValue;
Game_Action.prototype.makeDamageValue = function(target, critical) {
  value = vsAliasGameActionMakeDamageValue.call(this, target, critical);
   if (value == 0) value = Math.randomInt(4) + 1;
   return value;
};
make sure to put that as a plugin below the visuStella plugin...
basically it will call visuStella(or any other plugin) method first and get the value... then check if value == 0 then change it to random int 4 + 1... then return the value

hope this help...
 

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,044
Reaction score
853
First Language
French
Bingo! This worked.
Thank you everyone who tried and helped in this thread, much appreciated.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,118
Reaction score
611
First Language
English
Primarily Uses
RMMV
It might be the triple equal signs. When I was doing coding it was == for equals. Try that.
Both work...by default, only two equal signs in JS will attempt to convert variable types to see if they're supposed to be the same thing. So things like if (1 == '1') will return true. Three equal signs returns true only if the two things are exactly the same value and type of variable.
 

Latest Threads

Latest Posts

Latest Profile Posts

Took a small break by playing VR. Latest update of these glasses unfortunately caused a little of trouble but it can be fixed with a manual operation.

Until You Fall is freaking awesome.
I am SO HYPED to share this trailer with everyone when its done. I almost want to tear up i had no idea how far i came along with Fallen Feather in these last 3 years.
how it looks from the top
Hike was successful guys! I made it to the top!
Add Film-like Visual Effects During Test-Play, Deploy Games with Electron | RPG Maker News #69

Forum statistics

Threads
112,187
Messages
1,066,466
Members
145,790
Latest member
LiteSilverwind
Top