Hit, Evasion and Game_Action.prototype.apply = function(target)
I have been attempting to overwrite the functionality of this almost completely.
Issue Summary — I'm attempting to make Hit, Luk, and Eva impact physical attacks accuracy and evasion rates - I'm also trying to make Mdf, Mat, Luk, and Mev impact magic evasion. I found the functions that impact it but for some reason the declared constants aren't working as intended.
Details — When I plug the script in the game loads but crashes on attack stating "diffroll1" hasn't been defined. I have it set with an "if" "else" statement within the code however it says it isn't defined...
What tutorials or previous support threads have you referenced? — I've looked at support for Visustella's battle core and tried the ATT_Turan hit formula script ( it crashes when loaded every time. )
Are you using any plugins? — Yes, I'm using Visustella's Battle Core, Status Core, Menu Core, ItemsEquipCore, SkillsStatesCore, SkillLearn, and SRD_WalkCharacterBattlers.
Attach any illustrative screenshots, full event pages with no cropping, mock ups, etc. —
This is the script code:
/*:
* @target MZ
* @plugindesc Hit and Evasion mods by Clarx
* @Author Clarx
*
* @Help
* This makes the hit formula and evasion formula stat based using AGI and LUK for physical, MAT MDF and LUK for magic.
*
*/
const CLARX_HitEva = {};
// Hit calculations
Game_Action.prototype.itemHit = function(/*target*/) {
const successRate = this.item().successRate;
if (this.isPhysical()) {
let rough = successRate + this.subject().hit + ( this.subject().agi / 5 ) + ( this.subject().luk / 10 );
let rounded = Math.trunc(rough);
return rounded;
} else {
let roughm = successRate + ( this.subject().mat / 5 ) + ( this.subject().mdf / 5 ) + ( this.subject().luk / 10 );
let roundedm = Math.trunc(roughm);
return roundedm;
}
};
// Eva calculations
Game_Action.prototype.itemEva = function(target) {
if (this.isPhysical()) {
return target.eva + ( target.agi / 2 ) + ( target.luk / 10 );
} else if (this.isMagical()) {
return target.mev + ( target.mdf / 3 ) + ( target.mat / 5 ) + ( target.luk / 10 ) ;
} else {
return 0;
}
};
Game_Action.prototype.itemCri = function(target) {
return this.item().damage.critical
? this.subject().cri * (1 - target.cev)
: 0;
};
Game_Action.prototype.apply = function(target) {
// New variables
// End new variables
const result = target.result();
this.subject().clearResult();
result.clear();
result.used = this.testApply(target);
result.physical = this.isPhysical();
if (this.isPhysical()) {
const diffroll1 = ( target.agi / 2 ) + ( target.luk / 10 ) + target.eva;
} else {
const diffroll1 = ( target.mdf / 4 ) + ( target.mat / 4 ) + ( target.luk / 10 ) + target.mev;
}
const diffroll = Math.trunc(diffroll1);
// This is where misses and evasions actually happen. > greater, < less
result.missed = result.used && Math.randomInt(diffroll) >= this.itemHit(target);
result.evaded = !result.missed && Math.randomInt(diffroll) < this.itemEva(target);
// Nothing below is modified.
result.drain = this.isDrain();
if (result.isHit()) {
if (this.item().damage.type > 0) {
result.critical = Math.random() < this.itemCri(target);
const value = this.makeDamageValue(target, result.critical);
this.executeDamage(target, value);
}
for (const effect of this.item().effects) {
this.applyItemEffect(target, effect);
}
this.applyItemUserEffect(target);
}
this.updateLastTarget(target);
};
* @target MZ
* @plugindesc Hit and Evasion mods by Clarx
* @Author Clarx
*
* @Help
* This makes the hit formula and evasion formula stat based using AGI and LUK for physical, MAT MDF and LUK for magic.
*
*/
const CLARX_HitEva = {};
// Hit calculations
Game_Action.prototype.itemHit = function(/*target*/) {
const successRate = this.item().successRate;
if (this.isPhysical()) {
let rough = successRate + this.subject().hit + ( this.subject().agi / 5 ) + ( this.subject().luk / 10 );
let rounded = Math.trunc(rough);
return rounded;
} else {
let roughm = successRate + ( this.subject().mat / 5 ) + ( this.subject().mdf / 5 ) + ( this.subject().luk / 10 );
let roundedm = Math.trunc(roughm);
return roundedm;
}
};
// Eva calculations
Game_Action.prototype.itemEva = function(target) {
if (this.isPhysical()) {
return target.eva + ( target.agi / 2 ) + ( target.luk / 10 );
} else if (this.isMagical()) {
return target.mev + ( target.mdf / 3 ) + ( target.mat / 5 ) + ( target.luk / 10 ) ;
} else {
return 0;
}
};
Game_Action.prototype.itemCri = function(target) {
return this.item().damage.critical
? this.subject().cri * (1 - target.cev)
: 0;
};
Game_Action.prototype.apply = function(target) {
// New variables
// End new variables
const result = target.result();
this.subject().clearResult();
result.clear();
result.used = this.testApply(target);
result.physical = this.isPhysical();
if (this.isPhysical()) {
const diffroll1 = ( target.agi / 2 ) + ( target.luk / 10 ) + target.eva;
} else {
const diffroll1 = ( target.mdf / 4 ) + ( target.mat / 4 ) + ( target.luk / 10 ) + target.mev;
}
const diffroll = Math.trunc(diffroll1);
// This is where misses and evasions actually happen. > greater, < less
result.missed = result.used && Math.randomInt(diffroll) >= this.itemHit(target);
result.evaded = !result.missed && Math.randomInt(diffroll) < this.itemEva(target);
// Nothing below is modified.
result.drain = this.isDrain();
if (result.isHit()) {
if (this.item().damage.type > 0) {
result.critical = Math.random() < this.itemCri(target);
const value = this.makeDamageValue(target, result.critical);
this.executeDamage(target, value);
}
for (const effect of this.item().effects) {
this.applyItemEffect(target, effect);
}
this.applyItemUserEffect(target);
}
this.updateLastTarget(target);
};
I'm attaching the script below as well for ease of use.