[XP]Multiple Hit Script Causing Crash

Hello! I've encountered an issue using a script I found lately.

I was looking for a way to enable certain weapons and skills to strike enemies multiple times, and I found this script, which works perfectly for the most part. (For full disclosure, I also made the adjustment to the script that was mentioned a bit later in that thread.)

But I've run into an issue - if an enemy is hit by a multi-hit skill or weapon, and is slain before all of the hits have occurred, then the game will crash because it seems to look for a target that isn't there (assuming it's the last enemy in the battle.)

I've been searching for a solution to this, but couldn't seem to find one. Here's the setup I have for the script, in the form of a pastebin. I've also attached an image of the error message this crash gives me.

If anyone could help, it would be appreciated. Thank you in advance! <3

qIBBOpJ.png

I've moved this thread to RGSS Script Support. Thank you.

Rather curious. The error is in the default scripts 'make_basic_action_result' , the message indicating that there's no valid target to apply an attack effect. But this method also CREATES the target too. And Blizzard's script doesn't rewrite this method. Nor does it alter any 'random_target_actor' or 'random_target_enemy' methods that the 'make_basic_action_result' requires.

Do you have any other scripts that may affect battlers or battlesystems? And if so, the script order?
Hm, I tried playing around with other scripts to see if that was the issue, to no avail. Though it's completely possible that I was just not thorough enough. I do have a few others, though.

I have this multiple-hit script above every other battle system script. Below it is a script to disable enemy critical hits by MobiusXVI, then PK8's damage numbers script, then another one by MobiusXVI that allows animations to be played upon landing a critical hit. I skipped over a few that don't touch the battle system or enemies at all.

I've included pastebins of all of my settings for those scripts, if that helps. On my end, I'll play around with the order of these scripts to see if I can find a simple load order solution.
tl;dr I think there's a bug in the multiple hit script. Try replacing line 219:
Code:
@phase4_step = 2 if @repeat[0] > 1 && @repeat[2] > 0
with this:
Code:
@phase4_step = 2 if @repeat[0] > 1 && @repeat[2] > 0 && not judge

Full explanation of what I *think* is going on. During the default scripts "update_phase4_step2" (aka step 2) method it calls a sub method based on the attack type (either "make_basic_action_result", "make_skill_action_result", or "make_item_action_result"). All of these methods eventually call "smooth_target_enemy" if the actor is attacking an enemy and their target isn't forced. The problem is that this method assumes (incorrectly is this case but correctly in the default system) that an enemy exists. When none exist because the party just killed that last one, it return null which causes the error.

Ok, so why does smooth_target_enemy assume this and cause a problem? Well in the default system, the battle always (well almost always) progresses in order from step 1 to 2 to 3 etc. The new system does something different. To enable multiple hits the script loops like this: 1-repeat (2-5) as often as hits-6. So it loops around between steps 2 through 5 and skips step 1. However, step 1 is necessary before step 2 as it checks to see if the party has won (i.e. all enemies are dead). If the enemies aren't all dead, then it's safe to continue onto step 2, which is where the problem is.

So what I've done is added that same check from step 1 to the end of step 5 in the new system. If all the enemies are dead, it should prevent the loop back to 2 when it's not appropriate.
Hello again MobiusXVI, I appreciate you looking into this, but sadly that didn't seem to work, either. Now, it just gives me a syntax error on line 219 of that script whenever I try to boot the game. Any idea what might be causing this? I've triple-checked that I pasted it exactly as it is on the page.

Thank you in advance!
Looks like I just missed a set of parenthesis. Try this:
Code:
@phase4_step = 2 if @repeat[0] > 1 && @repeat[2] > 0 && (not judge)
There we go! It works perfectly, now!

Thank you very much- you've saved me again 🙂

And thank you, too, DerVVulfman!
@MollyAvast Can you please try these two variants, too?

Code:
@phase4_step = 2 if @repeat[0] > 1 && @repeat[2] > 0 && !judge
Code:
@phase4_step = 2 if @repeat[0] > 1 && @repeat[2] > 0 && (!judge)

The script should actually use "!" instead of "not". I'll make sure to properly fix it on my end.
Both of those scripts work for me as well, @bblizzard!
@bblizzard What's the reason for using "!" over "not"?
@MobiusXVI Yup. See here: https://www.techotopia.com/index.php/Ruby_Operator_Precedence
"&&" has precedence over "||" which is as it should be. But "and" and "or" have the same precedence. A line like
Code:
a || b && c
will be evaluated properly (first "a", and only if it's false, then "b && c") while a line like
Code:
a or b and c
will be evaluated wrong (first "a or b" and if it's false, then "c"). Or it was vice versa like "a and b or c" or something like that. I don't remember the exact use case anymore. In any case, "and" and "or" are messed up.

This is also why "!" needs to be used instead of "not". "not" has a lower precedence than the "&&" and "||" operators.

Original thread: https://forums.rpgmakerweb.com/threads/xp-multiple-hit-script-causing-crash.106600/