Renkai141

Pain make sme a believer
Member
Joined
Oct 31, 2018
Messages
29
Reaction score
3
First Language
Spanish & EN
Primarily Uses
RMMZ
My goal with Java script, in which I'm not very proficient, is to create a skill that hits a foe(100%) and those around it to take reduced damage(50%). I am using RPG maker MZ and I also have a number of plugins(battle core). However, I have been unsuccessful in creating that skill exactly how I want it.

Reference : Here

I've presumed to use a skill called "Chain Lighting" which fits the desired effect.

References for the code on using splice...
Reference

JavaScript:
<JS Targets>
  const foes = this.subject().opponentsUnit();
  const target = foes.members()[this._targetIndex];
  targets.push(target);
  let members = foes.aliveMembers();
  members.splice(members.indexOf(target), 1);
  let extraTargets = 2;
  while (extraTargets--) {
  const member = members[Math.randomInt(members.length)];
    if (member) {
      targets.push(member);
      members.splice(members.indexOf(member), 1);
    }
  }
</JS Targets>

However, the result... that I get. When I target a foe, and I execute the skill it hits the target twice and then it does the desired effect. I don't want it to hit the same target twice, only once.
What I'm I doing wrong?
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,042
Reaction score
8,974
First Language
English
Primarily Uses
RMMV
Not wrong, but you could make the first line a bit less convoluted by just saying:
Code:
const foes = target.friendsUnit();
It's not in the documentation, but if this is like the Yanfly plugin counterpart, I'm pretty sure there's already a target variable provided. If that gives you an error, go back to what you had.

Your problem is where you define "const target" and then push that into the targets array. See this point from the plugin instructions:
- The 'targets' variable will include the original set of targets determined
by the skill/item's original scale.

Therefore, the actual target you selected is already in the targets array, and you're defining and pushing it in again.
 
Last edited:

Renkai141

Pain make sme a believer
Member
Joined
Oct 31, 2018
Messages
29
Reaction score
3
First Language
Spanish & EN
Primarily Uses
RMMZ
Not wrong, but you could make the first line a bit less convoluted by just saying:
Code:
const foes = target.friendsUnit();
It's not in the documentation, but if this is like the Yanfly plugin counterpart, I'm pretty sure there's already a target variable provided. If that gives you an error, go back to what you had.

Your problem is where you define "const target" and then push that into the targets array. See this point from the plugin instructions:


Therefore, the actual target you selected is already in the targets array, and you're defining and pushing it in again.
Thank you for your time.
As for the first code reference, it definitely didn't do anything(made the code not work). For reference, I'm using Rpg maker MZ Battle Core. (So I had to keep the code the same)

As for second part, you mentioned that the problem is where it's defined const target = foes.members()[this._targetIndex]; what would you have me do instead?
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,042
Reaction score
8,974
First Language
English
Primarily Uses
RMMV
As for second part, you mentioned that the problem is where it's defined const target = foes.members()[this._targetIndex]; what would you have me do instead?
Nothing - don't push it into the array because it already starts in there. Delete the third line of code.
 

Renkai141

Pain make sme a believer
Member
Joined
Oct 31, 2018
Messages
29
Reaction score
3
First Language
Spanish & EN
Primarily Uses
RMMZ
Nothing - don't push it into the array because it already starts in there. Delete the third line of code.
I- I can't believe it was that simple. I appreciate your help tenfold! Consider this resolve.

JavaScript:
<JS Targets>
  const foes = this.subject().opponentsUnit();
  const target = foes.members()[this._targetIndex];
  let members = foes.aliveMembers();
  members.splice(members.indexOf(target), 1);
  let extraTargets = 2;
  while (extraTargets--) {
    const member = members[Math.randomInt(members.length)];
    if (member) {
      targets.push(member);
      members.splice(members.indexOf(member), 1);
    }
  }
</JS Targets>
 

Latest Threads

Latest Posts

Latest Profile Posts

Made a free sample pack + leftovers. Free Sample Pack 1
I'm curious, how many hours in RPG Maker do you have? I'm clocked in at 2100 hours on MV and the vast majority of it is for one game. I wish I could track how much I used XP back in the day, I was on it a lot.
Why is it so early? Can I have twenty more minutes of sleep, please?
DK
Do you like this design?

GIF.gif
Im watching Depp vs Heard and keep thinking: "Wouldnt it be fun if her middle name was Lisa? Then she'd be Amber L. Heard. Sounds like Amber Alert."

Then I found out her middle name is Laura.

Forum statistics

Threads
134,809
Messages
1,250,841
Members
177,606
Latest member
Buffinto
Top