I was wondering what is the correct way to kill a combatant starting from its game object. Something along this line:

public void Kill(GameObject combatantGameObject)
{
// Kill combatant
}

and, in case I want no loot spawned, if using something like this

Destroy(combatantGameObject);

would create problems to the ORK Framework (ex Quests, Pooling...).
  • edited February 2022
    Hi @ChimpLogik on my videos I'm subscribing to the Health Stat ValueChanged Event then calling the Death() method


    private void BattleManager_EnemyHealthValueChanged(Combatant combatant, int id, int change)
    {
    if (combatant.Status[CombatantStatusValue.HEALTH].GetValue()
    <= combatant.Status[CombatantStatusValue.HEALTH].GetMinValue())
    {
    combatant.Status.Death();
    }
    }

    I'm using above approach because I have the Health Stat set to not Die on minimum like shown in the tutorials, so to have more control when enemies and player group dies.

    Other approach I'm also using to Kill every enemy using a debug console:


    if (Input.GetKeyDown(KillKey))
    {
    foreach(Combatant c in enemies)
    {
    ORK.Battle.EnemyDefeated(c);
    }
    }


    But I'm pretty sure GiL will come up with a better way ;)
    Post edited by RustedGames on
  • If you just want a combatant gone, destroy the game object and that'll take care of everything (no battle spoils, etc., though). Alternatively, you can also disable the game object - enabling it later will bring it back. That's all for non-player combatants, as the player group members are still available even if they are destroyed.

    For killing, either call (as @RustedGames said):
    combatant.Status.Death();
    This'll start using the death action to animate death and cause getting loot (if the player attacked the combatant at some point).

    Or change it's health to cause death, e.g.:
    combatant.Status[index].SetValue(0, false, true, false, false, null);
    The index is the ID/index of your health status value that causes death. This'll silently (without flying text, etc.) set the health to 0.
    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!
  • How do I get the combatant from a game object though? I've tried these but they don't seem to be working...

    myGameObject.GetComponent<CombatantComponent>()
    myGameObject.GetComponent<Combatant>()


    @RustedGames I've noticed in your second function you mentioned accessing a list of all enemies.

    foreach(Combatant c in enemies)
    {
    ORK.Battle.EnemyDefeated(c);
    }

    How did you obtained the initial list of enemies and is that just a list of hostile combatants involved in a Battle or a list of all the combatants the game (enemies and allies)?
  • ORK 2:
    Combatant combatant = ComponentHelper.GetCombatant(gameObject);

    ORK 3:
    Combatant combatant = ORKComponentHelper.GetCombatant(gameObject);
    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!
  • edited February 2022
    forgot to add the enemies list logic

    private List<Combatant> enemies = new List<Combatant>();

    private void Start()
    {
    foreach(Combatant c in ORK.Game.Combatants.GetAll())
    {
    if (c.Group.IsEnemy(ORK.Game.ActiveGroup.Leader))
    {
    if (!enemies.Contains(c))
    {
    enemies.Add(c);
    }
    }
    }
    }

    or another way

    enemies = ORK.Game.Combatants.Get(ORK.Game.ActiveGroup.Leader, false, null, Consider.Yes, Consider.No, Consider.Yes, null);
    Post edited by RustedGames on
  • edited February 2022
    Perfect, thank you :)

    Thank you @RustedGames as well for adding the enemies list logic :)
    Post edited by ChimpLogik on
Sign In or Register to comment.