Question about variables and states

Im trying to make the rpg maker mz battle system be closer to D&D mechanics. I currently have attacks doing an rng check and adding stat modifier to check the def stat to see if it hits and im happy that it is working. The problem that has me stumped is how i would set advantage preferably as a state. is there a way with common events to have the attacking unit check to see if they have advantage or disadvantage to set differing rng to effect the outcome?

my attack common event rolls a RNG20 then this is the damage formula. I just dont know how to make it check for advantage or disadvantage
if (b.def>v[1]+(a.atk-10) / 2) {b.result().missed = true; 0} else Math.max(1, 3+Math.ceil(Math.random()*4)+ ((a.atk-10)/2) )
There have been many threads about recreating D&D mechanics for battle - trying to implement hits and misses inside the damage formula is not a good/correct approach.

By the time the game looks at the damage formula, it's already determined whether you hit. So by just changing it to a miss inside of that, other parts of the skill will/may malfunction.

A more correct approach is to use a plugin like my Custom Hit Formula and properly implement this as the hit roll. You can easily check for the presence of a state to be there and roll for advantage accordingly:
Code:
v[1] = a.isStateAffected(42) ? Math.max(Math.randomInt(20), Math.randomInt(20)) + 1 : Math.randomInt(20) + 1
(if your advantage state is ID 42)

As a side note, why is there any common event involved at all? You can just do the d20 roll at the beginning of your formula.
action seq stuff to have units jump around. that is where i had put the inital v1 random.

Im pretty bad at understanding code, sorry just trying to get a simple system working

◆Common Event:Dice roll
◆Wait:30 frames
◆Plugin Command:VisuMZ_1_BattleCore, MOVE: Jump
: :Targets = ["user"]
: :Desired Height = 100
: :Duration = 12
: :Wait For Jump? = false
◆Plugin Command:VisuMZ_1_BattleCore, MOVE: Move To Target(s)
: :Targets (Moving) = ["user"]
: :Targets (Destination) = ["all targets"]
: :Target Location = front base
: :Melee Distance = 24
: :Offset Adjustment = horz
: :Offset: X = 0
: :Offset: Y = 0
: :Duration = 12
: :Face Destination? = true
: :Movement Easing = Linear
: :Movement Motion = walk
: :Wait For Movement? = true
◆Wait:16 frames
◆Plugin Command:VisuMZ_1_BattleCore, MOTION: Motion Type
: :Targets = ["user"]
: :Motion Type = attack
: :Show Weapon? = true
◆Wait:16 frames
◆Plugin Command:VisuMZ_1_BattleCore, ANIM: Action Animation
: :Targets = ["all targets"]
: :Mirror Animation = false
: :Wait For Animation? = true
◆Plugin Command:VisuMZ_1_BattleCore, MECH: Action Effect
: :Targets = ["all targets"]
◆Wait:15 frames
◆Plugin Command:VisuMZ_1_BattleCore, MOVE: Opacity
: :Targets = ["user"]
: :Desired Opacity = 255
: :Duration = 15
: :Opacity Easing = Linear
: :Wait For Opacity? = false
◆Plugin Command:VisuMZ_1_BattleCore, MOVE: Jump
: :Targets = ["user"]
: :Desired Height = 100
: :Duration = 12
: :Wait For Jump? = false
◆Plugin Command:VisuMZ_1_BattleCore, MOVE: Move To Point
: :Targets = ["user"]
: :Destination Point = home
: :Offset Adjustment = horz
: :Offset: X = 0
: :Offset: Y = 0
: :Duration = 12
: :Face Destination? = false
: :Movement Easing = Linear
: :Movement Motion = walk
: :Wait For Movement? = false
◆Tint Screen:(0,0,0,0), 15 frames
◆Plugin Command:VisuMZ_1_BattleCore, ACSET: Finish Action
: :Immortal: Off = true
: :Wait For New Line = true
: :Wait For Effects = true
: :Clear Battle Log = true
: :Home Reset = true
: :Wait For Movement = true
◆Wait:15 frames
◆Plugin Command:VisuMZ_1_BattleCore, MECH: Multipliers
: :Critical Hit% =
: :Rate = 1
: :Flat = +0.00
: :Critical Damage =
: :Rate = 1
: :Flat = +0.00
: :Damage/Healing =
: :Rate = 1.00
: :Flat = +0.00
: :Hit Rate =
: :Rate = 1
: :Flat = +0.00

------------------------------------------------------------------------------------------------------
◆Control Variables:#0001 DiceRoll Value = Random 1..20
◆Plugin Command:VisuMZ_1_BattleCore, MECH: Variable Popup
: :Targets = ["user"]
: :Variable ID = 1
: :Digit Grouping = true
: :Text Color = #9a8161
: :Flash Color = [0, 0, 0, 0]
: :Flash Duration = 60
◆If:DiceRoll Value = 20
◆Plugin Command:VisuMZ_1_BattleCore, MECH: Multipliers
: :Critical Hit% =
: :Rate = 100
: :Flat = +0.00
: :Critical Damage =
: :Rate = 2
: :Flat = +0.00
: :Damage/Healing =
: :Rate = 1.00
: :Flat = +0.00
: :Hit Rate =
: :Rate = 100
: :Flat = +0.00
◆
:Else
◆
:End



This is what i have been using and it seems to be functioning but i still am not sure how to get the check for advantage on the damage formula
You might want to look up a few of those existing threads I mentioned, and/or look at the plugin I suggested.

Then with those, combined with the code I supplied above, if you have a hard time getting some part of it to work, let us know specifically what.

You posting that stuff initially made it look like you had some idea what you were doing, and you were just doing it the wrong way - but if all that code doesn't really mean anything to you and you copied it from someone else doing it the wrong way, that's not helpful 😛

In your Dice Roll common event, you simply use Conditional Branches to see whether you should roll 1d20 or 2d20 and keep the highest value.

Then you take all that junk out of your damage formula, install my Custom Hit Formula, and put the check for hitting based on the die roll in there.

Leave the damage formula for the damage.

Try doing that, and if you don't understand how to do a part, let us know.
I was using the common events to roll to make a nat 20 a critical. Is that possible to do in the damage formula?
Of course, you'd disable the critical hit on the skill itself and just put a conditional in that says if the variable is 20, double the damage.

But I'd strongly suggest doing one thing at a time - get the hit formula working correctly, then worry about adjusting anything that correctly goes in the damage formula that you can't figure out.

When you do work your way back around to that, here's a reference for you.

Original thread: https://forums.rpgmakerweb.com/threads/question-about-variables-and-states.174183/