Jump to content

How to make a run-once script?


Glenstorm

Recommended Posts

What Paladin posted is pretty much spot on. The code block has to be contained within a script which is always in existance though, ie a startgame enabled quest, or on a persistent reference.

 

If it's on an object which is destroyable, or there are multiple objects of a type, ie food, it will run once for every object.

Link to comment
Share on other sites

Here's a more specific way to do it. :P

 

at the top of the script(where you define some extra variables), you can do bdoonce

 

Example:

 

SCN Scriptname

short bDoOnce

Begin OnActivate (or OnTrigger)
    if (bDoOnce == 0)
          result script
          set bDoOnce to 1
    end if

 

I currently use a script using this function in a mod I'm making, and works like a charm. :thumbsup:

Edited by jhardingame
Link to comment
Share on other sites

If you need the script to run as soon as the mod is loaded, and I think that's what you asked, best way is to use a quest script. You can create a special quest just for running the script, and set it to a lvl 60 or so priority, with start game enabled checked.

 

Then in the script you call stopquest Questname, and the script will stop running. This it typically used to add items to the player when starting a mod, but you can do whatever you need.

 

short once

Begin GameMode

if once == 0
  ;do stuff
  stopquest QuestName
  set once to 1
endif

End

Link to comment
Share on other sites

If you need the script to run as soon as the mod is loaded, and I think that's what you asked, best way is to use a quest script. You can create a special quest just for running the script, and set it to a lvl 60 or so priority, with start game enabled checked.

 

Then in the script you call stopquest Questname, and the script will stop running. This it typically used to add items to the player when starting a mod, but you can do whatever you need.

 

short once

Begin GameMode

if once == 0
  ;do stuff
  stopquest QuestName
  set once to 1
endif

End

 

Just what I was looking for. I didn't know of the function stopquest. Haven't explored the quest portion of the GECK yet, as you probably guessed. Thanks a lot!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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