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?
  • Easiest way would be to register to the related event handler on the combatant.
    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
    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!
  • I used the first approach and it works, but I am not quite sure how to get information on the type of status effects on the combatant (for example to know if a specific one is there) or information about the status value change (for example to know if the status value has increased or decreased).

  • There are other event handlers to register to for more detailed information, e.g. for status value changes:
    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)
    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!
  • I tried checking if a specific status effect is present on a combatant using combatant.Status.Effects through a defined GUID string with something like:

    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...
  • edited February 2022
    Yeah ... that's a different GUID ... :D
    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)
    Post edited by gamingislove on
    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!
  • That worked like a charm, thank you!
    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);
  • Try this:
    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.
    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!
  • It worked perfectly, thank you so much!
  • It worked perfectly, thank you so much!
Sign In or Register to comment.