[SOLVED] Struggling with two targeting issues

I'm currently making two guard dog enemies that have different properties: one is an attacker and has its handler ally use a skill for the attack dog to target one actor, and the other is a defender and has its handler ally use a skill for the protection dog to guard that handler and counterattack whoever attacks its handler. Though there's a bit of issues I'm facing when it comes to the targeting:

  • For the attack dog, I know there is the target rate which boosts the chance of being targeted, though it makes every enemy want to target them instead of just the one enemy. I have a target state applied to the target and an attack state applied to the attack dog, but is there a way to connect them so that the attacker state only goes after the target state?
  • For the protection dog, I followed this Overwatch skill tutorial where allies can counterattack, and it works well enough for one enemy. However, when two guard dogs with the protect property shows up, only one of them actually defends (and it's just the same one). Is there a way for them to both defend and counterattack while not overlapping with only one of them doing it?
while there are several tricks for using target rate and other options, in your specific case it would be easier if you go with several plugins for advanced targeting and advanced skills and counter control.
I'm away from my computer and can't test, but for the attacking dog/handler, could you simply have the handler give the targeted actor a hidden item as part of the skill? Then you could have a couple of nested conditional branches for the dog's attack skill saying, "If: actor 1 has the hidden item, attack it. Then remove the hidden item. Else: If: actor 2 has the hidden item, attack it. Then remove the hidden item..." and so on. Then if no one has the hidden item, attack a random actor.

For the defense skill, you could do something similar. Give a handler ally a hidden item. If an allied handler has the hidden item, defend it. Then remove the hidden item.

Would something like that work for you?
while there are several tricks for using target rate and other options, in your specific case it would be easier if you go with several plugins for advanced targeting and advanced skills and counter control.
I've been using Yanfly's Target Core and Selection Control plugins, so I'm not too far off from what I need to do. I feel like I'm close to getting it, though

I'm away from my computer and can't test, but for the attacking dog/handler, could you simply have the handler give the targeted actor a hidden item as part of the skill? Then you could have a couple of nested conditional branches for the dog's attack skill saying, "If: actor 1 has the hidden item, attack it. Then remove the hidden item. Else: If: actor 2 has the hidden item, attack it. Then remove the hidden item..." and so on. Then if no one has the hidden item, attack a random actor.

For the defense skill, you could do something similar. Give a handler ally a hidden item. If an allied handler has the hidden item, defend it. Then remove the hidden item.

Would something like that work for you?
I'm a bit confused by what you mean here since only armor and weapons can be held. Unless you mean like something similar to how Pokemon does held items?
I'm a bit confused by what you mean here since only armor and weapons can be held. Unless you mean like something similar to how Pokemon does held items?
Sorry, I haven't done this personally. I was trying to give a solution that no one had thought of yet. But now that I'm thinking about it, it won't work anyway because by default inventory is for the party, not by individual member. My thought was that, as part of the attack, you could add "Hidden Item A/B" to the targeted actor's inventory. Then check the actors for the item and attack that actor.

Although... I guess I don't know why you couldn't do that with states.


Edit:
Could you have the Handler enemy add a state to an actor and turn a switch on (ex: HandlerAttackState)? Then you could have a Battle Event run when "HandlerAttackState" switch is on.

In Troop, something like:
If:
$gameParty.members()[0].isStateAffected(x)
Then:
var subject = $gameTroop.members()[x];
subject.forceAction(skillID, target unit);
BattleManager.forceAction(subject);
this.setWaitMode('action');

There are some problems with this as is (like how to get the target unit index of the actor with the state), but I feel like it's not the worst starting point in the world?

But if you have something that works for you or is close, then great 🙂
It seems that adding two more states (target 1 connector and target 2 connector) actually works pretty well for setting up the targeting between the attack dog and its target, as well as targeting between the guard dog and the handler it's supposed to protect from attacks. It ended up fixing all the issues for the guard dog and its counterattack, but the attack dog's targeting is still giving me a bit of trouble.

When I was testing possible solutions for it, I noticed that the selection control does not allow more than one state to be selected as targets. Here's what the selection code looks like so far:


<Select Conditions>

if target.isStateAffected(67)
State: 67
Not State: 68
else if target.isStateAffected(68)
State: 68
Not State: 67
end

</Select Conditions>

It seems to work when there is one State: x condition, but when there are more, the move doesn't work, even when there are if conditions. Is there a way to get it to work with more states?
Is there a way to get it to work with more states?
what youre doing isnt the correct syntax for the tag. its not going to parse the action sequence if-else-end blocks you tried to set up. so its trying to select battlers that dont have state 67, but also have state 67, and also have state 68 but also dont have 68.

what are you trying to set the selection criteria to? "if the target has state 67, consider them if have state 67 and not 68, else, if the target has 68, consider them if they have state 68 and not 67" just sounds like an extremely roundabout way of saying "if they have either 67 and 68" after you give both states a resist trait for the other
what youre doing isnt the correct syntax for the tag. its not going to parse the action sequence if-else-end blocks you tried to set up. so its trying to select battlers that dont have state 67, but also have state 67, and also have state 68 but also dont have 68.

what are you trying to set the selection criteria to? "if the t arget has state 67, consider them if have state 67 and not 68, else, if the target has 68, consider them if they have state 68 and not 67" just sounds like an extremely roundabout way of saying "if they have either 67 and 68" after you give both states a resist trait for the other
Thank you for the correction on the syntax! I switched it up now, so it works a bit better.

<Select Conditions>

if (user.isStateAffected(55) {
if user.isStateAffected(67)) {
Not State: 68
}
else if (user.isStateAffected(68)) {
Not State: 67
}
}

</Select Conditions>

I'm trying to link it so that the attacker with the target 1 connector state (67) can target the specific opponent who has the same state, and the attacker with the target 2 connector state (68) can target the specific opponent with that same state as well. This is so that group battles can work without everyone targeting the same opponent.

However, the way my code is now is a bit strange: the attacker with the target 1 state will target the opponent with the target 2 state instead, and the attacker with the target 2 state will go after the opponent with the target 1 state. If I try and set them to state instead of not state and change the IDs to the appropriate ones, the move will be skipped entirely.
again, its not the proper syntax for that tag. if you look at the documentation for the plugin, it shows precisely what youre allowed to use in that notetag. it does not accept JS or any kind of conditional logic, so any attempt to add it will at best be ignored.

1741141461492.png


If youre trying to make selection conditional and you dont want to make a second version of the skill so that one can only be used when the user has one set of states and the other can be used when the user has the other, you need to use the <Custom Select Condition> notetag not the <Select Conditions> one.


the criteria you tried to outline would look like:

Code:
<Custom Select Condition>
condition = user.isStateAffected(55) &&
  (user.isStateAffected(67) && !target.isStateAffected(68) ||
  user.isStateAffected(68) && !target.isStateAffected(67))
</Custom Select Condition>
again, its not the proper syntax for that tag. if you look at the documentation for the plugin, it shows precisely what youre allowed to use in that notetag. it does not accept JS or any kind of conditional logic, so any attempt to add it will at best be ignored.

View attachment 333359

If youre trying to make selection conditional and you dont want to make a second version of the skill so that one can only be used when the user has one set of states and the other can be used when the user has the other, you need to use the <Custom Select Condition> notetag not the <Select Conditions> one.


the criteria you tried to outline would look like:

Code:
<Custom Select Condition>
condition = user.isStateAffected(55) &&
  (user.isStateAffected(67) && !target.isStateAffected(68) ||
  user.isStateAffected(68) && !target.isStateAffected(67))
</Custom Select Condition>
That makes a lot of sense as to why it didn't work before. I ended up changing the numbers so that the users and targets both had the same ids, and now everything works perfectly! I'll leave the new code here for those who may have a similar issue with targeting states:

Code:
<Custom Select Condition>
condition = user.isStateAffected(55) &&
  (user.isStateAffected(67) && target.isStateAffected(67) ||
  user.isStateAffected(68) && target.isStateAffected(68))
</Custom Select Condition>

Though your solution does bring up another point about duplicated skills: for enemies who would not be affected by the attacker state and the target 1 or 2 states and just choose a random opponent, would there need to be another condition? I have the scope set to 1 random enemy, though while the solution works for the enemies with the attack state and the other targets, the ones without the state still don't move.
though while the solution works for the enemies with the attack state and the other targets, the ones without the state still don't move.
it sounded to me like you wanted this skill to only be usable when the battler has this state, so i made it a requirement that they have it in order for it to be able to select anything. If this is a normal skill that many battlers get and you wanted a specific enemy to be more selective about when it uses it, then i would have suggested Yanfly's Battle AI plugin over the selection plugin

for enemies who would not be affected by the attacker state and the target 1 or 2 states and just choose a random opponent, would there need to be another condition
either you would have a separate duplicate skill with no requirement (or maybe require NOT having the state if you want to be sure theyre mutually exclusive) or youd change the condition of the current one so that itd allow free use if the user doesnt have the state, but then restrict targets if they do.

Code:
<Custom Select Condition>
condition = !user.isStateAffected(55) ||
  (user.isStateAffected(67) && target.isStateAffected(67) ||
  user.isStateAffected(68) && target.isStateAffected(68))
</Custom Select Condition>
it sounded to me like you wanted this skill to only be usable when the battler has this state, so i made it a requirement that they have it in order for it to be able to select anything. If this is a normal skill that many battlers get and you wanted a specific enemy to be more selective about when it uses it, then i would have suggested Yanfly's Battle AI plugin over the selection plugin


either you would have a separate duplicate skill with no requirement (or maybe require NOT having the state if you want to be sure theyre mutually exclusive) or youd change the condition of the current one so that itd allow free use if the user doesnt have the state, but then restrict targets if they do.

Code:
<Custom Select Condition>
condition = !user.isStateAffected(55) ||
  (user.isStateAffected(67) && target.isStateAffected(67) ||
  user.isStateAffected(68) && target.isStateAffected(68))
</Custom Select Condition>
Ah, sorry about the confusion! I had actually duplicated the skill before during one of my previous ideas for a solution and since you brought up the point about it, I was thinking of making it back to just one skill again. Either way, everything is working properly now and totally feel like an idiot for not thinking of the custom conditions sooner (I've been at this for a month).

Thank you all so much again for your help! This thread can now be closed.
This thread is closed due to being marked solved. Report the next one so we can find it easily. If you needs this thread reopened, report it to let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/solved-struggling-with-two-targeting-issues.175490/