Help with this Attacking Code (UPDATED: New Issue)

RedFoxGaming

Veteran
Veteran
Joined
Jan 14, 2018
Messages
88
Reaction score
16
First Language
English
Primarily Uses
RMMV
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.
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.
 
Last edited:

RedFoxGaming

Veteran
Veteran
Joined
Jan 14, 2018
Messages
88
Reaction score
16
First Language
English
Primarily Uses
RMMV
Bump. Still haven't been able to get this to work. Even tried it in a brand new project and the script still isn't executing.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Made Custom ENEMY Information Screen
I'm having such a hard time thinking of an interesting battle system. and not being a coder, certain things I wanna do seem a lot harder lol.
Created a character outline with some code. I have no use for this. I'm....bored.....
Having lots of fun using different PS brushes to add a lil' texture to the floors and walls in my maps.

Forum statistics

Threads
93,721
Messages
914,912
Members
123,324
Latest member
ahmbor
Top