Jump to content

[LE] Simple Script help


BoneTongue

Recommended Posts

Im fairly new to scripting, i've only done a bunch of basic stuff

 

My question is, how do you make it so a script will only fire ONCE?

 

I dont want to do a self.disable on my pullchain

 

 

What im trying to do is just make a debug message pop up when the pullchain is activated

 

 

 

 

My script is (it is functional, it just repeats itself after every "Activate")

 

 

 

Scriptname BTG_PullChainTest extends ObjectReference
Actor Property PlayerRef Auto
Event OnActivate(ObjectReference akActionRef)
Debug.Trace("PlayerRef" + akActionRef)
if akActionRef == PlayerRef
Utility.Wait(2.5)
Debug.Notification("I can feel the ground rumbling")
endif
EndEvent
Thank you,
BTG
Link to comment
Share on other sites

Typically you'd set your script to run only if a variable has a value X, then change that variable inside the script so the condition is no longer true.

 

You can also use states, I think it's probably the better method but requires a little more effort to understand and implement.

 

This thread should have some relevant info:

https://forums.nexusmods.com/index.php?/topic/831819-force-a-script-to-run-only-once/

Link to comment
Share on other sites

Take a look at some of Bethesda default scripts

ScriptName defaultActivateLinkDoOnceSCRIPT 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.}

function ActivateNow(objectReference trigRef)
;  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
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

it a nice place to start if you don't want a custom scripts, or just to see how beth does certain things

Link to comment
Share on other sites

Int DoOnce

Event OnActivate(ObjectReference akActionRef)
if (akActionRef == PlayerRef)
  if (DoOnce == 0)
  DoOnce = 1
  Utility.Wait(2.5)
  Debug.Notification("I can feel the ground rumbling")
  endif
    endif
EndEvent

Try this. It's just using an int. People might prefer to use a boolean, but it functions in the same way.

Link to comment
Share on other sites

Int DoOnce

Event OnActivate(ObjectReference akActionRef)
if (akActionRef == PlayerRef)
  if (DoOnce == 0)
  DoOnce = 1
  Utility.Wait(2.5)
  Debug.Notification("I can feel the ground rumbling")
  endif
    endif
EndEvent

Try this. It's just using an int. People might prefer to use a boolean, but it functions in the same way.

 

Thank you so much, it worked flawlessly and was very "light" compared to another one a friend showed me and didnt involve quests.....

 

I'm leaving this topic up for others to learn from

Link to comment
Share on other sites

  • Recently Browsing   0 members

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