Dice Damage

So I want some kind of dice rolling mechanic for damage. Here's what I want to happen:

  1. Choose a number between 1 and 20. Add a possible weapon modifier (based on the weapon you have) to roll. Set to variable (for this example, variable 9).
  2. Show dice roll number with weapon modifier on screen using equation (d20 + [WM] = [DR], where [WM] is the weapon modifier, and [DR] is the dice roll with weapon modifier) in the middle of the screen.
  3. Deal damage based on dice roll with weapon modifier.
This game is going to have a DND feel to it. So is there a possibility to do this?
Number 1 and 3 can be done using your damage formula:
Code:
var randNum = 1 + Math.floor(Math.random() * 20);
The code abode generates a random number between 1 and 20. You can then add "randNum" to your weapon modifier to inflict damage in the same way you add other parameters to the damage formula, just be sure that the formula used for damage is the last part of your formula box contents.

The second depends on how you want to show the number. It can be done with a simple message window telling you how high the roll was, or it can be done in a different way, but they vary greatly depending on how you want it to be displayed.
Number 1 and 3 can be done using your damage formula:
Code:
var randNum = 1 + Math.floor(Math.random() * 20);
The code abode generates a random number between 1 and 20. You can then add "randNum" to your weapon modifier to inflict damage in the same way you add other parameters to the damage formula, just be sure that the formula used for damage is the last part of your formula box contents.

The second depends on how you want to show the number. It can be done with a simple message window telling you how high the roll was, or it can be done in a different way, but they vary greatly depending on how you want it to be displayed.

I suppose I wasn't specific enough. I want the damage to be (x / 20) - b.def, where x is a.atk * variable 9.
I want the damage to be (x / 20) - b.def, where x is a.atk * variable 9
Unfortunately, this is even more confusing, because this formula has no random value in it. How is damage affected by that random value?
You could have a common event set a variable between one and twenty in a skill and (using a follow up skill plugin) have the formula check the variable. Although, this would mean you would need to make two skills for each skill that uses that. Is there a plugin that lets you run a common event before everything else in the skill? If there is, you would only need one skill to do this
@Oddball why would you do it that way if it can already be done in a much easier way using the damage formula itself? MV formula box has been greatly improved compared to VX Ace's, with a much larger number of characters allowed. Even if the OP wants to assign a random value to a variable it is still possible within the formula. Using a common event and a plugin for something that the engine already does sounds very redundant.
then how about this?

Math.randomInt(21)+((wm)) = damage output

It would return a random number between 1 and 20 and add the weapon modifier

I refrenced this thread
https://forums.rpgmakerweb.com/index.php?threads/damage-formulas-101.81905/
Math.randomInt(21)+((wm)) = damage output
When assigning a value to a variable you have to place that variable before the value you are assigning to it, like this:
Code:
var dmgOutput = Math.randomInt(20) + 1 + wm;
On top of it, the correct syntax is
Code:
Math.randomInt(20) + 1
and not
Code:
Math.randomInt(21)
Using the latter generates a random number from 0 to 21, which is not a random d20 roll (from 1 to 20). The former, on the other hand, generates a random number between 0 and 19 and then adds 1, resulting in the random value range being [1, 20], which is exactly what you need to simulate rolling a d20.

However, this does not answer my question. In the OP formula there is no random value at all, we can only assume that he wants his variable 9 to have a random value, but without a word from him there is no way we can know that for sure.
Alright, let me explain this once again. Here are the steps in order that I want to take. In this, let the dice land on 12, a character's attack power be 60, and the weapon's modifier be 1.
  1. Roll a dice. This turn, the dice lands on 12.
  2. Add the weapon modifier to the dice roll. The weapon modifier is 1.
  3. Show the dice roll in the center of a screen, in the equation [Dice roll] + [Weapon modifier] = [Total amount]. In this example, 12 + 1 = 13.
  4. Damage the enemy using the equation ([Total amount] * [Attack power]) / 20. In this case, it would be (13 * 60) / 20. That solves to 39 DMG dealt to the enemy.
If you are fine with inverting step 3 and 4, which means that you deal damage and then instantly show the result, you can do it using the damage formula. If you are not fine with displaying damage and message simultaneously (because that is what the player is going to see), then you have to go for a roundabout way.

Either way, you can roll the dice in your damage formula as we suggested in our previous posts using
Code:
var randVal = Math.randomInt(20) + 1;
$gameVariables.setValue(YourVarIDGoesHere, randVal);
((randVal + WeaponModifierGoesHere) * a.atk) / 20

In the common event you can use Show Message, set it to appear in the middle part of the screen and display your variable value, together with any other variable you need to complete that formula. You can use Control Variables commands to set them before displaying the message.

IMPORTANT NOTICE
In the code above I used newlines to increase readability. In your formula box you are supposed to replace them with spaces and put everything on a single line. Do not remove the semicolons or it will not work.
In order to let that code work you have to change everything with "GoesHere" in its name with something meaningful for the engine. It can be a variable, a number, a method, anything you need, as long as you actually change the code and remove those things.
Keep in mind that "YouVarIDGoesHere" MUST be the same value in both the formula and your common event.

Spoiler: The roundabout way
The roundabout way is longer to explain, but, to make things short, you apply a state to the target, store the damage in a variable and deal no damage, then use a common event to display the message and, after closing the message, you scan every enemy looking for that particular state. Once you find it, you deal damage to the enemy affected by that state according to the value you previously stored.
That code works fine so far. Now, all I need is a way to put the roll result in the center of the screen.
The Show Text event command should have an option to set it in the centre of the screen, and if you are using the default font, you should be able to see how much space you need to put it exactly in the middle of the window directly from the said event command text box.
The Show Text event command should have an option to set it in the centre of the screen, and if you are using the default font, you should be able to see how much space you need to put it exactly in the middle of the window directly from the said event command text box.

How can I use the show text event during the turn?
Call Common Event > Show Text
It works! Thanks!
Well, i tried to be helpful. Guess i should learn to know when i'm talking out of my arse
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/dice-damage.112850/