Yanfly Plugins causes user.forceAction infinity loop BUG? (SOLVED!)

Urashima09

Villager
Member
Joined
Apr 27, 2017
Messages
29
Reaction score
5
First Language
Portuguese
Primarily Uses
RMXP
Greetings

Just tried to use user.forceAction(skill id, target index) inside the following notetags:

<Custom Action Start Effect>
user.forceAction(9,-2);
</Custom Action Start Effect>

or

<Custom Action End Effect>
user.forceAction(9,-2);
</Custom Action End Effect>

like
1588039914425.png

The skill 9 is used, but, it causes a infinity loop until I don't have MP enought to Skill 9.
I'm using default battle system, and pretty all Yanfly plugins, but this notetag is from:

Help, pls!
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,551
Reaction score
8,159
First Language
German
Primarily Uses
RMMV
what order are your plugins in?

usually if yanfly's plugins behave strangely that is caused by one or more of those plugins out of the order sequence they are required to be in.
 

Urashima09

Villager
Member
Joined
Apr 27, 2017
Messages
29
Reaction score
5
First Language
Portuguese
Primarily Uses
RMXP
I'm preety sure its the same order of the Yanfly wikia:

1588040875392.png
1588040894040.png
1588040909950.png
1588040926564.png
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
927
Reaction score
580
First Language
English
Primarily Uses
RMMV
The problem isn't with the plugin, it's with the fact that you're causing an infinite loop on your own.

Forcing an action still causes an action to happen, and you're attaching a forced action to action start (or end) which is happening when the forced action starts (or ends).

Turn end might be better, or at least, it won't cause an endless loop anymore, but it might not do whatever else it is you're trying to do.
 

Urashima09

Villager
Member
Joined
Apr 27, 2017
Messages
29
Reaction score
5
First Language
Portuguese
Primarily Uses
RMXP
The problem isn't with the plugin, it's with the fact that you're causing an infinite loop on your own.

Forcing an action still causes an action to happen, and you're attaching a forced action to action start (or end) which is happening when the forced action starts (or ends).

Turn end might be better, or at least, it won't cause an endless loop anymore, but it might not do whatever else it is you're trying to do.

I see, thank you for answering.
So, to prevent the loop, I inserted a counter to check if the second skill is already used, like this:

<Custom Turn Start Effect>
user._counter= 0; //Set the counter to 0 again
</Custom Turn Start Effect>

<Custom Confirm Effect>
if (user._counter== 0){
user.forceAction(25,-2);
user.forceAction(24,-2);
user._counter+= 1;
}
</Custom Confirm Effect>

That's enought to prevent looping, but, only the second line (a bold one) is read. If I have 2 States, one for skill 25 and another for skill 24, after the first one runs, the turn is skipped and the second still ignorated.

Can you help me? :confused:
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
927
Reaction score
580
First Language
English
Primarily Uses
RMMV
In that case you're forcing two actions at once. The effect isn't immediate, but you're essentially telling the engine to queue up skill 25 and then immediately telling it to queue up 24 instead.

If you want multiple skills to trigger, you'd need to use multiple states, and different counter variables to keep track of them all. But I don't think that'll work, because multiple sources of forceAction will probably overwrite eachother, just like in your example.
 

Urashima09

Villager
Member
Joined
Apr 27, 2017
Messages
29
Reaction score
5
First Language
Portuguese
Primarily Uses
RMXP
Yes, I tried with multiples states and differents counters, but it's the same: only one state take effect...

Any idea how to trigger multiple skills? I already tried <Instant> notetag to prevent skip my turn
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
927
Reaction score
580
First Language
English
Primarily Uses
RMMV
In your sample code, you have two actions being triggered if the variable is 0. I would suggest making the first action trigger if the variable is 0, and the second trigger if it is 1. This way, when the first forced action occurs, it will increment the variable to 1, and trigger the second one, which should increment it to 2.

JavaScript:
<Custom Confirm Effect>
if (user._counter == 0){
    user.forceAction(25,-2);
    user._counter+= 1;
} else if (user._counter == 1) {
    user.forceAction(24,-2);
    user._counter+= 1;
}
</Custom Confirm Effect>
 

Urashima09

Villager
Member
Joined
Apr 27, 2017
Messages
29
Reaction score
5
First Language
Portuguese
Primarily Uses
RMXP
Brilliant! I couldn't expect less from a Beoulve :D (FFT is my fav game ever, all plataforms, all times, all genres)

So, it's worked. I need to trigger differents Skills depending which State or States the actor has. Im your code, if user haven't a State to use the first skill (25), counter not increase, and user cannot uses the Skill 24 :(

So, I tried the following adaptation:

JavaScript:
<Custom Turn Start Effect>
user._counter = 0; // Set to zero again
</Custom Turn Start Effect>

<Custom Confirm Effect>
if (user._counter == 0){ //0: Skill 24 (Firebolt) is used IF user have State 45 (Fire Aura)
    if (user.isStateAffected(45)){
        user.forceAction(24,n); }
    user._counter+= 1;
}
   
if (user._counter == 1) { //1: Skill 25 (Thunder) is used IF user have State 44 (Thunder Aura)
    if (user.isStateAffected(44)){
        user.forceAction(25,n); }
    user._counter+= 1;
}

if (user._counter == 2) { //2: Skill 9 (Aqua) is used IF user have State 46 (Water Aura)
    if (user.isStateAffected(46)){
        user.forceAction(9,n); }
    user._counter+= 1;
}
</Custom Confirm Effect>

For some weird reason, if actor have the three States in my code, the middle one skill (Thunder) is used properly, all others actors and enemies performe their actions, and in the turn ends the actor uses the first skill (Firebolt), not using the third at all.

Any idea? :C


This "Firebolt" thing etc is just to illustrate what I'm really trying to do. Sorry if it looked kind of silly.
In fact, what I want is to make a "Summon System". I want to be able to conjure monsters to fight for the actors, or else live weapons like animated swords. As I use Yanfly plugins, I never found a compatible summon plugin. My solution was to turn them into States, using counters like HP and skills as their attacks. Therefore, I need this code to consider that I have some creature summoned without having another, and also that I have more than one. I accept any other kind of idea, too, and thanks for the help.
 
Last edited:

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
927
Reaction score
580
First Language
English
Primarily Uses
RMMV
I see what you're doing here now, and we've got a problem.

The incremented variable thing that I suggested was for if one state was responsible for two (or more) skills being forced. If there are multiple states forcing a single action, I don't think that's the way to get that to work.

Before I try to come up with a way that it might actually work though, have you considered the game balance repercussions of having one actor capable of doing one skill and having three additional skills go off? Personally, I'd say both from a game balance standpoint, and also a... physics? standpoint that a single actor probably shouldn't be able to have more than one of these passive buffs that cause extra spells on them at the same time.

And really, if you made them mutually exclusive, that solves all of the issues with multiple spells not going off.

Forced actions are wonky at the best of times. Which enemy ends up targeted if the skill that triggered the effect hit an ally? How about if it hit all enemies? What if it hit the user? Yanfly actually did something to neuter forced actions back when the ATB and CTB plugins were still supported because forced actions were causing some sort of infinite looping problem too.
 

Urashima09

Villager
Member
Joined
Apr 27, 2017
Messages
29
Reaction score
5
First Language
Portuguese
Primarily Uses
RMXP
About balance: My intention is to simulate more than 4 or 5 actors in the battle. Sometimes, much more. I explained this in the top spoiler, but not in the main topic because I didn't think it was necessary to increase the text. In fact, it is not the actor who is really doing anything. The actor casts 1 skeleton and 1 fire elemental to protect him. "Skeleton" is a State that performs the "Sword" Skill and has 100 HP, and "Elemental" is another, which performs the "Fireball" Skill, and so on. Upon hitting the caster, they lose HP via <Custom React Effect> which decreases state counters.

I created a main State, which checks if the other 'monsters are conjured', that is, if the actor has the other states. This main State, which is the code we are making, is the one who governs what skills the cast monsters will use per round, while the other states, in addition to saying this to the main, control the amount of HP of the monsters, remaining turns, and show for the player these things. That is, even with multiple states, only THIS forces the actions, the rest are for other things.

I am almost sure that, with the right logic, it is possible to check if and what states are applied to force the correct actions at the end of the player's action, taking advantage of the loop. But I need help thinking about this code. =/
 

Urashima09

Villager
Member
Joined
Apr 27, 2017
Messages
29
Reaction score
5
First Language
Portuguese
Primarily Uses
RMXP
@ramza, I thought of something. Since I have no idea how to work with arrays, I will try to describe what I imagined could be a programming logic to solve the problem using its mutually exclusive logic.

The idea is that each skill that represents each summon, when applied, adds a value at one position in an array. The order I think doesn't matter. So, instead of calling a predetermined skill, we create a variable (let's say, "skill") that receives the first position in the array, and then we call that variable within forceAction (skill, -2). Then, after use, in addition to the counter, we update the skill variable to the second position of the array, which is also called and so on.

At the end of the battle, by removing the main State, it clears the array.
I need your help to know which terms to use to deal with arrays

Idea outline:

Each state except main state has:
JavaScript:
//Every State (EXCEPT THE MAIN STATE) such 'Fire Aura',
//'Thunder Aura' and 'Water Aura', once applied, pull
//their skills into a array, like:
<Custom Apply State>
user._somearray[] += 25; //Adds skill 25 to array
</Custom Apply State>

<Custom Remove State>
user._somearray[] -= 25; //Remove the skill 25, so since the summon was dead don't performe skill 25 anymore
</Custom Remove State>

And main state are:
JavaScript:
<Custom Confirm Effect>
//Check if array is empty
if (!arrey.is.empy.code.here){
    //If dont, get the first skill
    var skill = user._somearray[first skill];

if (user._counter == 0){
    user.forceAction(skill,-2);
    user._counter+= 1;
    //then get the second position
    skill = user._somearray[second skill];
} else if (user._counter == 1) {
    user.forceAction(skill,-2);
    user._counter+= 1;
    //then get the third position
    skill = user._somearray[third skill];
} else if (user._counter == 2) {
    user.forceAction(skill,-2);
    user._counter+= 1;
}

}
</Custom Confirm Effect>

<Custom Remove State>
//clear the array
user._somearray[] = undefined;
</Custom Remove State>
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
927
Reaction score
580
First Language
English
Primarily Uses
RMMV
Alright, we can try an array for that.

JavaScript:
<Custom Apply Effect>
    if (!user._afterEffects) {
        user._afterEffects = []
    }
    user._afterEffects.push(25)
    user.addState(X)
</Custom Apply Effect>
<Custom Remove Effect>
    var index = user._afterEffects.indexOf(25)
    if (index > -1) user._afterEffects.splice(index, 1)
</Custom Remove Effect>
This is your 'summon' state. When the state is applied, it checks to see if the user._afterEffects array exists, and if it doesn't it creates it. After it knows the array exists, it pushes 25 to it, the skillId of the skill to use. If the state is removed, it doesn't delete the array, it removes an index which contains 25 from it.

This state is for your one specific example of lets say a skeleton. If it dies, and the state is removed, we don't want it killing all of your summons at once, so it only removes the skeletons skill from the array.

Next, you need a new state, which is used solely to spam after effect skills. This state is added on the apply effect above, change the X to it's Id. All of the summon states should all add the same state. There should be only one of these states. You could summon a monkey, a skeleton, a fire elemental and an elephant, and they all add their own unique state above and each of those states only adds this one state below.

The new state is going to have a confirm effect similar to what we already had, but using the array. It's going to grab the first value from the array, as pushed to it above, and forceaction that, then increment a counter variable so at the end of that force action it will know to do the next one on the next go around.

JavaScript:
<Custom Confirm Effect>
    user._counter = (user._counter != undefined) ? user._counter + 1 : 0
    if (user._afterEffects[user._counter]){
        user.forceAction(user._afterEffects[user._counter], -2)
    } else {
       user._counter = undefined
    }
</Custom Confirm Effect>
What this should do, is after using any skill that hits it will force the first skill in the array. When that skill hits, it will increment the counter and use the next skill in the array. Then the next, until the counter gets higher than the number of skills in the array. At that point, nothing should happen and the turn should end on it's own.

At the end of the next action, the same thing should happen.

Keep in mind this might cause an infinite loop, if one of the skills added adds another force action to the list.
 
Last edited:

Urashima09

Villager
Member
Joined
Apr 27, 2017
Messages
29
Reaction score
5
First Language
Portuguese
Primarily Uses
RMXP
What can I say? You are the man

This thread can be closed!
(I always wanted to say that)
 

Latest Threads

Latest Profile Posts

here's another RPG Maker remake idea: "Plumbers Don't Wear Ties". I'll salute to whomever does this
I won't finish it today, I only will have time to work on that next Saturday, what a shame... :(
I made something for @LittenDev [as he requested]
It's been a weird while. I've been so torn down that even playing video games has been something I avoided. But I shouldn't forget two things. One, I love RPG Maker for a reason. Two, only way to eat an elephant is a bite at a time.

Forum statistics

Threads
111,388
Messages
1,060,742
Members
144,732
Latest member
Jamie1976
Top