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...).
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 ;)
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)?
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!
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);
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 ;)
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.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
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)?
Combatant combatant = ComponentHelper.GetCombatant(gameObject);
ORK 3:
Combatant combatant = ORKComponentHelper.GetCombatant(gameObject);
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
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);
Thank you @RustedGames as well for adding the enemies list logic :)