In a nutshell, I'm trying to create a script, that, upon the player's (or any Actor I attach the script to) death, they will come back to life. To accomplish this, I have set the player to be an essential NPC, and made him into a quest alias on my control quest. On his "OnEnterBleedOut()" Event, code is run to make it happen.
Scriptname Lich02QuestLichAliasScript extends ReferenceAlias {This script alters the death of the Lich assuming he is a Type 02 Lich}Lich02QuestScript Property Lich02Quest AutoActor Property Lich AutoEvent OnInit() ; Set Lich Actor to Self Lich = GetActorRef()EndEventEvent OnEnterBleedOut() Utility.Wait(3.5) ; Let the Lich's ragdoll hit the ground Lich02Quest.AdjustTargetHP(Lich, 15) ; Set Lich's health to 15EndEvent
The above uses a custom function within my Lich02Quest script. The code is as follows:
Function AdjustTargetHP(Actor Target, Float TargetHP) ; Acquire the Target's current HP Float CurHP = Target.GetAV("Health") ; Adjust HP accordingly If CurHP < TargetHP ; Target is lower than Target HP. Heal him ; Debug.MessageBox("Target is lower than Target health. Let's heal him.") Target.RestoreAV("Health", TargetHP - CurHP) Else ; Target is higher than Target HP, damage them ; Debug.MessageBox("Target is higher than Target health. Let's damage him.") Target.DamageAV("Health", TargetHP - CurHP) EndIf EndFunctionSo, upon running, if they have higher health than the number that was passed to the function, they will be damaged until they hit that specified value. If they were lower, they will be healed.
I use the AdjustHealth function to both bring an essential actor "back from the dead", and put them in a near death state.
On to the issue:
This all works perfectly the VERY FIRST TIME it is run. The actor dies, kneels over for a couple seconds (as per the Utility.Wait function), and then is healed to 15HP (Because he currently has negative health). However, upon his second "death", without the help of ANY code what so ever, he is restored to FULL hp immediately after he is thrown into the "OnEnterBleedOut" event.
This can even be tested using only console commands without the aid of the AdjustTargetHP method. That is to say, if you simply leave them hanging in in the IsBleedingOut state, they will stay that way forever. If you restore their hp using console commands, the exact same result will be produced. The only time the player actually "stays down" is on his first "death".
I couldn't figure out why this was happening, so I searched through the available actor functions to try and find a solution. I'd thought I found one.
Event OnEnterBleedOut() Self.SetNoBleedoutRecovery(True) ; Prevent Actor from recovering from bleedout Utility.Wait(3.5) ; Let the Lich's ragdoll hit the groundEndEvent
And it worked great! Upon his second death he did not restore to full hp. With the code I used above, I was merely trying to ensure he stayed down, so I had to bring him out of bleedout myself via RestoreAV Health command. However, it seems it was not quite as successful as I had hoped. The moment the player is restored above 1 HP, he is healed to full, regardless of the restore amount. I did some testing and this occurs regardless of whether it is done via console or script. No matter what, the very first "RestoreAV Health" that is run after entering the bleedout state, brings the player (and perhaps any target, though I haven't tested it on others yet.) above 1HP, he is healed to full.
Why does this happen, how can I stop it? I can't even seem to control it via scripts for some reason. They are healed to full no matter what I do. Any help appreciated...