How to have a weapon inflict a random effect

I want a weapon to inflict a random attack on an enemy.
Health damage, mana damage, poison, silence or even an insta-kill... but I want that to be randomly picked.
How would I go about doing this?

So far I have the following:
- The weapon (Chaos Staff) adds the magic skill: Chaos Attack.
- That skill (Chaos Attack) triggers a Common Event: Random Attack.
- The Random Event picks a number between 1-10... and after picking the number it inflicts the effect on the enemy.

But It is not working.
I'm probably missing something obvious, but I don't know what.

Schermafbeelding 2024-05-11 110208.png

Schermafbeelding 2024-05-11 110033.png

Schermafbeelding 2024-05-11 110044.png
You gave the skill to the actor to be used through skill selection (magic), but didn't change the default attack skill for the staff.
assuming that is what you want, because "not working" didn't tell you if it is not working when selected through magic or when pressing attack.
You gave the skill to the actor to be used through skill selection (magic), but didn't change the default attack skill for the staff.
assuming that is what you want, because "not working" didn't tell you if it is not working when selected through magic or when pressing attack.
Sorry for being unclear.
I did mean that using the skill Chaos Attack (which you get when wielding the staff) did not work... not the base attack of the staff.
I now changed the base attack of the staff to the Chaos Attack, and now it works.

Not exactly what I wanted, but for now I know it works... sort of.
If you're satisfied, OK.
if yo still want to figure out the cause we'll need more info about your plugins and your battlesystem and so on, because by defalt that skil should work.
I don't use plugins for this, and I'm mostly happy with how it works, except for one issue.
I cannot have the target be randomly selected.
In the Skill settings > Scope: I have it set to 1 random enemy.
Yet the Common Event says I have to pick enemy 1,2,..,6. Or the Entire Troop

I don't want the Entire troop to be affected, as it will be slightly over powered, but setting it to Enemy 1 always targets that enemy... never another.
You can store the Last Target Enemy Index in a variable:
  • Control Variables -> Game Data -> Last -> Target Enemy Index
However, I think it'd be worth using a Script command here. E.g. for the "add state" effects:
JavaScript:
// Get reference to Last Target Enemy
const target = $gameTroop.members()[$gameTemp.lastActionData(5) - 1];
// Apply effect to them
target.addState(42);
For the other effects in your screenshot, I think you could use:
  • Change HP = this.changeHp(target, -100, true);
  • Change MP = target.gainMp(-100);

Otherwise, you would need a bunch of extra Conditional Branch commands ("if target index = 1, affect enemy 1; if target index = 2, affect enemy 2; etc") inside each of your existing branches. That's doable, but tedious. 😴

[Edit: added -1 to script call, because "Last Index" is stored starting from 1, not 0.]
You could try this as a script call:
JavaScript:
const target = $gameTroop.randomTarget();
if (target) {
const value = 300;
const stateId = 7;
target.gainHp(-value); // add this line if you want the enemy to lose HP
target.gainMp(-value); // add this line if you want the enemy to lose MP
target.addState(stateId); // add this line if you want to add a state to the enemy
}
Ty for the replies and suggestions folks.

I'll see if I can get this to work later.
You can also use a plugin like my Eval Tags or VisuStella's Battle Core to put a notetag on the skill and run code at the end of every attack.

Most of the actual code would be the same as what @caethyril gave, but you would be provided a target variable without having to get it from the BattleManager, and you wouldn't need to take up a Common Event slot at all.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-have-a-weapon-inflict-a-random-effect.168567/