% chance to add a debuff

Simple question that I can't seem to find a solution to through googling:
You know how you can make a skill that has a % chance to add a state? Well what if I want to do that with a debuff instead of a state? I assumed it would be simple enough like it is with states, but apparently not because it only gives you the option to chose how many turns the debuff lasts and not a % for applying it...
Database >> Common Event
Create a common event named Debuff 1.
Set a variable with a random value.

Conditional Branch: If the variable is less or equal to 30
Do the debuff
End

(This gives a 30% chance of success, you can change it accordingly and even make an else case)


Skill >> Effects: Double Click >> Other >> Common Event
Select the Common event you made.


It would help out to find a command to set the enemy index inside a variable, to target enemies easier I suppose.
In that case you use a Script in the control variables to set it up and I would love to know how to do this if possible:
If not in battle return 0, else return the Enemy id the user has chosen to cast the spell.
Is this possible? :eswt:

If it's not possible, then you might need to use a Plugin.


So continuing you can create a Conditional Branch according to that variable.
Let's say you wanna change Enemy State, you use the event command and you check one after another, using conditional branches, if the variable equals to 1 or 2 or ... or 6.
Thus for each case you target different enemy, then set that variable to 0.

The past missing from the puzzle is the way to set a variable to the value of a selected enemy (0 of no enemy selected).
Ahh nice. Haven't gotten around to using common events yet, but this sounds simple enough at least. Thanks for the help 🙂
Ahh nice. Haven't gotten around to using common events yet, but this sounds simple enough at least. Thanks for the help 🙂
Edited my reply. Read it carefully. It is not THAT simple. :/
We need someone to give us a simple command to solve this puzzle and you are done.


Edit:
So, it seems we need this:
$gameVariables.setValue(var, value);

var will be the #id of the variable (the number of the slot it resides in the database)

value
I want to set enemyIndex there. How can I refer to enemy index on-the-fly people, or return 0 if there is no id?
Yea, I see now getting the enemy ID isn't that simple. On top of that it doesn't seem like there is a default event command for applying buffs or debuffs (Once again there is for state but not for buffs...). I guess you'd probably need scripting to do it.
Let me move this to a more appropriate thread, so people can help you out.
Moderator note: Moved to a more appropriate place.
Oh, you should be able to do this all in the skill formula! ^_^

You can set a variable's value quite easily in a skill formula thanks to a handy alias v[id] for variable #id; you can get the target's id (assuming they are an enemy!) like so:
Code:
v[1] = b.enemyId()
[Edit: @Dreadshadow whoops, it should be b.index(). Either way, though, I've just discovered an awful loophole in this approach: the damage formula only calculates on hit, meaning the variable might not be set correctly! 😩 I'll reply with more detail, including a failsafe, on your new thread.]

However, I'd recommend simply doing it all in the damage formula itself. Here's an example formula that has a 52% chance to apply a 2 turn mhp debuff, then it always deals 0 damage:
Code:
if (Math.randomInt(100) < 52) b.addDebuff(0, 2); 0
The last "line" (separated by semicolons) in a formula is always the damage (or healing) amount. addDebuff takes two inputs: parameter ID and duration in turns. The parameter IDs are 0~7: mhp, mmp, atk, def, mat, mdf, agi, and luk respectively.

You may find this thread useful~: https://www.rpgmakercentral.com/topic/36290-damage-formulas-101-mv-edition/ (reposted here on RMW: https://forums.rpgmakerweb.com/index.php?threads/damage-formulas-101.81905/ )
Nice @caethyril !
I will create another thread for the remaining piece of my approach.
Thanks! I wasn't aware you could do fancy stuff like that in the damage formula, very useful. The thread seems like it'll be a lot of help too.
This will send you to a thread I asked for that, cause I was curious.
Now all the things on the puzzle are here for you to build what you need.


So this:

Code:
$gameVariables.setValue(40, BattleManager._action ? 1 + BattleManager._action._targetIndex : -999)

Code means:
We will set the value of Variable with id=40
If we are in battle, set the value equal to what this spell targeted,
otherwise set it to -999


inside the formula works like a charm.
I stored the value to the 40th variable.
IS this the only way to run code through battle?
I mean, can you get the current move's targetIndex using the Common Event?
The real question is, what the scope of targetIndex is. Can it be reached from the common event and what the variable would be?


Case is solved, on my behalf, but I am curious to know if you can use a script command from common event and do the same thing.


TO SUM THINGS UP:

Create the skill you need to do the debuff.
Set damage to HP. In the formula, insert this:

Code:
$gameVariables.setValue(40, BattleManager._action ? 1 + BattleManager._action._targetIndex : -999)

Make sure it is certain hit.


Now imagine that the 40th variable is named EnemyIndex.

Database >> Common Event
Create a common event named Debuff 1.

Set a variable named PROB with a random value.

Conditional Branch: If PROB is less or equal to 30
Conditional Branch: If EnemyIndex =1
Change Enemy HP: #1 -10
End


Conditional Branch: If EnemyIndex =2
Change Enemy HP: #2 -10
End


and so on...

End



(This gives a 30% chance of success. Then we check case of Index. Whoever the index belongs, will get a -10HP ddebuff on our example!)

Go back to your Skill.
Skill >> Effects: Double Click >> Other >> Common Event
Select the Common event you made.


And that's how you can set up what you need to do.
Cool, I think I get it. But at least for now I'm probably gonna stick with the other method. Thx anyways 🙂
Is your case solved? 🙂
I'd say so yes
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/chance-to-add-a-debuff.92505/