Some of my combatants have a script component that is supposed to spawn specific items (with a different logic than the loot system) when the combatant dies, is damaged or has status effects on it.
Is there a way for this script to be notified when its combatant dies, is damaged or has status effects on it?
First, get the combatant of the game object:
Combatant combatant = ORKComponentHelper.GetCombatant(this.gameObject);
E.g. in the Start function of the component should have it already set up when spawning.
Next, register to the combatant's handlers:
combatant.Status[statusID].SimpleChanged += this.NotifyStatusValue;
combatant.Status.DeathStateChangedSimple += this.NotifyDeath;
combatant.Status.Effects.Changed += this.NotifyEffect;
THe statusID here is the ID/index of the status value in the editor.
The functions you register should have no parameters, e.g.:
public void NotifyStatusValue()
{
// do your stuff
}
Alternatively, you can also do it without any scripting and just use schematics:
- status change schematics in your status values
- effect schematics in your effects (e.g. used on apply or remove)
- schematic animating the combatant's death
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
combatant.Status[statusID].ValueChanged += this.NotifyStatusValue;
The function needs some parameters in that case:
public void NotifyStatusValue(Combatant combatant, StatusValue statusValue, int change)
For status effects, you can either check for effects in combatant.Status.Effects, or register to the added/removed handlers:
combatant.Status.Effects.Added += this.NotifyEffectAdded;
combatant.Status.Effects.Removed += this.NotifyEffectRemoved;
Both require a function with these parameters:
public void NotifyEffect(Combatant combatant, StatusEffect effect)
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
string statusEffectGUID = "myStatusEffectGUIDstring";
if(combatant.Status.Effects.Get(statusEffectGUID)!=null)
{
// do my things
}
where combatant is the combatant I am checking, but doesn't seem to be working...
It doesn't use the GUID of the effect, but the unique GUID of the added instance of the effect.
If you want to get effects by GUID, get the effect settings for your GUID and use that to get the effect instance:
StatusEffectSetting effectSetting = ORK.StatusEffects.Get("yourGUID");
if(effectSetting != null && combatant.Status.Effects.Get(effectSetting) != null)
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
After that I got excited and tried to add a status effect via script...but that didn't go as well as I hoped.
StatusEffectSetting effectSetting = ORK.StatusEffects.Get("myGUID");
if (effectSetting != null)
combatant.Status.Effects.Add(effectSetting, combatant, effectChange, false, false, this.gameObject, null, null);
combatant.Status.Effects.Add(effectSetting, combatant, null, false, false, null, null, null);
You only need the StatusEffectChange and source if you actually have those things. The source would e.g. be an ability that cast the effect.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!