Creating random effect skill

I've had an idea for a skill that functions kind of like the Wabbajack from the Elder Scrolls. Instead of doing flat damage or inflicting a status effect, it randomizes a variable. Depending on what that variable lands on, it'll pull from a list of effects. From healing the user, drenching everyone in oil (causing all active fighters to take more fire damage), to transforming an enemy into another enemy. Like a chicken.

Doing this in a common event is the way to go, but I hit a roadblock with the transforming part. I noticed there isn't an option to pick the last target, instead you have to pick from a list of enemies on the field. This means that even if you hit enemy 4 and land on chicken time, enemy 1 gets bugawked instead.
Is there a way to set it so the enemy the player attacked is the one getting hit with the status effect? I'll include screen shots below.
1622617428293.png


The options have it so I can choose enemies 1-8 but I can I specify that the last enemy the player targeted is the one that gets chickified?
there is a workaround here - for direct targeting you would need a plugin that creates that ability, but you can trick the engine into remembering with event commands as well.

in the skill that calls the common event (the one that the player targeted), have it apply an invisible state to the target.
By invisible I mean no messages, no icon, no effect, only the named state itself.

Then in the common event, have eight conditional branches for the eight enemy index numbers, each checking if that enemy has the target state applied.
if yes, make your changes to that enemy and remove the state.
You could just make multiple versions of the same skill for each different effect, and each time one is cast, have it be removed removed from the character and then roll a random variable to determine which version of the skill they get to use next time.

And randomise the skill put on the character once again at the start of each encounter, so a player loading the same saved game more than once doesn't run into getting the exact same version to cast each first time they use it in their first next battle.
You can use

BattleManager._subject._lastTargetIndex

to get the enemy index of the target of the actor who used the skill.
there is a workaround here - for direct targeting you would need a plugin that creates that ability, but you can trick the engine into remembering with event commands as well.

in the skill that calls the common event (the one that the player targeted), have it apply an invisible state to the target.
By invisible I mean no messages, no icon, no effect, only the named state itself.

Then in the common event, have eight conditional branches for the eight enemy index numbers, each checking if that enemy has the target state applied.
if yes, make your changes to that enemy and remove the state.
Did this and it works like a charm! Mostly. The enemies do transform correctly, however, there was something I did with the variable that causes every effect to trigger instead of one different effect each time.
I'll include some screen caps in case if anyone face a similar problem, thanks for the help!
1622656111993.png
1622656184376.png

This causes every effect to trigger.
1622656474051.png

Instead of asking if the variable is less than or equal to a number, set the max number to how many effects you're going to use, then ask if the variable is at a number.
The way you have that set up, if the variable is over a certain amount, it will trigger EVERY effect that is below that number as well.

If you don't want to check specific numbers(which could lead to potentially lower variation when used with few effects), instead put further checks inside the else clause of the if statements. This way it ONLY continues checking if the current condition wasn't met.
So basically it would be: If number <= #1, do this. If not (else), check if number <= #2. If yes, do this. If no, check if number <= #3. And so on for each threshold you have.

Original thread: https://forums.rpgmakerweb.com/threads/creating-random-effect-skill.137079/