Making a skill with Random Effects

Animebryan

Need more resources!
Veteran
Joined
Jul 31, 2012
Messages
394
Reaction score
189
First Language
English
Primarily Uses
RMMV
Is there a way to make a skill that has random effects? Like the Chance spell from the Dragon Quest series.
 

Animebryan

Need more resources!
Veteran
Joined
Jul 31, 2012
Messages
394
Reaction score
189
First Language
English
Primarily Uses
RMMV
All that does is add a random state. I'm looking for a way to make a skill that randomly chooses another skill from a set of skills.
 

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
99
Reaction score
23
First Language
English
Primarily Uses
RMMV
The thing that immediately jumps to mind for me is to make the Skill save the user of the skill and target of the skill as variables. I think you can do this in the damage formula by setting variable X to "a.index" and variable Y to "b. index," and then run a common event. I believe it would look like this.

Code:
$gameVariables.setValue(X, a.index); $gameVariables.setValue(Y, b.index); $gameTemp.reserveCommonEvent(n);
The common event will set a variable to a random value, then have a conditional branch where there's a different skill for each value. Each branch will then have the command:

Code:
$gameParty.members()[$gameVariables.value(X)].forceAction(skillId, $gameVariables.value(Y));
 

yeahchris

Veteran
Veteran
Joined
Apr 14, 2020
Messages
86
Reaction score
23
First Language
English
Primarily Uses
RMMV
You have two options that I am aware of. One would be to make your skill run a common event as Damascus suggested, save user and target as variables, choose a skill randomly, and then execute. This would be best if you want your skill to have a small list of possible effects.

Then there is this plugin: http://sumrndm.site/metronome-skill/

This will allow you to tag a skill such that it automatically executes any one skill from your project's database randomly except those that you have specifically tagged to be exempt. This may be preferable if you want a huge number of possible effects.

Personally I would recommend the common event.
 

Animebryan

Need more resources!
Veteran
Joined
Jul 31, 2012
Messages
394
Reaction score
189
First Language
English
Primarily Uses
RMMV
The thing that immediately jumps to mind for me is to make the Skill save the user of the skill and target of the skill as variables. I think you can do this in the damage formula by setting variable X to "a.index" and variable Y to "b. index," and then run a common event. I believe it would look like this.

Code:
$gameVariables.setValue(X, a.index); $gameVariables.setValue(Y, b.index); $gameTemp.reserveCommonEvent(n);
The common event will set a variable to a random value, then have a conditional branch where there's a different skill for each value. Each branch will then have the command:

Code:
$gameParty.members()[$gameVariables.value(X)].forceAction(skillId, $gameVariables.value(Y));
Doesn't work
 

yeahchris

Veteran
Veteran
Joined
Apr 14, 2020
Messages
86
Reaction score
23
First Language
English
Primarily Uses
RMMV
So, for clarity's sake,

This definitely works:

Code:
$gameParty.members()[$gameVariables.value(1)].forceAction($gameVariables.value(3), $gameVariables.value(2));

BattleManager.forceAction($gameParty.members()[$gameVariables.value(1)]);
Insofar as it seems to make the party member with the index saved to variable 1 use the skill with the skillID saved to variable 3 on the enemy/friend with the index saved to variable 2. Populate variable 3 with some random numbers and you have a skill with random effects.

The difficult part is saving the skill user and target indexes to variables 1 and 2.

Not sure I'll be able to help with that. But maybe it gives you an idea of what you need to ask others who are better versed in this stuff.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,216
Reaction score
1,116
First Language
English
Primarily Uses
RMMV

Note that while this only allows for single target spells, you can get around this by using yanfly's action sequence packs to force the targeting via Whole Action and keywords like opponents, friends, user, all alive, all not user, etc. Example:

Generic AoE spell to be activated via Chance, even if the chance skill itself is a single target ability:
Code:
<Target Action>
</Target Action>
<Whole Action>
perform action
action animation: opponents
wait for animation
action effect: opponents
death break
perform finish
</Whole Action>
Generic ST spell to be activated via Chance:
Code:
<Target Action>
</Target Action>
<Whole Action>
perform action
action animation: targets
wait for animation
action effect: targets
death break
perform finish
</Whole Action>
 

Animebryan

Need more resources!
Veteran
Joined
Jul 31, 2012
Messages
394
Reaction score
189
First Language
English
Primarily Uses
RMMV
Yeah, I'm not too familiar with Yanfly's Action Sequences Packs, but I am using his Target Core to setup some custom targets.
I've already setup all 20 possible effects & the targets vary quite a bit.

Targets:
All Allies: 5
All Enemies: 3
Everyone: 7
4 Random Enemies: 1
User: 2
1 Random Enemy or Ally: 1
???: 1 (Escape Battle effect)

One major tricky problem is 1 of the effects is supposed to Revive, fully heal HP/MP & remove all states from the entire party, including allies that are alive & dead. I was hoping Yanfly's Target Core would fix that differentiation between alive & dead but it doesn't. I have the default plugin DeadOrAliveItem which makes it possible to target a single or multiple targets regardless of whether they're dead or alive, but I've had crashes when using it with Yanfly's plugins. Why Yanfly didn't take this plugin & incorporate it into his Target Core is beyond me.

I've also tried the straight forward approach by setting the main skill to call on a common event which generates a random number then uses conditional branches with Force Action to use the selected effect, but the stupid thing has a limited setting for 'Subject' (aka User). setting a target is redundant because each effect already has a target set (including custom plugin based ones like Everyone & 1 Random Enemy or Ally.

If only I could use a script call to identify the user of the original skill then that's all I would really need, along with being able to target dead or alive targets together somehow.
 

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
99
Reaction score
23
First Language
English
Primarily Uses
RMMV
I think Action Sequences could help a lot here, as they can override what the actual target of the Skill is. For example, if in the Action Sequences you have "action effect: target" it will target what is actually listed in the dropdown menu for target. But if you instead have "action effect: all friends" it will target your whole party regardless of what is listed as the target in the dropdown menu. Can't test it right now, but I believe this should also override the target listed with the Force Action command.

The method I listed above should still save the user of the skill and apply it to Force Action. As for all the possible targets you listed, there are options for all of those in Action Sequences, except for random targets. Which, come to think of it, feels like quite an oversight. Luckily, none of your choices involve manually selecting a target, which I think makes things a bit easier, so you can rely on Action Sequences to set the target(s) automatically.

EDIT: I did manage to do some testing, and realized I made a few mistakes. The Force Action command uses the Actor ID, and not the Index, so I should be using "a.id" and not "a.index". However, my damage formula is not saving a.id to a variable as desired, and I can't determine why.

A little workaround is to have a separate "Randomizer" skill and common event for every actor. Then in the common event you will just use the standard command under each conditional branch like so

Code:
Force Action : Marsha, Party Restore, Last Target
The target ultimately doesn't matter if it's being overriden by Action Sequences.

Gave this a test myself and it worked great. I had it select randomly from four different skills, and each one used the appropriate targets for itself.
 
Last edited:

Animebryan

Need more resources!
Veteran
Joined
Jul 31, 2012
Messages
394
Reaction score
189
First Language
English
Primarily Uses
RMMV
Having it divided for different actors is ridiculous. That's way too complicated of a workaround for something so simple. It also wouldn't work because the spell is granted by an Augment (Yanfly's Attachable Augments plugin), which can be equipped by anybody. The fact that Yanfly's Action Sequences don't include random targets makes me not want to rely on it.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,216
Reaction score
1,116
First Language
English
Primarily Uses
RMMV
Changing the targeting (as in, targets selected by the player) is a bit tricky for people unfamiliar with code though. It really is advisable to learn how the action sequence system works, because that way, you can pretty much disregard that target selection (using the Shades of Black method I posted above) when the Chance skill redirects to whatever effect it's supposed to cause. All of the things you listed are doable with action sequence-based selection:

All Allies: action effect: friends
All Enemies: action effect: opponents
Everyone: action effect: all alive
4 Random Enemies: action effect: random 4 enemies (see below)*
User: action effect: user
1 Random Enemy or Ally: action effect: random 1 everyone (see below)*

* Okay so random targeting doesn't exist in yanfly's action sequence system natively, but I made a plugin that adds it: AES_X_ActSeqRndTarget

So, if you use the Shades of Black method, you'd have your "Chance" spell be the skill with all the stuff copypasted from the yanfly tips/tricks page, then create each of its effects as a separate skill. When Chance transfers control from itself to whatever skill it randomly selects, that skill will inherit whatever Chance's user-based targeting selection was (user, all enemies, etc) which is...not desirable. By using the action sequences I posted in my previous post:

Code:
<Target Action>
</Target Action>
<Whole Action>
perform action
action animation: TARGET
wait for animation
action effect: TARGET
death break
perform finish
</Whole Action>
You can replace TARGET with a keyword (friends, opponents, all alive, random 1 everybody, etc) to override Chance's default targeting. This way, you can make it look nice and professional by having Chance target just the user while the effect hits, say, all the enemies or all the allies.

Edit: Note that for the 4 random enemies, that can be a bit trickier depending on how you want the skill to behave:

4 random enemies, 1 at a time - traditional RM behavior:

Code:
<Target Action>
</Target Action>
<Whole Action>
perform action
action animation: random 1 enemy
wait for animation
action effect: same
action animation: random 1 enemy
wait for animation
action effect: same
action animation: random 1 enemy
wait for animation
action effect: same
action animation: random 1 enemy
wait for animation
action effect: same
death break
perform finish
</Whole Action>
In contrast, there's also the option to hit up to 4 different random enemies in one shot, without hitting the same one twice:

Code:
<Target Action>
</Target Action>
<Whole Action>
perform action
action animation: random 4 enemies
wait for animation
action effect: same
death break
perform finish
</Whole Action>
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,652
Reaction score
1,105
First Language
EN
Primarily Uses
RMMV
However, my damage formula is not saving a.id to a variable as desired, and I can't determine why.
Try a.actorId() or a.actor().id instead. Assuming the user is an actor, a is an instance of Game_Actor, which has no id property. a.actor() returns the database record ($dataActors) associated with that actor, which does have an id property. May also want an a.isActor() check in there in case enemies can use the skill. :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts


:3c here's a thing i made a while while while back
Tried mochi for the first time. It's quite nice. Has a pleasant smell and taste, and is nice and chewy.
made a bio for the protag in my project!
Beggar : "I haven't eat for days..."
Kid : "Just do crime! You will get daily necessity for free in prison~"

Forum statistics

Threads
99,159
Messages
962,454
Members
130,725
Latest member
teendinsaikha
Top