Is there a way to revive the player via code after it's been killed?
  • Sure, beside changing the health status value to something that doesn't immediately kill the combatant again, you also need to set the death state (and a status recalculation afterwards doesn't hurt):
    combatant.Status.DeathState = CombatantDeathState.Alive;
    combatant.Status.MarkResetStatus();

    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!
  • Using the functions below I was able to get in the player's Combatant Component
    IsDead = false
    Health = max value
    but once "revived", the player doesn't respond anymore to
    click-movement inputs
    can't perform any ability (the shortcut ability HUD is gone).

    These are the Kill/Revive functions I used:
    private void KillPlayer()
    {
    ORKCombatantStatusValues.AddCombatantStatusPoints(playerObject, -1000, ORKGUIDs.statusValue_health);
    GlobalFunctionsManager.GetPlayerCombatant().Status.DeathState = CombatantDeathState.Dead;
    }
    private void RevivePlayer()
    {
    ORKCombatantStatusValues.AddCombatantStatusPoints(player, 1000, ORKGUIDs.statusValue_health);
    GlobalFunctionsManager.GetPlayerCombatant().Status.DeathState = CombatantDeathState.Alive;
    ORKComponentHelper.GetCombatant(GlobalFunctionsManager.GetPlayer()).Status.MarkResetStatus();
    }
  • Might be either a control block (e.g. in the death schematic of the player), a game over (check the game over settings in Game > Game Settings, especially Auto Game Over should be disabled to not cause game over in field/real time area battles) or dead combatants being set up to leave their groups (see the death settings of the combatant/general combatant settings, found in their battle settings).
    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 was indeed the Auto Game Over, thank you Nicholas!
  • edited June 2024
    I am getting discrepancies in editor Vs in build when the player gets killed. Everything works in editor but in the build the player does not get revived.
    I don't know if this is caused by obvious errors on my part or not accounting for other elements like saving times on file...

    Currently the cycle at the end of a session when the player gets killed is the following.
    1) player killed
    2) revive player (so it's not saved dead) using the revive functions below
    3) player progress saved using:
    SavePlayerXML_ToFile(player_initial_ORK_XML, NameManager.save_initial_player_data_key);
    4) End game using:
    Maki.SaveGame.Save(0);
    Maki.Game.StopGame(true);
    5) New game using
    ORK.Game.NewGame(true);
    6) wait for player spawned
    7) Load previous progress on new blank player using:
    DataObject data = new GamingIsLove.Makinom.IO.XMLParser(xml, null).Parse();
    8) check if player was saved "dead" and revive it if needed ( added on top of 2) since it was not working)

    Revive functions used in 2) and 6)
    if(playerCombatant.Status.DeathState == CombatantDeathState.Dead )
    {
    ORKCombatantStatusValues.AddCombatantStatusPoints(playerObject, 1000, ORKGUIDs.statusValue_health); // 1000 is waay over the max player hp
    playerCombatant.Status.DeathState = CombatantDeathState.Alive;
    playerCombatant.Status.MarkResetStatus();
    }
    Post edited by ChimpLogik on
  • Is any error occuring in the built game when this happens?
    Might be some code stripping in the built game. Check your build/player settings in Unity - depending on the Unity version that can be named differently, but should be in the optimization settings and named something like Managed Stripping Level, which you should set to disabled.
    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 June 2024
    I checked and that Managed Stripping Level was already set to disabled :(

    If there are no obvious errors in my code above, would you suggest:

    a) reviving the player before saving its XML data
    b) saving it dead and reviving it when the game starts after it's spawned and the previous XML is loaded onto the player?
    c) they are equivalent
    Post edited by ChimpLogik on
  • If there'd be errors, it'd already break in the editor :)

    Could be that something in the custom saving is not working in build (SavePlayerXML_ToFile and whatever you use to load that again). E.g. saving somewhere it's not allowed to or some other thing.

    Maybe add some debug output throughout the save/load process and check what's going on that way.
    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!
  • On a related note, before reviving the player, I was trying to set its HP to the max value through this function (as opposed to adding a very high value, which works) but this function doesn't seem to actually set anything:
    public static void SetCombatantStatusValue(GameObject item, string _guid, int amount)
    {
    if (item != null && ORKComponentHelper.GetCombatant(item) != null)
    {
    Combatant combatant = ORKComponentHelper.GetCombatant(item);
    combatant.Status[ORK.StatusValues.GUIDToIndex(_guid)].SetValue(amount, false, true, true, false, true, null);
    }
    }
  • edited June 2024
    Should work, though depends on what amount is set to.

    On a different note, there's a function to regenerate (heal consumable stats) and revive a combatant available:
    combatant.Status.Regenerate(true);
    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!
  • edited June 2024
    I did some tests and I am getting some odd behaviors.

    I moved the ReplenishPlayer() and RevivePlayer() functions to the player gameobject Death event.
    combatant.Events.DeathStateChangedSimple += this.NotifyDeath;
    public virtual void NotifyDeath()
    {
    ReplenishPlayer();
    RevivePlayer();
    }

    private void RevivePlayer()
    {
    Debug.Log("EventDeath.RevivePlayer() Player."); //(1)
    if(combatant.Status.DeathState == CombatantDeathState.Dead) //(2)
    {
    Debug.Log("EventDeath.RevivePlayer() Player. Player status = dead"); //(3)
    playerCombatant.Status.DeathState = CombatantDeathState.Alive;
    playerCombatant.Status.MarkResetStatus();
    }
    }

    The event is received correctly when the player dies but:
    - the player attributes are not changed
    - the player death state does not get recognized on (2)
    - even if (2) condition gets removed, the player still does not get revived...
    Post edited by ChimpLogik on
  • edited June 2024
    gamingislove said: or dead combatants being set up to leave their groups (see the death settings of the combatant/general combatant settings, found in their battle settings).
    Did you check that earlier as well? E.g. if the player leaves the player group on death, changing things on that combatant and afterwards getting player will operate on different combatants (or rather only have one combatant and no player).

    Your script uses different combatants - one checks if combatant is dead and afterwards changes things on playerCombatant. Both are not really set anywhere in the code you posted, so hard to say if they are the correct combatants ...
    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!
  • Yes, in the player Battle Settings, Leave on Death = false

    Regarding the combatant and playerCombatant, they are the same, I was trying to simplify the code for the sake of brevity on the forum.
  • Just noticed, The code above only sets the death state back to alive, but doesn't regenerate health, so combatant will just die again if health is still 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!
  • edited June 2024
    The function ReplenishPlayer() does that using the same code I posted earlier in the thread.

    Apologies about the lack of clarity, I was trying to be concise but I realize it's actually not helping the conversation :(
    Post edited by ChimpLogik on
Sign In or Register to comment.