- Joined
- Jan 14, 2018

- Messages
- 88

- Reaction score
- 16

- First Language
- English

- Primarily Uses
- RMMV

Code:

```
/////////////////////////////////////////////////////////////////
// RFG-Multiple Hits System
// Author: RedFoxGaming
/////////////////////////////////////////////////////////////////
/*:
* @plugindesc A Multiple Hits attack system similar to Final Fantasy
* @author RedFoxGaming
*
* This plugin has no plugin commands
*
* @param Maximum Possible Hits
* @desc The maximum possible amount of hits, without state modifiers
* @default 16
*
* @param Maximum Magic Hits
* @desc The maximum possible magic multipliers
* @default 6
*
* @param Double Hits State
* @desc The stateID of the state you want to double your hits (will go beyond max)
* @default 10
*
* @param Half Hits State
* @desc The stateID of the state you want to half your hits
* @default 11
*
* @param Possible Hits Formula
* @type text
* @desc The formula that calculates how many hits are possible
* @default agi / 16
*
* @param Damage Formula
* @type text
* @desc The default damage formula
* @default atk * 4 - def * 2
*
* @param Magic Damage Formula
* @desc The default damage formula for spells
* @default base + a.mat * 2 - b.mdf * 2
*
* @param Actual Hits Variable
* @desc The ingame variable to store your hits scored (to use in messages)
* @default 1
*
* @help
*
* ----------------------------------------------
* RFG Multiple Hits System
* Version 0.1
* ----------------------------------------------
*
* The purpose of this plugin is to mimic the way Final Fantasy handles their
* attacking system, where your attack has the possibility of landing multiple
* hits. In order to use this plugin, all you have to do is replace your formulas
* in the skills you have set to attack, or your magic formulas to my functions.
*
* Function for Physical Attacks
* this.physicalAttack(a,b)
*
* Function for Magical Attacks
* this.magicalAttack(a,b,base) where base is a default number value
*
* Function for Healing Magic
* this.healingMagic(a,b,base) where base is a default number value
*/
function getRandomInt (min,max) { //Define a function to get a random range of numbers
min = Math.ceil(min);
max = Math.floor(max) + 1;
return Math.floor(Math.random() * (max - min)) + min;
}
function toNumber(str, def) {
return isNaN(str) ? def : +(str || def);
}
var parameters = PluginManager.parameters("RFG-MultipleHitsSystem");
var mhitsposs = toNumber(parameters['Maximum Possible Hits'], 16);
var mmagicposs = toNumber(parameters['Maximum Magic Hits'], 6);
var doublehitsstate = toNumber(parameters['Double Hits State'], 10);
var halfhitsstate = toNumber(parameters['Half Hits State'], 11);
var phitsform = parameters['Possible Hits Formula'] || "a.agi / 16";
var damageform = parameters['Damage Formula'] || "a.atk * 4 - b.def * 2";
var magicdamform = parameters['Magic Damage Formula'] || "base + a.mat * 2 - b.mdf * 2";
var actualhitsvar = toNumber(parameters['Actual Hits Variable'], 1);
var phits = 0;
var damage = 0;
Game_Action.prototype.physicalAttack = function(a,b){
$gameVariables.setValue(actualhitsvar, 0);
phits = eval(phitsform);
if(phits < 1) { phits = 1; }
if(a.isStateAffected(doublehitsstate)) { phits = phits * 2; }
if(a.isStateAffected(halfhitsstate)) { phits = phits / 2; }
for(i=0; i < phits; i++){
if(Math.random() > 1 - a.acc && Math.random() > b.eva) { //If both of these conditions are true, than this was a successful hit
damage = damage + eval(damageform);
$gameVariables.setValue(actualhitsvar, $gameVariables.getValue(actualhitsvar) + 1); //Add one to actual hits if sucessful
}
}
console.log("Damage: " + damage + " | Possible Hits: " + phits + " | Actual Hits: " + $gameVariables.getValue(actualhitsvar));
if(damage > 0) {
if(Math.random() < a.cri){
damage = damage * 2;
if(a.isActor() == true) { SceneManager._scene._logWindow.push(TextManager.criticalToEnemy); }
if(a.isActor() == false) { SceneManager._scene._logWindow.push(TextManager.criticalToActor); }
return damage;
}
else { return damage; }
}
else{
if(a.isActor() != true){
SceneManager._scene._logWindow.push(TextManager.enemyNoHit);
return 0;
}
else{
SceneManager._scene._logWindow.push(TextManager.actorNoHit);
}
}
}
Game_Action.prototype.magicalAttack = function(a,b,base){
}
Game_Action.prototype.healingMagic = function(a,b,base){
}
```

This code is not finished yet, but what I am trying to do here is make a multiple hit calculation similar to the Final Fantasy games. The issue is the damage returned is always 0. I had to add breakpoints and step through each individual line to figure out what's going on, and I'm still not sure why. The script proceeds as normal until it gets to phits = eval(phitsform); at this point, in the game's built in damage calculation function, an exception is getting caught right here, and in the game's built in Try Catch block, it is catch(e) { return 0; }, and this is why I'm getting 0 damage.

I don't know why the formula is failing however. And because of this, I cannot see if the rest of the plugin is actually functioning properly. I'm sure it's something simple like a typo I'm not seeing.