Damage roll to variable

Exactly what it says. Basically it's a case of system detection of the damage roll for a given result during battle off a single action. Damage only, no recovery results. The idea is to detect exact results per action and (if it is a damage count) to save the result in a game variable for immediate access or some other purpose. Basically the joke is to blame the serpent trickster for a damage roll of 666 and save a record of the result into the player's logbook, trophy case, achievements etc.
no need for a plugin, you can use an if command in the damage formula and store the damage number into a variable as well.
you just need a bit of javascript to do so inside every damage formula that could trigger this.
Start with these two tutorials:

https://steamcommunity.com/sharedfiles/filedetails/?id=681253029
https://forums.rpgmakerweb.com/index.php?threads/damage-formulas-101.81905/

Once you've gone through those, you should be able to implement Andar's suggestion in the damage formula.
So using the suggestions I added the code to rpg_objects under the executeHpDamage event (but can move it accordingly if it works better in another place). The only other stipulation of course is that I want the achievement, trophy etc. to update while the battle is still in progress (for obvious reasons).

Anyway, what I have implemented uses two common switches, one each for the devil sign (666) and the upper echelon sign (1337). Now that I've gotten on top of this, I'm also debating the addition of a "Metaphysic Answers on Existence" achievement (guess which sign that is?) And the logic code is as follows:

Code:
        if (value == 666) {
            $gameSwitches.setValue(447, true);
        }
        if (value == 1337) {
            $gameSwitches.setValue(446, true);
        }
added the code to rpg_objects
you should never modify the default scripts - that destroys the option to ever update your project.
and none of us suggested any change in the engine code either, we suggested to use the damage formula directly.
As I said, I can always move it if required. If anything you can probably consider this a temporary measure at best, or one of several options at the least. If this can be added to the VE damage display instead it would be preferable, although upgrades of the core aren't a priority for me. That and I've already changed or commented out the defaults that I don't require or use, or that don't immediately do what I need 'em to (and the lack of a "got away" success message is one such reason for which I have no other known method of doing so at this time).
@BreakerZero why don't you simply use the damage formulae field?
Or do you not understand what we mean with that question?

Because every single variant you mentioned is not required for something this simple
In that case I'll examine this further and see what else I have in terms of options. Regarding the damage formulae itself, I don't need that so much as the actual result which is where the scripting came into the question. I'm also hesitant to use an event during the battle sequence as I've had a lot of horrid results with this kind of thing (and it usually happens with moment definitions by nature of their inherent oddities).
OK, you obviously didn't understand what we mean. We were not talking about the calculation of the damage but about the use of the damage formula beyond simple mathematics.

Place this into a skills damage formula and it will store the result of the damage formula into a variable (10 in this case):
Code:
r=a.atk*4-b.def*2; v[10]=r; r

Or if you want it with your if and switches:
Code:
r=a.atk*4-b.def*2; if (r=666) {$gameSwitches.setValue(447, true);}; r

you only have to make sure that the damage is the last number processed because that will be used after the eval by the engine.
And of course you can replace the default damage formula I used in the example with whatever other formula you want.

Look here for a screenshot:
damform.jpg
Problem with your calculation @Andar is that it will only turn true if the value is that before variance, is there a way to make it take the REAL value and trigger the switch?

I have something like this I added in my game just this week for achievements that are damage based or healing based, but it was by editing the forbidden base JS files, so I don't want to post it here or someone might say I did it wrong >;p lol

I jest of course, I'll share a version thats just right for what OP asked for, and it should work if you edit it in yourself to rpg_objects.js as I have (as long as no other plugin overwrites that function) Just remember if you do any edits to the base JS files make sure that you mark them in case they ever cause issues, or in @Andar case about not being able to update the project you can quickly and easily check to see if you still need the edits or can copy them over correctly.

Code:
Game_Action.prototype.makeDamageValue = function(target, critical) {
    var item = this.item();
    var baseValue = this.evalDamageFormula(target);
    var 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);
    value = Math.round(value);
    // Edit: Added in for damage achievements
    if (!target.isActor()) {
        if (value == 666) {
            $gameSwitches.setValue(447, true)
        }
        if (value == 1337) {
            $gameSwitches.setValue(446, true)
        }
    }
    // End fo Edit
    return value;
};

open the rpg_objects file and search for "Game_Action.prototype.makeDamageValue" and that is where you will want to add the edit section I put in near the bottom.

Edit: Forgot to put in conditional to prevent enemies from accidentally making achievement trigger 😛
Which is what I thought of in the first place. One last question I have in this is to verify that a common event will detect the switch change during battle scenes. As stated before I had an issue with moment-based battle events in similar situations (which is probably because of the design specification), and I don't want to change my troop definitions either.

EDIT: I'm getting a "Game_Temp is not defined" condition as well.
Ill try it in a clean project, cause it was working fine with my game... let me make sure im not crazy. Are you using something like YEP Battle Engine Core or someone elses core that may be overwriting the code by chance, aslo what version of MV was your project on? to check that, open the rpg_core.js file and should literally be right at the top.
Problem with your calculation @Andar is that it will only turn true if the value is that before variance, is there a way to make it take the REAL value and trigger the switch?
You can set the skill's variance to zero in the database and include randomness in the damage formula instead, e.g. 20% variance:
Code:
r=a.atk*4-b.def*2; r+=Math.floor(r*0.2*(0.5-Math.random())); if (r==666) {$gameSwitches.setValue(447,true);}; r
[Edited r=666 to r==666 as noted by Aloe Guvner.]

...I'll share a version thats just right for what OP asked for, and it should work if you edit it in yourself to rpg_objects.js as I have (as long as no other plugin overwrites that function)...
For clarity: that code should work fine if you just save it as a .js file and import as a plugin (preferably near the top of the load order, since it's an override). No need to manually edit it in. 😅

Alternatively, since you're only adding code, you could use an alias, e.g.
Spoiler
Code:
(function() {
  var alias = Game_Action.prototype.makeDamageValue;
  Game_Action.prototype.makeDamageValue = function(target, critical) {
    var value = alias.apply(this, arguments);  // get normal value
    // your extra code~
    if (!target.isActor()) {
      if (value == 666) {
        $gameSwitches.setValue(447, true)
      }
      if (value == 1337) {
        $gameSwitches.setValue(446, true)
      }
    }
    return value;
  };
})();
That's something else that I intended to ask as I anticipated the possibility. I'll try the alias method first as I'm not sure where to put this in the Yanfly core.

EDIT: And that'll do it. Wasn't aware of the possibility before, and I have it above all the Yanfly stuff in the plugin list.

EDIT 2: I'm also using MV core 1.6.0.

EDIT 3: This gives me an idea for another plugin, specifically regarding the evac messages in battle scenes for success/fail in getting away.

EDIT 4: In terms of the damage formula I'm doing a similar thing with HP recovery skills.
You can set the skill's variance to zero in the database and include randomness in the damage formula instead, e.g. 20% variance:

I mean I know you can do that, but some people would potentially consider that a wee bit tedious 😉 And I know tedious when it comes to formula's for my game.

Code:
Game_Battler.prototype.flame = function(a, b) {
    if (a.isActor()) {
        damage  = (((a.mat+Math.pow((a.mat/10), 2)))*(100/(100.00+b.mdf))+((a.mat-b.mdf)/2))*1.50
        damage *= 1.40
        damage *= ($gameVariables.value(8)*0.02)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.mdr)
        console.log(a._name+": Flame ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
    else {
        damage  = (((a.mat+Math.pow((a.mat/10), 2)))*(100/(100.00+b.mdf))+((a.mat-b.mdf)/2))*2.25
        damage *= 1.40
        damage *= (b.level*0.05)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.mdr)
        console.log(a.originalName()+": Flame ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
}

I'm not trying to argue and say I'm right and your wrong, but everyone prefers to do their own thing 😀 (also, no commenting on how I shouldn't be using parseInt instead of round 😛 I had reasons, lol)
That's something else that I intended to ask as I anticipated the possibility. I'll try the alias method first as I'm not sure where to put this in the Yanfly core.

EDIT: And that'll do it. Wasn't aware of the possibility before, and I have it above all the Yanfly stuff in the plugin list.

EDIT 2: I'm also using MV core 1.6.0.

EDIT 3: This gives me an idea for another plugin, specifically regarding the evac messages in battle scenes for success/fail in getting away.

EDIT 4: In terms of the damage formula I'm doing a similar thing with HP recovery skills.
It's generally advisable to have aliases lower/later in the load order to avoid unexpected behaviour. This is why "core" plugins should generally be loaded first: they tend to override (i.e. replace) parts of the code entirely, whereas any add-ons simply add code via aliasing. I'd recommend putting that little alias plugin near the bottom of the Plugin Manager list if you're using it, even if it seems to be working as-is. 😅

Also, I think v1.6.0 had some issues, at least in the editor; you may want to consider updating your project files? Instructions can be found in the announcement here in case you're interested: https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-v1-6-1-stable-release.96715/
Small syntax fix, in case anyone tries this in the future -- change "=" (assignment) to "==" (equality)

Code:
r=a.atk*4-b.def*2; if (r=666) {$gameSwitches.setValue(447, true);}; r

Change to
Code:
r=a.atk*4-b.def*2; if (r==666) {$gameSwitches.setValue(447, true);}; r

And yeah, 1.6.0 had 2 major issues with the editor itself (crash when selecting a tileset as an event picture and messed up map hierarchy). You should upgrade to 1.6.2 which fixes these issues without any changes to the game code itself (so it's not exactly relevant for this thread, more of an aside)

Original thread: https://forums.rpgmakerweb.com/threads/damage-roll-to-variable.109607/