Jump to content

Need a Script to Enable/Disable in Triggerbox, help plez.


NexBeth

Recommended Posts

Well, long story short, I've been trying to get a sound marker to go on then off at certain times. I initially attempted to apply conditions within AI packages to make it go off. That should have worked, but could never get it to work.

 

https://forums.nexusmods.com/index.php?/topic/7788313-set-a-condition/

 

Now, and I think it is actually a better option, I am trying to get this to be triggered when an NPC enters the trigger (on sound) and leaves trigger (off sound).

 

I've got the triggerbox set with the following script attached:

 

Scriptname EP_NameScript extends ObjectReference

 

Int iCount = 0 ;

Event OnTriggerEnter(ObjectReference akActionRef)
If (akActionRef as Actor) && akActionRef != Game.GetPlayer()
iCount += 1
ObjectReference kTemporary = GetLinkedRef() ;
If iCount == 1 && kTemporary && kTemporary.IsDisabled() ;
kTemporary.Enable()
EndIf
EndIf
EndEvent

Event OnTriggerLeave(ObjectReference akActionRef)
If (akActionRef as Actor) && akActionRef != Game.GetPlayer()
iCount -= 1
ObjectReference kTemporary = GetLinkedRef() ; s
If iCount == 0 && kTemporary && !kTemporary.IsDisabled() ;
kTemporary.Disable()
EndIf
EndIf
EndEvent

 

 

No properties on script.

This triggerbox is link-ref to an activator (below).

Z is set to number other than zero.

 

Have activator (initially disabled) with defaulttoggleselfonactivate script attached, no properties

Has player activation ticked

Z is set to number other than zero

 

Sounder maker has the above activator set as Enable Parent.

 

Won't work.

 

I'm not a script-er. The script above was gifted to me for another very similar situation, but for some reason won't work.

 

Any help is appreciated. Thanks

Link to comment
Share on other sites

Not sure what the iCount is for, can't you keep it simple:

 

EVENT onTriggerEnter(objectReference akActionRef)
if akActionRef == Game.GetPlayer()
;Do something
endif
endEvent


EVENT OnTriggerLeave(objectReference akActionRef)
if akActionRef == Game.GetPlayer()
;Do something else
endif
endEvent

 

 

Also kTemporary is a property and needs to be defined.

Link to comment
Share on other sites

iCount is used to keep track of how many/when objects enter and leave the trigger. It's an old way to ensure that the events do not fire out of sequence(i.e OnTriggerLeave firing before OnTriggerEnter). The creator of papyrus though has stated in the past the GetTriggerObjectCount() is better.

Link to comment
Share on other sites

" Now, and I think it is actually a better option, I am trying to get this to be triggered when an NPC enters the trigger (on sound) and leaves trigger (off sound). "


Why don't you use a default vanilla script ? :

defaultDisableExitEnableEnter


This script will disable the triggerbox's linked references when the player exits the triggerbox, then enables them when the player enters the triggerbox. This script will only work on triggerboxes. Only 5 linked references can be recognized.

Link to comment
Share on other sites

 

" Now, and I think it is actually a better option, I am trying to get this to be triggered when an NPC enters the trigger (on sound) and leaves trigger (off sound). "
Why don't you use a default vanilla script ? :
defaultDisableExitEnableEnter
This script will disable the triggerbox's linked references when the player exits the triggerbox, then enables them when the player enters the triggerbox. This script will only work on triggerboxes. Only 5 linked references can be recognized.

 

I would gladly but as I said I'm not a scripter so I don't know which one might work. Right now the activator which is linked to the trigger as defaulttoggleselfonactivate script attached, which is a vanilla script. Also, this needs to work with NPCs not the player.

Link to comment
Share on other sites

I don't know why you need an " Activator ", but you can Link Ref the " Sounder maker " directly to the script's properties ( MyREF ).

* " Sound Marker " should be in a initialy disable state.

Script should look something like this so that all actors can trigger it :


ObjectReference Property MyREF Auto
{Enable and Disable Link Ref on Trigger Enter - Leave}

ObjectReference Property MyActivator auto
{Activates Activator}


EVENT onTriggerEnter(objectReference triggerRef)
if triggerRef as Actor == TRUE
MyREF.Enable()
MyActivator.Activate(self)
EndIf
ENDEVENT


EVENT onTriggerLeave(objectReference triggerRef)
if triggerRef as Actor == TRUE
MyREF.Disable()
MyActivator.Activate(self)
EndIf
ENDEVENT


Link to comment
Share on other sites

@maxarturo: Thanks for writing that up for me. You said I don't need an activator but you included a property for an activator? Not sure what to do. I've created the script and it compiled. Linked the myRef property to the sound marker. Just need to understand the activator part?

Edited by NexBeth
Link to comment
Share on other sites

  • Recently Browsing   0 members

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