Force Random Action

So I made this item called "D20" which lets you use a move in battle that rolls the D20, I wanted to make the user (actor 2, only she can equip it so thats not an issue) forced to use a random action, and I thought i was onto something when I realized "Force Action" doesn't take variables.. so now im lost
The equivalent script call for Force Action is something like this:

JavaScript:
let skillId = 29, target = 3;
let subject = $gameActor.actor(5); // or $gameTroop.members()[2] or $gameParty.members()[7] etc
subject.forceAction(skillId, target);
BattleManager.forceAction(subject);
this.setWaitMode('action');

So if you substitute what you need into that and put it in a script call, it should do what you want.
The equivalent script call for Force Action is something like this:

JavaScript:
let skillId = 29, target = 3;
let subject = $gameActor.actor(5); // or $gameTroop.members()[2] or $gameParty.members()[7] etc
subject.forceAction(skillId, target);
BattleManager.forceAction(subject);
this.setWaitMode('action');

So if you substitute what you need into that and put it in a script call, it should do what you want.

Where do i put the variables, and what does each number mean :0?
Replace 29 with the skill ID, 5 with the actor, and 3 with the target of the action. I think 3 means the fourth enemy or (if the skill is used by an enemy) the last actor in the battle party.

To use a variable, replace one of those numbers with:

JavaScript:
$gameVariables.value(32)

where 32 is the variable ID.
Replace 29 with the skill ID, 5 with the actor, and 3 with the target of the action. I think 3 means the fourth enemy or (if the skill is used by an enemy) the last actor in the battle party.

To use a variable, replace one of those numbers with:

JavaScript:
$gameVariables.value(32)

where 32 is the variable ID.
Ooo thanks thanks, but is there a way to make it force the action on a random enemy, or whatever enemy was targeted?
Of course. To target a random enemy, replace the target (3) with the following code:

JavaScript:
Math.randomInt(8)

To use a random skill, replace the skill ID (29) with the following code:

JavaScript:
[12, 42, 100][Math.randomInt(3)]

In the above code, you can add as many skill IDs as you want, separated by commas. The number in parentheses needs to be the same as the number of skills. If you want to pick a skill from a certain range (for example, any skill from 21 to 47), then you could use the following code instead:

JavaScript:
21 + Math.randomInt(47 - 21)

Since both of those codes are kind of long, you can make the script a little more readable by splitting it into two lines:

JavaScript:
let skillId = ...
let target = ...
Will that still use smoothTarget, Solar?
Of course. To target a random enemy, replace the target (3) with the following code:

JavaScript:
Math.randomInt(8)

To use a random skill, replace the skill ID (29) with the following code:

JavaScript:
[12, 42, 100][Math.randomInt(3)]

In the above code, you can add as many skill IDs as you want, separated by commas. The number in parentheses needs to be the same as the number of skills. If you want to pick a skill from a certain range (for example, any skill from 21 to 47), then you could use the following code instead:

JavaScript:
21 + Math.randomInt(47 - 21)

Since both of those codes are kind of long, you can make the script a little more readable by splitting it into two lines:

JavaScript:
let skillId = ...
let target = ...
Thanks!! I think I understand, although when I put it in it didn't exactly work, maybe i dont know where to put the script?
1595339301877.png
i did this
Will that still use smoothTarget, Solar?
I didn't check. I was assuming it would though - using Math.randomInt(8) relies on it.

@AriDingus That screenshot appears to be correct, so either it's a problem with the code itself or you've put it in a place that's not actually getting called.

So we can eliminate one possible issue, can you try it in a troop with exactly 8 enemies, without any hidden enemies? If it works there but not in smaller troops, then it's an issue with smoothTarget not being called.
where do I put smoothTarget @Solar_Flare ?
I would try without it first, as I don't know if it's even needed.

Original thread: https://forums.rpgmakerweb.com/threads/force-random-action.124282/