MV Chain Lightning Skill?

Hello!

I am trying to make a Chain Lightning skill, where the skill will automatically trigger another version of it depending on RNG.

Currently, what I have is this:

JavaScript:
<After Eval>
var chance = (Math.randomInt(10) +1);
if (chance >= 5){
BattleManager.queueForceAction(user, 95, target);
}
</After Eval>

(I know it's not exactly the most robust script in the world...)

I am using the Yanfly Skill Core.

The skill here is skill 94, 95 is a slightly weaker version that has no MP cost and targets one random enemy, where as 94 allows you to select a specific target.

Both have a 35% chance of leaving the enemy with a 'Stunned' state.

And it... technically works, sort of, evidenced by the playing of the animation. But it doesn't display or register damage until the very last target is hit, which as you may imagine is a problem.

[Edit: after testing a bit I have confirmed damage does indeed register it just is not displayed. Additionally and more strangely, if a target reaches 0 hp when hit by anything other than whatever ends up being the last hit, they will remain "alive" and able to attack. Very strange.]

It does, however, leave targeted enemies with the state as you'd expect.

Would anyone happen to have any advice on how I might better go about it?
I appreciate this, and I'll bookmark the tab, but this requires two paid plugins I do not currently have.
Is there no way to achieve a similar effect without this?
I appreciate this, and I'll bookmark the tab, but this requires two paid plugins I do not currently have.
Is there no way to achieve a similar effect without this?
Ah, you don't have Target Core or Damage Core?

There probably is still a way you could pull it off, but it would be a bit more complicated.
Ah, you don't have Target Core or Damage Core?

There probably is still a way you could pull it off, but it would be a bit more complicated.
That's fine, so long as I can make it work without everything crashing or something hahaha
I find trying to do things out of order/in the middle of other skills using force action often leads to difficulties and errors.

If you can't afford the other Yanfly plugins, I would simply put this into an action sequence. All three of those plugins are free.

You might have to do some studying of the commands to work out the exact syntax you need, but they're very versatile and there are a number of threads with lots of stuff already listed in them you can use.
I find trying to do things out of order/in the middle of other skills using force action often leads to difficulties and errors.

If you can't afford the other Yanfly plugins, I would simply put this into an action sequence. All three of those plugins are free.

You might have to do some studying of the commands to work out the exact syntax you need, but they're very versatile and there are a number of threads with lots of stuff already listed in them you can use.
Ooooh okay. I'll give that a try, thanks!
(apologies for the double post but I can't seem to find a consistent answer)
Using the action sequence, I have managed to get this skill working more or less as intended, the only remaining issue is its going through a common event using rpg maker mv's built in force action command.

I'd like to, instead, be able to store/refer to the ID of the last battler to act(in this case whomever is using the skill) so that I can have this trigger regardless of how the party is arranged or who cast it, even if it's an enemy. Is that possible with a script call?

Edit: I've figured that out now, too. Only issue is now for whatever reason if it activates too many times I guess the game and/or plugins don't like it and it crashes.

¯\_(ツ)_/¯​

Only issue is now for whatever reason if it activates too many times I guess the game and/or plugins don't like it and it crashes.
It's difficult-to-impossible to offer any troubleshooting tips without seeing the action sequence code you wrote. You should post it (making sure to use the CODE tags, </> on the edit bar, to preserve your formatting).

As a kind of side-warning-note, if you're doing this with action sequences I don't see why any common events or force actions would be involved at all. That was the entire purpose I recommended action sequences several posts above, to avoid all of that stuff.
It's difficult-to-impossible to offer any troubleshooting tips without seeing the action sequence code you wrote. You should post it (making sure to use the CODE tags, </> on the edit bar, to preserve your formatting).

As a kind of side-warning-note, if you're doing this with action sequences I don't see why any common events or force actions would be involved at all. That was the entire purpose I recommended action sequences several posts above, to avoid all of that stuff.
Ah well. I could not find a way to generate a random number inside the action sequence. And even if I could I couldn't figure out a way to have the skill essentially re-start if the value of that number was over a certain threshold, so the best I could do was go with a common event.

this is currently attached to Skill 94, as stated before.
Code:
<target action>
motion spell: user
animation 10: target
wait for animation
action effect
common event: 65
end
</target action>

this is the action sequence. It's nothing, really, it just... Activates the spell. It's probably functionally pointless since it does next to nothing except activate the common event (which I know can be activated through rpg maker's built in tools, but for whatever reason this seemed more stable while I was testing?)

1677613705076.png


And *this* is the common event. It... functions more or less as intended except... y'know, the crashing, haha.


If there's some part of the Action Sequence packs that would allow me to re-input a damage formula based on a generated number's value I simply do not understand it well enough to find it.
And *this* is the common event.
Just as a quick note about your event, there's no purpose to saying "Else: Exit Event Processing." You can just take off the Else branch and the event will end anyway.

I could not find a way to generate a random number inside the action sequence.
Math.random() or Math.randomInt().

I couldn't figure out a way to have the skill essentially re-start
I don't understand why you'd want to 😛

I'm gonna throw a bit of JavaScript in there just to make sure there's a second valid target, but you could do it a few different ways with action sequence commands. (also, your action sequence had an incorrect "end" command at the bottom)

Code:
<target action>
motion spell: user
animation 10: target
wait for animation
action effect
if Math.random()<.3
    eval: other_targets=$gameTroop.aliveMembers().filter(enemy => enemy!=target); target=other_targets.length>0 ? other_targets[Math.randomInt(other_targets.length)] : null;
else
    eval: target=null;
end
if target
    animation 10: target
    wait for animation
    action effect
end
</target action>

If there's some part of the Action Sequence packs that would allow me to re-input a damage formula based on a generated number's value I simply do not understand it well enough to find it.
I'm not positive what this means, but every time you call "action effect" it recalculates the damage.

If you need the secondary strike to do less damage, I'd make a state with a little lightning resistance and add it to the target before the second action effect, then take it back off after.
Just as a quick note about your event, there's no purpose to saying "Else: Exit Event Processing." You can just take off the Else branch and the event will end anyway.
yeah, this I know. That's only in there to see if it'd circumvent the crashing somehow. It didn't, to no one's surprise haha.
Math.random() or Math.randomInt().
For some reason I didn't think the normal script call language worked in the action sequence parameters, so this is good to know. Thanks!
I don't understand why you'd want to
Well, it was just the only way I could think of to have the skill continue assuming conditions were met.
I'm gonna throw a bit of JavaScript in there just to make sure there's a second valid target, but you could do it a few different ways with action sequence commands.
This works for the most part, but it keeps hitting the initial target? I'm not sure why.
(also, your action sequence had an incorrect "end" command at the bottom)
uhh oops. Thanks for spotting that haha

I'm not positive what this means, but every time you call "action effect" it recalculates the damage.
What you've provided here essentially answers the question, so it's all good here.

Essentially what I meant was if there were some way of... well, doing exactly what your script here is doing. (minus the repeating target)
For some reason I didn't think the normal script call language worked in the action sequence parameters, so this is good to know. Thanks!
When you do a conditional (if), that's straight JavaScript. If you use the provided Eval: action sequence command, that's JavaScript.

This works for the most part, but it keeps hitting the initial target? I'm not sure why.
Hm. That's curious. It should explicitly not be able to do that.

If you use it against a troop with only one enemy in it, what happens? The expected result is you'd never get the second hit.

If you hit F8 and go to the Console tab while using the skill, are there any errors?
When you do a conditional (if), that's straight JavaScript. If you use the provided Eval: action sequence command, that's JavaScript.


Hm. That's curious. It should explicitly not be able to do that.

If you use it against a troop with only one enemy in it, what happens? The expected result is you'd never get the second hit.

If you hit F8 and go to the Console tab while using the skill, are there any errors?
No errors, no.

In a troop against a single foe, it still hits twice.

Also for some reason it hits the target twice, no matter what, even if they're technically dead after the first hit? They die after the skill has finished but. Still. Hmm.

I am using YanFly's ATB system, could that have any effect on that?
Change the line with the long eval to this:
Code:
eval: other_targets=$gameTroop.aliveMembers().filter(enemy => enemy!=target); target=other_targets.length>0 ? other_targets[Math.randomInt(other_targets.length)] : null; console.log("other_targets is ", other_targets, " target is ", target);

Do the skill with the console open and paste the results.

I'm not concerned about the dead thing, if we get this bit fixed it won't hit the same target twice, so it doesn't matter whether they die or not.
Change the line with the long eval to this:
Code:
eval: other_targets=$gameTroop.aliveMembers().filter(enemy => enemy!=target); target=other_targets.length>0 ? other_targets[Math.randomInt(other_targets.length)] : null; console.log("other_targets is ", other_targets, " target is ", target);

Do the skill with the console open and paste the results.

I'm not concerned about the dead thing, if we get this bit fixed it won't hit the same target twice, so it doesn't matter whether they die or not.
First let me just say thank you for helping me out with this, I really appreciate it.

Second, it's still doing the same thing, which I find strange. I feel like I understand more or less what this line of code is trying to do and it's bizarre that it's not... working. It is still behaving the same.

This is all that comes up. (select multiple targets referring to Zecia/St0rmTiger's plugin, which I tried turning off and testing and it had the same result)
1677683172106.png


Do I just have something out-of-date or some such? Is that possible?
Okay, so the commands in the if-else aren't getting executed at all.

That's fair in the first case, we're telling it to prepare things for a second strike only 30% of the time, so we'd expect not to necessarily see that.

But then the else should be executing to make the target null so the subsequent if fails.

Can you edit the else eval to this:
Code:
else
    eval: target=null; console.log("target made null");
end

and see if it pops up in the console?

You should fix the other stuff - your multiple targets plugin shouldn't be spamming the console and there's apparently something wrong with your code in your HUD if it's looking at undefined actors.
You should fix the other stuff - your multiple targets plugin shouldn't be spamming the console and there's apparently something wrong with your code in your HUD if it's looking at undefined actors.
yeah I will have to look at the multiple targets thing, I'm not sure why it'd be doing that.

As for the HUD, that was coming up because I've got it setup so some elements only appear dependent on who is in your party, so that was coming up due to me having 2/3 possible party members. Using the debug mode I just plopped the 3rd party member in and that 'error' stopped coming up.
and see if it pops up in the console?
1677684700370.png

Should it look like this?

edit:
Okay I grabbed this: https://forums.rpgmakerweb.com/index.php?threads/action-sequence-nested-if.79325/

And moved the
Code:
if target
    animation 10: target
    wait for animation
    action effect
end
above the "else."

The 30% chance of triggering the action works now as it should.

However, it is still not targetting anyone other than the initial target. hmmm...
Okay. It doesn't work as written because the "target" variable is created locally for each individual action sequence command.

So we have to go out to the BattleManager level.

This works in my test project, let me know how it goes for you.

Code:
<target action>
motion spell: user
animation 10: target
wait for animation
action effect
if Math.random()<.3
    eval: other_targets=$gameTroop.aliveMembers().filter(enemy => enemy!=target); if (other_targets.length>0) this._targets[0]=other_targets[Math.randomInt(other_targets.length)]; else target.lightningHit=true;
else
    eval: target.lightningHit=true;
end
if !target.lightningHit
    animation 10: target
    wait for animation
    action effect
end
eval: $gameTroop.aliveMembers().forEach(enemy => enemy.lightningHit=false);
</target action>
Okay. It doesn't work as written because the "target" variable is created locally for each individual action sequence command.

So we have to go out to the BattleManager level.

This works in my test project, let me know how it goes for you.

Code:
<target action>
motion spell: user
animation 10: target
wait for animation
action effect
if Math.random()<.3
    eval: other_targets=$gameTroop.aliveMembers().filter(enemy => enemy!=target); if (other_targets.length>0) this._targets[0]=other_targets[Math.randomInt(other_targets.length)]; else target.lightningHit=true;
else
    eval: target.lightningHit=true;
end
if !target.lightningHit
    animation 10: target
    wait for animation
    action effect
end
eval: $gameTroop.aliveMembers().forEach(enemy => enemy.lightningHit=false);
</target action>
Oh that worked like a DREAM

Thank you so much, you're a legend.

Original thread: https://forums.rpgmakerweb.com/threads/chain-lightning-skill.155337/