Target Core - Updating Target Array After Death During Random Skill

Discussion in 'Javascript/Plugin Support' started by AdamSakuru, Nov 8, 2017.

  1. AdamSakuru

    AdamSakuru StudioDaeera Veteran

    Messages:
    314
    Likes Received:
    168
    Location:
    Calgary, Alberta.
    First Language:
    English
    Primarily Uses:
    N/A
    In my game I have a skill that hits 3 random enemies. I noticed sometime after making it that if any enemy dies during the first or second hit of the skill, the now non existent enemy still has a chance of being targeted for the following hits. I'm surprised this happens as I think it defeats part of the purpose of a skill hitting multiple random enemies. The skill should capitalize on an enemy dying early in the skill at the trade-off of the player not knowing who it will hit. This is how I've seen random skills handled in RPGs at least.

    What I would like is to make use of the <Custom Target Eval> to have skills that hit multiple random targets update the target array mid skill if an enemy dies. So on a 3 random target skill: if the first hit of the skill kills enemy A, then enemy A won't get targeted for the remainder of the hits. This also means that enemy A could be targeted 3 times if enemy A is alive for the entire skill.

    Code:
    <Custom Target Eval>
    // Adds the selected target to the target list.
    targets.push(target);
    // Grab the group of alive foes as candidates.
    var members = foes.aliveMembers();
    // Remove the target from the group of candidates.
    members.splice(members.indexOf(target), 1);
    // This is the number of extra targets to select with Chain Lightning.
    var extraTargets = 3;
    // Loop the extra targets.
    while (extraTargets--) {
      // Grab a random foe from the alive foes.
      var member = members[Math.floor(Math.random() * members.length)];
      // Check to see if the member exists.
      if (member) {
        // Add the member to the group of targets.
        targets.push(member);
        // Remove the member as a viable candidate.
        members.splice(members.indexOf(member), 1);
      }
    }
    </Custom Target Eval>
    The above code is from Yanfly's chain lightning trick. After an enemy gets hit by a skill with this code, other random enemies can be hit by the skill afterwards by the skill repeating itself on a number of random targets. In the code's case it's 3 other enemies. But the code makes it so that the same enemy can't be targeted twice by the randomness. It's not quite the effect I want, but it's sort of close.

    Here's what I want it to do:
    1. Create an array with 3 targets, chosen at random.
    2. Hit the first target in the array then remove it if it has 0 HP.
    3. Hit the next, then remove it if it has 0 HP.
    4. Hit the last, remove it.
     
    Last edited: Nov 12, 2017
    #1
  2. AdamSakuru

    AdamSakuru StudioDaeera Veteran

    Messages:
    314
    Likes Received:
    168
    Location:
    Calgary, Alberta.
    First Language:
    English
    Primarily Uses:
    N/A
    Le'Bump
     
    #2
  3. AdamSakuru

    AdamSakuru StudioDaeera Veteran

    Messages:
    314
    Likes Received:
    168
    Location:
    Calgary, Alberta.
    First Language:
    English
    Primarily Uses:
    N/A
    Bump
     
    #3
  4. Maliki79

    Maliki79 Veteran Veteran

    Messages:
    630
    Likes Received:
    238
    Location:
    New Jersey
    First Language:
    English
    Primarily Uses:
    N/A
    I think if you remove the last member.splice line, it should work fine.
     
    #4
    AdamSakuru likes this.
  5. AdamSakuru

    AdamSakuru StudioDaeera Veteran

    Messages:
    314
    Likes Received:
    168
    Location:
    Calgary, Alberta.
    First Language:
    English
    Primarily Uses:
    N/A
    I think that solved it (or am pretty sure at least, when I set the skill up but removed the member splicing line it's appeared to work consistently).
    Thanks for the help Maliki79, I'm giving you a credit in my game for technical support. This problem legitimately rustled my jimmies.

    Edit:
    dayum, okay well now it's consistently trying to target dead enemies still. But, compared to before I tried your edit suggestion, it doesn't play the skill animation/damage the target (it still seems to count as one of the attacks though). The camera commands in the skill's action sequence still focus on the target whether or not they're alive. SO it's still somewhat of an improvement.
     
    Last edited: Jan 11, 2018
    #5
  6. Maliki79

    Maliki79 Veteran Veteran

    Messages:
    630
    Likes Received:
    238
    Location:
    New Jersey
    First Language:
    English
    Primarily Uses:
    N/A
    Ah... I think the reason may be the plugin only evals the targets once. I don't use the plugin so I can't say for sure. I'd have to dl it to see.
    Maybe make an extension to do what you need.
     
    #6
  7. AdamSakuru

    AdamSakuru StudioDaeera Veteran

    Messages:
    314
    Likes Received:
    168
    Location:
    Calgary, Alberta.
    First Language:
    English
    Primarily Uses:
    N/A
    Would you know anyone who'd know how to do it? (or would you?)

    Around the time I made this post I asked around in a few RPG Maker Discord servers and no-one seemed to know how to solve it.
     
    #7

Share This Page