So I had another thread with the same code but all of that is solved. Now, I want to ask help on how to do something completely different. I'm coming into this with 0 javascript experience and I don't know where any of the games original functions are located within the individual *.js files.
So here is my code. It's really just an attack formula that is implementing multiple hits per attack.
UPDATE:
So I rewrote the code to try and clean it up, and now I have a new issue. No matter what I do, calling this.customPhysicalAttack(a,b,false) in the formula box isn't working. This function isn't even executing period, and I cannot seem to figure out why because I am getting absolutely no error messages.
EDIT: I gotta fix the issue with it not even executing before I worry about this below now.
So here is my code. It's really just an attack formula that is implementing multiple hits per attack.
UPDATE:
So I rewrote the code to try and clean it up, and now I have a new issue. No matter what I do, calling this.customPhysicalAttack(a,b,false) in the formula box isn't working. This function isn't even executing period, and I cannot seem to figure out why because I am getting absolutely no error messages.
Code:
Game_Action.prototype.customPhysicalAttack = function (a,b,ignoreDefense) {
var phits = Math.floor(a.agi / 16); //Variable that holds the maximum possible hits the actor can have
$gameVariables.setValue(20,0); //Initialize this variable so the game can read this value in message boxes
var damage = 0; //Initialize the value that will hold the finished damage
if(phits > 16) { phits = 16; } //Don't allow phits to be larger than 16 normally
if(phits < 1) { phits = 1; } //Set phits to 1 if for some reason it was set to 0
if(a.isStateInflicted(98)) { phits * 2; } //Check if haste is inflicted and double hits
if(a.isStateInflicted(99)) { phits / 2; } //Check if slow is inflicted and half hits
console.log("Script executed")
if(ignoreDefense == true) { //Check if the ignore defense flag is checked
for(i=0; i < phits; i++){ //Perform actual damage calculation, defense is ignored
if((Math.floor(Math.random() * 100) + 1) > 100 - (a.hit * 100) &&
(Math.floor(Math.random() * 100) + 1) > (b.eva * 100)){
damage = damage + a.atk * 4;
$gameVariables.setValue(20, $gameVariables.value(20) + 1);
}
}
}
else if(ignoreDefense == false){ //If ignoreDefense is false, which this will be the most common result
if(a.atk < b.def){ //If the enemy's defense is higher, perform a different calculation
for(i=0; i < phits; i++){
if((Math.floor(Math.random() * 100) + 1) > (100 - (a.hit * 100)) / 2 &&
(Math.floor(Math.random() * 100) + 1) > (b.eva * 100)){
damage = damage + Math.floor(Math.random() * 10) + 1;
$gameVariables.setValue(20, $gameVariables.value(20) + 1);
}
}
}
else{ //If your attack is higher than the enemy's defense
for(i=0; i < phits; i++){
if((Math.floor(Math.random() * 100) + 1) > 100 - (a.hit * 100) &&
(Math.floor(Math.random() * 100) + 1) > (b.eva * 100)){
damage = damage + (a.atk * 4) - (b.def * 2);
$gameVariables.setValue(20, $gameVariables.value(20) + 1);
}
}
}
}
if($gameVariables.value(20) > 0){
return damage; //If you scored at least 1 hit, return damage result
console.log("Damage was returned: " + damage + " damage! Hits x " + $gameVariables.value(20));
}
else{
return Game_ActionResult.missed(); //If you scored 0 hits, return a missed statement
console.log("No damage was returned. Miss Hits x " + $gameVariables.value(20));
}
}
/*
Game_Action.prototype.whiteMagicAttack = function(a,b,base,ignoreDefense){
}
Game_Action.prototype.blackMagicAttack = function(a,b,base,ignoreDefense){
}
Game_Action.prototype.healingMagic = function(a,b,base){
}
*/
EDIT: I gotta fix the issue with it not even executing before I worry about this below now.
It works as intended, but what I want to do now is overwrite (or remove) where the game checks accuracy and evasion on its own in the default battle system, so that it doesn't perform these checks, and that misses are calculated on whether you scored 0 hits or not. I want to have a check if(ahits < 1) { Result.missed(); } or something similar to where, if ahits = 0, instead of just setting damage to 0 and returning that, I actually want to return the Missed function. I also plan on changing the formula until I find a balance, and I know I could also clean the code up some. I believe the random1 and random2 variables aren't really needed.
As it is right now, I'm missing enemies twice as much because I do 0 damage if ahits = 0, but also I can miss or the enemy can evade based off of the default battle engine. I want it to all be handled within my plugin. The accuracy checks for the plugin are performed in the for loop for each individual hit.
Also, how could you add a +- 20% variance to the damage pool I'm adding up in the for loop? I don't really know how to go about a +- function in Javascript, or how to have a Math.random() return -0.20 to 0.20.
As it is right now, I'm missing enemies twice as much because I do 0 damage if ahits = 0, but also I can miss or the enemy can evade based off of the default battle engine. I want it to all be handled within my plugin. The accuracy checks for the plugin are performed in the for loop for each individual hit.
Also, how could you add a +- 20% variance to the damage pool I'm adding up in the for loop? I don't really know how to go about a +- function in Javascript, or how to have a Math.random() return -0.20 to 0.20.