Hi All,

I'm looking for a way to change the action target to a random enemy during a battle event. I've found the node Change Action Targets but it has no ability it seems to pick just one target out of a collection. The use case for this would be an ability that damages several random enemies over time and not all at the same time. After sometime I've come up with a solution using Global Objects but it feels a bit too hacky. I'm wondering if anyone has a more straight forward way of doing this or just posting it for anyone that may have the same use case.

Before using this function you would assign the user of the ability to the Global Variable "user" and after running the function your target would reside in the Global Variable "target".

public void GetRandomTarget(bool enemy)
{
List<Combatant> potentialTargs;
Combatant user = ORK.Game.GetGlobalObjects("user")[0].GetComponent<CombatantComponent>().combatant;

if (enemy)
{
potentialTargs = ORK.Game.Combatants.Get(user, true, Range.Infinity, Consider.Yes, Consider.No, Consider.Yes);
} else
{
potentialTargs = ORK.Game.Combatants.Get(user, true, Range.Infinity, Consider.No, Consider.No, Consider.Yes);
}

if (potentialTargs.Count != 0)
{
List<GameObject> selectedTarget = new List<GameObject>();
selectedTarget.Add(potentialTargs[Random.Range(0, potentialTargs.Count)].GameObject);
ORK.Game.ChangeGlobalObjects("target", selectedTarget, ListChangeType.Set);
}
}
  • Well I got a hacky idea, but at least it's done within Ork.

    You assign a bool game variable to your combatants with a default value of 0. When they get hit by your event, their variable is set to 1, and they can't be targeted anymore (do that with requirements). The next turn or after time has passed, their bool is reset to 0 and they can be targeted again by your event.
  • Thanks for the reply. The idea was that an enemy could be targeted multiple times in a single attack and even several times in a row. An example would be any of the limit breaks in FF7 that hit multiple times. The damage is applied to random enemies X times.
  • Well assuming the change action target doesn't work, here's a hack you could try.

    Same solution above, except you change the bool on the combatant to 1 when he gets hits. When another combatant gets hit, you reset it to 0. I think that could be done in your ability battle event, by checking all enemy combatant's variables present in the battle each time this attack is made.

    For hitting several times in a row, a simple work around would do. In your limit break ability, you set up a variable fork with random chance, for instance if x <10, hit selected target 1 time, if x between 10 and 20, hit selected target 2 times... etc. So when a target is selected, it can hit it again randomly, or not, and you have control on the chance. That would be pretty close to your initial idea.
  • As you already found out, you can either use the Change Action Targets node or the Use Other Targets option in the Calculate node to use any kind of combatant as the target for calculations. I.e. you can also use combatants from found objects or selected data, which can be selected in your event before hitting them (e.g. Search Combatants or Select Combatant nodes).

    Hitting multiple times just requires using the Calculate node multiple times (or when using damage dealers/zones, allow the damage dealer to do multiple damages). @UserName explained a good way to do that in a cycle using variables :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.