Trouble with Yanfly's Target Core and Selection Control

Discussion in 'Javascript/Plugin Support' started by Okk, Sep 7, 2019.

  1. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    I'm working with Yanfly's Target Core and Selection Control, but I'm having a little trouble hammering out the details of its functions. There are two skills in particular that I'm working on.

    My first problem is a magic skill that damages all enemies. I'd also like it to optionally damage all allies instead; otherwise I wouldn't be using the Selection Control plugin. Unfortunately, notetags such as <Actor or Enemy Select> seem to completely override the Scope of the skill, changing it into a single-target attack.

    The second problem is a revive spell. Ultimately, I'd like any KOed or undead targets to be valid, but I can't even get a spell to target KOed units. Again, the <Actor or Enemy Select> overrides the Scope, so with that alone, the spell will fail to target any KOed character. I've tried using <Select Conditions> using state 1 and zero hp, but the skill is disabled even when there are KOed actors on the field. I've also tried custom lunatic code, but it seems to get ignored.
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    28,448
    Likes Received:
    6,493
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    that is because KO'ed actors are a different target than non-KO'ed actors, see the regular targeting scope.
    Selecting actors as target will automatically exclude the targets "actor (dead)".

    Sorry, I can't tell you how to solve this but that is where you have to start looking for an answer why the dead actors can't be targeted.
     
    #2
  3. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,183
    Likes Received:
    731
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    Plugin links for convenience:
    Not sure about the All Allies / All Enemies thing. After a quick look through Selection Control's options it seems like "Actor or Enemy" selection is single-target only. You may need an add-on plugin to implement a "Party or Troop" scope. :kaoslp:

    For the dead or alive thing: there's a plugin called DeadOrAliveItem (for me it's in my RMMV install folder, under dlc/KadokawaPlugins) that lets you bypass the dead/alive scope difference that Andar mentions. Last I checked it had some conflicts with Yanfly's Selection Control; I have a compatibility patch over here in case you're interested: view/download CaeX_YEPDeadOrAlive (Google Drive).
     
    #3
  4. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    Sorry, not sure why I keep forgetting to link the relevant plugins. Like I can't grasp that somebody might not know about Yanfly engine.

    Thanks, caethyril. I can actually target dead allies with revive spells now, which is probably the most important part. It seems that the Select Conditions are causing the trouble. Things like 'Param HP% === 0' or 'State: 1' are always evaluating as false. Maybe the Selection Control plugin is only bothering to check alive members in the first place.
     
    #4
  5. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,183
    Likes Received:
    731
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    No worries! I just link the plugins because otherwise it's an extra search + click away. Much more convenient to simply click a link~ :kaothx:

    And you're correct, by default there is no "dead and alive" scope, and Selection Control only decides which targets of the given scope can be selected. So, if the skill can't target dead allies in the first place, the select condition "State: 1" won't have any effect, since possible targets are either all alive or all dead. :kaophew:

    I've been looking at Target Core / Selection Control trying to figure out how to implement a "Party or Troop" scope, but can't seem to see it. :kaoslp: Hopefully someone else can help there, sounds like a neat feature! :kaojoy:
     
    #5
  6. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    Well, I've managed to make a revive spell that can hit a KOed ally without being shunted to the next living ally, which is a good start. It's not pretty though. I can't use my desired select conditions (Param HP% === 0) because the always evaluate to false, defeated enemies are not valid targets (I can live with that one), and when the spell is forced to miss because the target is alive, they still display their damaged animation and SFX and the 'miss' popup appears twice. (The spell also deals damage instead of healing it, but I'm pretty sure that's an error in my damage formula.)
    As is, the spell 'works' in the strictest sense of the word, but I do hope there's a more elegant solution.
     
    #6
  7. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    After a little experimenting, I'm starting to wonder if this thread wouldn't be better off in the Plugin Requests board. I could be mistaken, but if my select conditions are ignoring KOed battlers, regardless of what the conditions may be, then I think the plugins may just not support that natively and may need a patch. Most of the time, ignoring dead battlers is fine, but fringe cases always pop up like this.
     
    #7
  8. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,183
    Likes Received:
    731
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    The thing is, as mentioned, "Dead Ally" is a separate scope. (And "Dead Enemy", by default, doesn't exist.) It's easy to make a skill that targets only dead allies or only living allies, just select the scope in the database. The DeadOrAliveItem plugin should allow a skill to "combine" these scopes. As such, the select condition "State: 1" seems redundant to me, why not just select Dead Ally scope? :kaoswt2:

    If this is about the dead enemy targetting, then yes, I think that'll need another plugin to add the required scope.
     
    #8
  9. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    You're right, but that's kind of what I'm on about with my second query: A revive spell that can target either a KOed ally or an enemy with the Undead passive state. With the DeadOrAliveItem plugin and thanks to your compatibility patch, I was able to get a "good enough" situation in place. But ideally, I want a spell that can target any KOed unit or any unit with Undead state, friend or foe, and if no such unit exists, the spell cannot be used. (Why I want so much to let the player hurt themself, who can say?)

    Part of the problem is that, until recently, I wasn't clear on the difference between "selecting" and "targeting." When that finally dawned on me during testing, I started digging around in Yanfly's Selection Control in hopes of finding answers, and when I noticed the recurring use of ".aliveMembers" as opposed to ".members" I thought maybe I could make a little patch myself. So I gave that a shot, and not only does it give me the desired result, it only does it when I want it to, via my new notetag.

    Unfortunately, I don't actually know Javascript, or the RPG Maker API, or what kind of methods Yanfly employs, and honestly I was never a very good programmer in the first place. As such, I managed to introduce a game-crashing bug in the process. When my skill is chosen, there is no default selection. The player can select a valid unit from there (by pressing up or down I think), but if they try to cast the spell on this null target first, the game crashes. The skill should automatically begin the selection process pointing at a valid target (preferably favoring a KOed ally, if one exists.) This issue only seems to occur when I'm using the custom select notetags below.

    I'll go ahead and include my patch here, along with other relevant information, in case anybody wants to take a peek and try to help me out. I really do enjoy programming, I just wish I was better at it.

    EDIT: I've disabled my patch, and this bug still exists when using the custom select conditions listed below. KOed enemies are not accounted for, but if there are Undead enemies and no KOed allies, the selection starts pointing at a null target.

    Code:
    <CAN HIT DEAD>
    <scope:oneDeadOrAlive>
    <Actor or Enemy Select>
    
    <Custom Select Condition>
      if (target.hp <= 0) {condition = true;}
      else if (target.isStateAffected(244)) {condition = true;}
      else {condition = false;}
    </Custom Select Condition>
     

    Attached Files:

    Last edited: Sep 13, 2019
    #9
  10. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,183
    Likes Received:
    731
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    Oh I see! Yes: scope, targets, and selection are all different. Will have a look at your patch when I get a chance, see if I can spot anything~
     
    #10
  11. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    Thank you very much, I would appreciate that.

    I've actually managed to reproduce this null target bug without my patch though, in a fresh project. I used only the three aforementioned Yanfly plugins, the Dead Or Alive Item plugin and the compatibility patch, then added these notetags to the Fire skill:
    Code:
    <Custom Select Condition>
      if (target.mhp == 200) {condition = true;}
      else {condition = false;}
    </Custom Select Condition>
    <scope:oneDeadOrAlive>
    <Actor or Enemy Select>
    I made a troop with a bat, a slime and a second bat to test on, and when I choose the fire skill, the selection defaults to nothing. Selecting the null target results in TypeError, Cannot read property 'index' of undefined.
     
    #11
    caethyril likes this.
  12. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,183
    Likes Received:
    731
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    OK I am still confused but I managed to get an error ("isActor is undefined") with the setup you described, as soon as I selected the Fire skill for use. Looks like it was because two of the listed targets are actually strings: "ALL ALLIES" and "ALL ENEMIES". I added this little override and the error seemed to disappear:
    Code:
    Window_BattleEnemy.prototype.autoSelectFirstDeadActor = function() {
        var length = this._enemies.length;
        for (var i = 0; i < length; ++i) {
          var member = this._enemies[i];
          if (typeof member === 'string') continue;  // <-- added
          if (member && member.isActor() && member.isDead()) return i;
        }
        return 0;
    };
    Not sure why we'd see different errors, though, so there's probably still some problem(s) lurking... :kaoslp:
     
    #12
  13. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    This doesn't seem to make a difference for me, in either the new project or my game's revive skill. Was I supposed to just drop it into a plugin at the bottom of my list?
    I'm also not sure about the different errors, so I checked the versions of all my yanfly scripts, and they seem to be up to date.
     
    #13
  14. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,183
    Likes Received:
    731
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    Yep, that's what I did, but you'll probably need a different fix given you get a different error. It's difficult for me to guess at the solution if I can't replicate the problem, though, sorry... I'm testing with a v1.6.1 project, maybe that's it? Otherwise hopefully someone else can help. :kaoswt2:
     
    #14
  15. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    I just checked my RPG Maker version, and it looks like I'm using v1.6.2. I made my clean test project in that version. I suppose it's possible that's enough to make the difference.
     
    #15
  16. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,183
    Likes Received:
    731
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    #16
  17. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    In that case, I'm a bit stumped. Should I send this fresh project somewhere or something?

    EDIT
    : I asked a friend of mine if he could help me out. After poring over code for several hours, he finally told me to comment out line 84 of CaeX_YEPDeadOrAlive.js (this.select(iSel);). This appears to have fixed my problem and given me the results I wanted with the revive spell. I hope this edit won't cause issues down the road though...
     
    Last edited: Sep 15, 2019
    #17
  18. Okk

    Okk Veteran Veteran

    Messages:
    46
    Likes Received:
    9
    First Language:
    English
    It took a while, but I modified my previous script to also allow skills that can only target either entire group. I think I got it functioning right, but working with something as modular as MV is like a stressful scavenger hunt.
    @caethyril Thank you for helping me out with this sort of stuff. Please let me know if you think commenting out line 84 could cause problems down the road.
     

    Attached Files:

    #18
    caethyril likes this.
  19. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,183
    Likes Received:
    731
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    Interesting... I think that line only affects who is originally selected after picking a skill to use, shouldn't be a big issue. Then again, I wouldn't have expected it to cause this error in the first place. :kaoslp:

    Glad you eventually found a fix, thanks for letting me know! :kaothx:
     
    #19
    Okk likes this.

Share This Page