Jump to content

[LE] Script Function for Sneaking to Activate Trigger


jucoking

Recommended Posts

Perhaps the following will be helpful:

RegisterForAnimationEvent

OnAnimationEvent

Animation Events

 

Sounds like you are already monitoring if the player enters the trigger while sneaking but want to catch if they go into sneak while already in the trigger. The animation event method may be best. Track sneak state when entering. If sneaking, do your thing as you already are. If not sneaking, register for the sneak animation events. When the sneak animation event is triggered do your thing. You may wish to utilize a bool to stop the sneak event from triggering additional times if the player changes sneak state either on purpose or gets triggered via one of the "accidental" methods outlined on the Animation Events page linked above.

 

I would recommend a script with the following basics on your trigger volume box.

 

 

Scriptname TriggerVolumeBoxScript Extends ObjectReference
 
Event OnTriggerEnter(ObjectReference akActionRef)
  If akActionRef == Game.GetPlayer()
    If akActionRef.IsSneaking()
      ;already sneaking - do stuff
    Else
      RegisterForAnimationEvent(akActionRef,"tailSneakIdle")
      RegisterForAnimationEvent(akActionRef,"tailSneakLocomotion")
    EndIf
  EndIf
EndEvent
 
Event OnTriggerLeave(ObjectReference akActionRef)
  If akActionRef == Game.GetPlayer()
    UnregisterForAnimationEvent(akActionRef,"tailSneakIdle")
    UnregisterForAnimationEvent(akActionRef,"tailSneakLocomotion")
  EndIf
EndEvent
 
Event OnAnimationEvent(ObjectReference akSource, String asEventName)
  If akSource == Game.GetPlayer()
    If asEventName == "tailSneakIdle" || asEventName == "tailSneakLocomotion"
      ;player started sneaking while inside the trigger - do stuff
    EndIf
  EndIf
EndEvent

 

 

Link to comment
Share on other sites

That did the trick! Thanks so much! Here is the final script:

 

 

 

Scriptname CV2_ActivateBridgetoRoverBCscript extends ObjectReference  

{Default script intended for triggers.  When hit, they'll activate their linked reference}

import game
import debug

objectReference property OnlyActor auto
{Set this property if you want to only allow activation from a specific actor, such as the player}

bool property doOnce auto
{by default, this trigger fires once only.}

Actor Property PlayerRef Auto

Key Property CV2_BlueCrystalKey Auto

function ActivateNow(objectReference trigRef)
    If PlayerRef.GetItemCount(CV2_BlueCrystalKey) == 1 && PlayerRef.IsSneaking()
;     Debug.Trace("Activating: " + self + " " + myLink)
    objectReference myLink = getLinkedRef()

    self.activate(self, true)
    if MyLink != NONE
        myLink.activate(self as objectReference)    
    endif
    if doOnce == true
        gotoState("allDone")
    endif
    Else
      RegisterForAnimationEvent(PlayerRef,"tailSneakIdle")
      RegisterForAnimationEvent(PlayerRef,"tailSneakLocomotion")
    EndIf
endFunction

auto STATE waiting
    EVENT onTriggerEnter(objectReference actronaut)
;     Debug.Trace("Trigger Enter: " + actronaut)
            
        if !onlyActor
            activateNow(actronaut)
        endif
        
        if onlyActor == actronaut
            activateNow(actronaut)
        endif
        
    endEVENT
endSTATE

STATE allDone
;do nothing
endSTATE
 
Event OnTriggerLeave(ObjectReference akActionRef)
  If akActionRef == PlayerRef
    UnregisterForAnimationEvent(akActionRef,"tailSneakIdle")
    UnregisterForAnimationEvent(akActionRef,"tailSneakLocomotion")
  EndIf
EndEvent
 
Event OnAnimationEvent(ObjectReference akSource, String asEventName)
  If akSource == PlayerRef && PlayerRef.GetItemCount(CV2_BlueCrystalKey) == 1
    If asEventName == "tailSneakIdle" || asEventName == "tailSneakLocomotion"
    objectReference myLink = getLinkedRef()

    self.activate(self, true)
    if MyLink != NONE
        myLink.activate(self as objectReference)    
    endif
    if doOnce == true
        gotoState("allDone")
    endif
      ;player started sneaking while inside the trigger - do stuff
    EndIf
  EndIf
EndEvent

 

 

 

You all are the best!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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