Jump to content

Need some Professional Insight on a script attached to an actor


Recommended Posts

Ok i need help with a script attached to my custom follower but said follower is only custom in looks and armor

What i want to do is

Actor script detects if follower is recruited and/or dismissed then if recruit is true adds a spell then if dismiss is true removes that spell

 

So i need 2 version one on how to do this with out to create a custom follower framework for her

Second is with creating a custom follower framework for future plans

 

Please scripting gods answer me i beg

Link to comment
Share on other sites

At first you do not really have posted a script code here. What should we insight? Maybe next script is working for you.

 

shxFollowerAliasScript

 

Scriptname shxFollowerAliasScript extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/10123758-need-some-professional-insight-on-a-script-attached-to-an-actor/

  Spell PROPERTY myFollowerSpell auto        ; new created spell to give the follower, if players teammate


; -- EVENTs -- 5

EVENT OnInit()
    Debug.Trace(" OnInit() - has been reached.. " +self)                    ; for debugging only
    RegisterForSingleUpdate(1.0)    ; on new game or savegame first time
ENDEVENT

EVENT OnPlayerLoadGame()
    Debug.Trace(" OnPlayerLoadGame() - has been reached.. " +self)          ; for debugging only
    RegisterForSingleUpdate(1.0)    ; every time a savegame is loaded with this script
ENDEVENT

EVENT OnUpdate()
    RegisterForSingleUpdateGameTime(0.0)    ; check: Is already a follower? 
ENDEVENT


EVENT OnDeath(Actor akKiller)
    actor aRef = self.GetActorReference()
    aRef.RemoveSpell(myFollowerSpell)              ; ***
    self.Clear()
ENDEVENT


EVENT OnActivate(ObjectReference akActionRef)
IF (akActionRef == Game.GetPlayer() as ObjectReference)
    UnRegisterForUpdateGameTime()
    Utility.Wait(0.25)                      ; MANDATORY! wait here, until activation is over
    RegisterForSingleUpdateGameTime(0.0)    ; check: Is still follower or dismissed?
ENDIF
ENDEVENT


EVENT OnUpdateGameTime()
    Utility.Wait(1.0)
    actor aRef = self.GetActorReference()

IF ( aRef )
    IF aRef.IsPlayerTeammate()
            
        IF (aRef.GetActorValue("WaitingForPlayer") == 1)
            ; is waiting for player, anywhere
        ELSE
            IF aRef.HasSpell(myFollowerSpell)
                ; already active follower
            ELSE
                ; new recruited
                aRef.AddSpell(myFollowerSpell)        ; *A*
            ENDIF
        ENDIF
    
        RegisterForSingleUpdateGameTime(1.0)  ; try again 1 hour later
    ELSE
        ; not a follower
        aRef.RemoveSpell(myFollowerSpell)            ; ***
    ENDIF
ENDIF
ENDEVENT

 

 

 

Keep in mind this is a script of type "ReferenceAlias", not of type "Actor". You have to create a new quest, and inside at least one new alias. Attach the script on this alias, do not forget to fill the property.

If the alias is not assigned on quest start, tick on flag "optional" for that. To fill the alias at gameplay, create a new spell and use a magic effect with a script like next.

 

shxMakeFollowerEffectScript

 

Scriptname shxMakeFollowerEffectScript extends ActiveMagicEffect
; use in spell of type "fire and forget"

   ReferenceAlias PROPERTY myFollowerAlias auto       ; fill with alias from quest above

; -- EVENTs -- 2

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
    Debug.Trace(" OnEffectStart() - target = " +akTarget)

    IF ( myAlias )
        actor aRef = myFollowerAlias.GetActorReference()
        IF ( aRef )
            ; alias already filled
            IF (aRef == akTarget)
                myFollowerAlias.Clear()
            ENDIF
        ELSE
            ; alias found and not refered to actor  
            ; https://www.creationkit.com/index.php?title=ForceRefTo_-_ReferenceAlias
            myFollowerAlias.ForceRefTo(akTarget as ObjectReference)
       ENDIF
   ENDIF
ENDEVENT

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

At first you do not really have posted a script code here. What should we insight? Maybe next script is working for you.

 

shxFollowerAliasScript

 

Scriptname shxFollowerAliasScript extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/10123758-need-some-professional-insight-on-a-script-attached-to-an-actor/

  Spell PROPERTY myFollowerSpell auto        ; new created spell to give the follower, if players teammate


; -- EVENTs -- 5

EVENT OnInit()
    Debug.Trace(" OnInit() - has been reached.. " +self)                    ; for debugging only
    RegisterForSingleUpdate(1.0)    ; on new game or savegame first time
ENDEVENT

EVENT OnPlayerLoadGame()
    Debug.Trace(" OnPlayerLoadGame() - has been reached.. " +self)          ; for debugging only
    RegisterForSingleUpdate(1.0)    ; every time a savegame is loaded with this script
ENDEVENT

EVENT OnUpdate()
    RegisterForSingleUpdateGameTime(0.0)    ; check: Is already a follower? 
ENDEVENT


EVENT OnDeath(Actor akKiller)
    actor aRef = self.GetActorReference()
    aRef.RemoveSpell(myFollowerSpell)              ; ***
    self.Clear()
ENDEVENT


EVENT OnActivate(ObjectReference akActionRef)
IF (akActionRef == Game.GetPlayer() as ObjectReference)
    UnRegisterForUpdateGameTime()
    Utility.Wait(0.25)                      ; MANDATORY! wait here, until activation is over
    RegisterForSingleUpdateGameTime(0.0)    ; check: Is still follower or dismissed?
ENDIF
ENDEVENT


EVENT OnUpdateGameTime()
    Utility.Wait(1.0)
    actor aRef = self.GetActorReference()

IF ( aRef )
    IF aRef.IsPlayerTeammate()
            
        IF (aRef.GetActorValue("WaitingForPlayer") == 1)
            ; is waiting for player, anywhere
        ELSE
            IF aRef.HasSpell(myFollowerSpell)
                ; already active follower
            ELSE
                ; new recruited
                aRef.AddSpell(myFollowerSpell)        ; *A*
            ENDIF
        ENDIF
    
        RegisterForSingleUpdateGameTime(1.0)  ; try again 1 hour later
    ELSE
        ; not a follower
        aRef.RemoveSpell(myFollowerSpell)            ; ***
    ENDIF
ENDIF
ENDEVENT

 

 

 

Keep in mind this is a script of type "ReferenceAlias", not of type "Actor". You have to create a new quest, and inside at least one new alias. Attach the script on this alias, do not forget to fill the property.

If the alias is not assigned on quest start, tick on flag "optional" for that. To fill the alias at gameplay, create a new spell and use a magic effect with a script like next.

 

shxMakeFollowerEffectScript

 

Scriptname shxMakeFollowerEffectScript extends ActiveMagicEffect
; use in spell of type "fire and forget"

   ReferenceAlias PROPERTY myFollowerAlias auto       ; fill with alias from quest above

; -- EVENTs -- 2

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
    Debug.Trace(" OnEffectStart() - target = " +akTarget)

    IF ( myAlias )
        actor aRef = myFollowerAlias.GetActorReference()
        IF ( aRef )
            ; alias already filled
            IF (aRef == akTarget)
                myFollowerAlias.Clear()
            ENDIF
        ELSE
            ; alias found and not refered to actor  
            ; https://www.creationkit.com/index.php?title=ForceRefTo_-_ReferenceAlias
            myFollowerAlias.ForceRefTo(akTarget as ObjectReference)
       ENDIF
   ENDIF
ENDEVENT

 

 

 

Hi Thank you for this and yes i did not post a code because this was posted from my phone but heres my makeshift code that works for adding the spell but when dismissed does not remove the spell so basically i can summon her even if shes not following and this is without a quest

 

heres the script attached to her

 

SHXACompanionDynamicScript

ScriptName SHXACompanionDynamicScript Extends Actor
{Script to configure companion.}

Spell Property FollowerSummon Auto
{Spell to call companion}

Faction Property FactionCheck Auto
{Companion Faction to check}

Actor Property FollowerRef Auto
{Companion to configure}


Function OnPackageChange(Package akOldPackage)
    If FollowerRef.IsInFaction(FactionCheck)
       Self.GotoState("GiveSummon")
    EndIf 
EndFunction

State GiveSummon

 Function onBeginState()
     If !Game.GetPlayer().HasSpell(FollowerSummon As Form)
         Game.GetPlayer().AddSpell(FollowerSummon, True)
         Debug.Trace("SHX: Companion Summon spell add processing", 0)
     EndIf
 EndFunction
EndState

and this is the script attached to my spell with magic effect

SHXASummonScript

ScriptName SHXASummonScript Extends ActiveMagicEffect
{Summon companion If separated from player.}

VisualEffect Property MGTeleportOutEffect Auto

Actor Property FollowerRef Auto
{Companion to configure}

VisualEffect Property MGTeleportInEffect Auto



Function OnEffectStart(Actor akTarget, Actor akCaster)

 Actor PlayerREF = Game.GetPlayer()

 Utility.Wait(0.05)

 Float az = PlayerRef.GetAngleZ()

 MGTeleportOutEffect.Play(FollowerRef As ObjectReference, 2 As Float, None)

    FollowerRef.SetAlpha(0 As Float, False)
      FollowerRef.SetAngle(0.0, 0.0, az + 180.0) ; so actor is facing player
        FollowerRef.MoveTo(PlayerREF, 200.0 * Math.sin(az), 200.0 * Math.cos(az), 0.0, False)

 MGTeleportInEffect.Play(FollowerRef As ObjectReference, 2 As Float, None)

    FollowerRef.SetAlpha(1 As Float, True)
EndFunction

 

so this is what i got

Edited by ShadowHybriX
Link to comment
Share on other sites

  • Recently Browsing   0 members

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