Jump to content

Can't get the "Kill" function to work on an actor


Recommended Posts

Hey, I'm currently working on a mod which adds an injury and death system to followers. In my simplified first version, I want to have an Int that tracks the injuries a follower has. Each time they enter bleedout, the integer is incremented by 1. Upon reaching 3 injuries, the follower should be killed.

Here's how I tried to implement this:

Scriptname fidFollowerInjuryScript extends Actor
{Increased injury number when follower 
enters Bleedout and unprotects + kills them
if number of injuries reaches threshold.
}

Int Property numberOfInjuries  Auto  

Event OnEnterBleedout()
	If numberOfInjuries < 3
		numberOfInjuries = numberOfInjuries + 1
		Debug.MessageBox("Follower has"+numberOfInjuries+" injuries.")
	ElseIf numberOfInjuries >= 3
		self.Kill()
	Else
		Debug.MessageBox("Invalid number of injuries")
	EndIf
EndEvent

I have attached this script to Jenassa for testing purposes. The number of injuries increases correctly, but the Kill() function doesn't work. Instead of dying, she just gets stuck in an animation loop playing the "getting back up" animation that usually plays when a follower recovers from their bleedout/knocked out state. I have also tried the KillEssential() function instead, but the result was the same.

Has somebody encountered a similar issue? I can only speculate that calling the Kill() function inside the OnEnterBleedout Event might not work properly, but I am unsure right now how I could fix this.

Thanks in advance :smile:

Link to comment
Share on other sites

Jenassa is marked as protected. Trying using KillEssential() to test it on her.

 

KillEssential() only removes the essential flag, you need to use it in combination with kill.
KillEssential()
kill()
Link to comment
Share on other sites

 

Jenassa is marked as protected. Trying using KillEssential() to test it on her.

Â

KillEssential() only removes the essential flag, you need to use it in combination with kill.

KillEssential()

kill()

According to the wiki the function includes Kill() inside it.

 

https://www.creationkit.com/index.php?title=KillEssential_-_Actor

Link to comment
Share on other sites

I have tried using KillEssential(), the result was the same. I have adjusted the script as follows (removing the injury bit for easier testing), still the same issue:

Scriptname fidDeathTestScript extends Actor

ActorBase Property baseOfThis  Auto 
Actor Property PlayerRef  Auto   

Event OnEnterBleedout()
	baseOfThis = self.GetActorBase()
	baseOfThis.SetEssential(false)
	baseOfThis.SetProtected(false)
	RegisterForSingleUpdate(1.0)
EndEvent

Event OnUpdate()
	If baseOfThis.IsEssential()
		Debug.MessageBox("Tried to kill actor but is still essential")
	Else
		self.kill(PlayerRef)
	EndIf
	If self.IsDead()
		Debug.MessageBox("Follower has died")
	Else
		RegisterForSingleUpdate(1.0)
	EndIf
EndEvent

I think I'm going to avoid using the Kill() function entirely, instead just setting the follower to unprotected/non-essential upon reaching a certain number of injuries so they die next time they drop to 0 hp.

 

EDIT:

Alright, I figured out why it didn't work. Turns out, when recruiting a follower, they become an alias for the DialogueFollower quest. This quest alias has the "Protected" flag set, overriding the state of the "Protected" flag on the actor itself. For now, I have simply removed the Protected flag from the quest alias, although I'm a bit unsure whether that could lead to issues down the line.

I'm also still confused as to why the KillEssential() function did not work. I can only assume that KillEssential() can not be used on a protected actor?

In case anyone finds this useful, here is the current script I'm using:

Scriptname fidFollowerInjuryScript extends Actor
{Increased injury number when follower 
enters Bleedout and unprotects + kills them
if number of injuries reaches threshold.
}

Int Property numberOfInjuries  Auto

ActorBase Property baseOfThis  Auto  

Event OnEnterBleedout()
	If numberOfInjuries < 3
		numberOfInjuries = numberOfInjuries + 1
		Debug.MessageBox("Follower has"+numberOfInjuries+" injuries.")
	ElseIf numberOfInjuries >= 3
		baseOfThis = self.GetActorBase()
		baseOfThis.SetEssential(false)
	Else
		Debug.MessageBox("Invalid number of injuries")
	EndIf
EndEvent

In order for this to work as intended, the "essential" flag must also be set on the actor, otherwise they will just die immediately the first time they drop to 0 hp.

Edited by TheLegendaryBen
Link to comment
Share on other sites

Protected status is different from Essential.

 

Essential = NOBODY can kill it.

 

Protected = NOBODY ELSE except the player can kill it.

 

KillEssential() checks if the actor is essential and is flagged as unique, if it is, kill() is then called.

 

Edit: To kill an actor that has the protected flag set on the quest alias, simply set the killer as the player, since as per the above, only the player the can kill protected actors.

 

So here's what I've come up with.

Function KillProtected(Actor akVictim)
ActorBase kVictimBase = akVictim.GetBaseObject() as ActorBase
 
; Does 2 checks. One for the flag set on the actorbase level, and the other for the flag
; set on the quest level, if any.
 
if kVictimBase.isProtected() == true
    kVictimBase.SetProtected(false)
    akVictim.Kill()
    
    if akVictim.isDead() == false
        if akVictim.IsBleedingOut() == true
            akVictim.Kill(Game.GetPlayer())
        endif
    endif
endif
 
EndFunction
Edited by Rasikko
Link to comment
Share on other sites

A lot of important things has been posted already. Nevertheless it's always a good idea to assign a script not to the ACTOR directly.

Better way is using a new quest, create an alias and assign them with ReferenceAlias script.

 

fidFollowerInjuryScript

 

Scriptname fidFollowerInjuryScript extends Actor
{kill the assigned actor after some injuries}
; https://forums.nexusmods.com/index.php?/topic/8589363-cant-get-the-kill-function-to-work-on-an-actor/

; Increased injury number when follower enters Bleedout and unprotects + kills them
; if number of injuries reaches threshold.

  Int PROPERTY numMax = 3 auto           ; [default = 3]
  Int PROPERTY number     auto Hidden    ; the counter


; -- EVENTs --

EVENT OnInit()
    Debug.Trace(self+" OnInit() - has been reached..")
ENDEVENT


EVENT OnEnterBleedout()
IF (number < numMax)
    number += 1
    Debug.MessageBox("Follower has " +number+ " injuries.")        ; debugging only !!!
    RETURN    ; - STOP -
ENDIF
;---------------------
    gotoState("Done")                ; ### STATE ###
    self.StopCombat()
    myF_KillMe()
ENDEVENT


EVENT OnDeath(Actor akKiller)
    gotoState("Done")                ; ### STATE ###    just in case
ENDEVENT


;===============================
state Done
;=========
    EVENT OnEnterBleedout()
    ENDEVENT

    EVENT OnDeath(Actor akKiller)
    ENDEVENT
;=======
endState


; -- FUNCTIONs --

;---------------------------------------
Bool FUNCTION myF_IsFollower(Actor aRef)  ; just a sample for conditions
;---------------------------------------
    DialogueFollowerScript ps = (Game.GetForm(0x000750BA) as Quest) as DialogueFollowerScript    ; DialogueFollower [QUST:000750BA]

IF ( ps )                                            ; valid quest script
    referenceAlias RA = ps.pFollowerAlias
    IF ( RA )                                        ; valid alias
        RETURN (aRef == RA.GetActorReference())      ; TRUE or False
    ENDIF
ENDIF
    
    Return False
ENDFUNCTION


;--------------------
FUNCTION myF_KillMe()
;--------------------
    DialogueFollowerScript ps = (Game.GetForm(0x000750BA) as Quest) as DialogueFollowerScript    ; DialogueFollower [QUST:000750BA]

;"when recruiting a follower, they become an alias for the DialogueFollower quest.
; This quest alias has set the 'Protected flag' which is overriding the 'flag on the actor itself'."

IF ( ps )                                           ; valid quest script
    referenceAlias RA = ps.pFollowerAlias
    IF (RA) && (RA.GetActorReference() == self)
        ps.DismissFollower(0, 0)                    ; dismiss silence
        Utility.Wait(0.1)
    ENDIF
ENDIF

    ; https://www.creationkit.com/index.php?title=KillEssential_-_Actor

    actorBase AB = self.GetBaseObject() as ActorBase

    IF AB.IsProtected()
        ; If you set the flag, and the actor is essential, the essential flag will be cleared.
        AB.SetProtected(False)        ; clears actors protected flag
    ENDIF

    IF AB.IsEssential()
        ; If you set the flag and the actor is protected, the protected flag will be removed.
        AB.SetEssential(False)        ; clears actors essential flag
    ENDIF

;;  self.Kill(self as Actor)          ; Suizide!
    self.Kill( Game.GetPlayer() )     ; killed by player suggested by Rasikko
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...