Jump to content

[LE] Changing actor's voice type via script?


Recommended Posts

I do not have experience with VoiceType changing, and in particular SKSE special functions. Maybe next sample can be useful for understanding.

SampleAliasVoiceTypeScript

 

Scriptname SampleAliasVoiceTypeScript extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/7227756-changing-actors-voice-type-via-script/
; SeraphimKensai wrote: "I'm working on a script that is attempting to change an actors' voice and was confused about how to go about doing it."

  VoiceType PROPERTY newVoiceType auto        ; fill with CK
  VoiceType originalVT                        ; voiceType holder only


; -- EVENTs --

EVENT OnInit()
IF SKSE.GetVersion()
    gotoState("SKSE")                  ; ### STATE ###
    RegisterForSingleUpdateGameTime(0.0)
ELSE
    gotoState("NoSKSE")                ; ### STATE ###
ENDIF
ENDEVENT


EVENT OnUpdateGameTime()
    myF_Test()                ; run the test
ENDEVENT


;===============================
State SKSE
;=========
EVENT OnCellLoad()
ENDEVENT

EVENT OnLoad()
ENDEVENT

EVENT OnUnLoad()
ENDEVENT

EVENT OnActivate(ObjectReference akActionRef)
ENDEVENT
;=======
endState


;===============================
State NoSKSE
;===========
EVENT OnBeginState()
    Debug.Trace(self+" SKSE not loaded..")
ENDEVENT

EVENT OnCellLoad()
IF SKSE.GetVersion()
    gotoState("SKSE")                ; ### STATE ###    switch state, because SKSE is ready now
    RegisterForSingleUpdateGameTime(0.0)
ENDIF
ENDEVENT
;=======
endState


; -- FUNCTION --

; ******************************************************************************
; -- Race.psc -- SKSE modified
; VoiceType FUNCTION GetDefaultVoiceType(Bool female)                  native    ; returns the races default voice type
;           FUNCTION SetDefaultVoiceType(Bool female, VoiceType voice) native    ; sets the races default voice type

; -- ActorBase.psc -- SKSE modified
; VoiceType FUNCTION GetVoiceType()                 native                        ; gets the Actors voicetype
;           FUNCTION SetVoiceType(VoiceType nVoice) native                        ; sets the Actors voicetype
; ******************************************************************************

;------------------
FUNCTION myF_Test()
;------------------
    actor aRef = self.GetActorReference()        
   ;actor aRef = self.GetReference() as Actor            ; equal to above, but it needs two temp variables, not one

; https://www.creationkit.com/index.php?title=GetActorBase_-_Actor
    actorBase AB = aRef.GetActorBase()
   ;actorBase AB = aRef.GetBaseObject() as ActorBase    ; equal to above, but it needs two temp variables, not one

    oiginalVT = AB.GetVoiceType()            ;* global script variable
    Debug.Trace(self)
    Debug.Trace("---------------------------------------------------------------------------")
    Debug.Trace(" (before) actor = " +aRef+ ", ActorBase = " +AB+ ", VoiceType = " +originalVT)

    AB.SetVoiceType(newVoiceType)
    Debug.Trace(" (after) actor = " +aRef+ ", ActorBase = " +AB+ ", VoiceType = " +AB.GetVoiceType())

;--------------------------------
    race r = aRef.GetRace()
    voiceType VT                            ;* local function variable

    IF (AB.GetSex() == 0)                            ; male
        VT = r.GetDefaultVoiceType(False)
    ELSE ;IF (i == 1)                                ; female
        VT = r.GetDefaultVoiceType(TRUE)
    ENDIF

    Debug.Trace("Try to set default VoiceType by race..")
    Debug.Trace(" (before) race = " +r+ ", ActorBase = " +AB+ ", VoiceType: current = " +AB.GetVoiceType()+ ", default = " +VT+ ", original = " +originalVT)

    r.SetDefaultVoiceType(AB.GetSex() as Bool, VT)    ; male == False, female == TRUE
    Debug.Trace(" (after) race = " +r+ ", ActorBase = " +AB+ ", VoiceType: current = " + AB.GetVoiceType() + " == " +originalVT+ " ?")

;--------------------------------
    AB.SetVoiceType(originalVT)
    Debug.Trace(" (after) actor = " +aRef+ ", ActorBase = " +AB+ ", VoiceType: current = " + AB.GetVoiceType() + " == " +originalVT+ " ?")
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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