Jump to content

[LE] OnInit question


Recommended Posts

I have an activator spawning random creatures when activated. That part is working ok. But I'm having trouble because I want the first creature in the list to be already spawned before the button is activated. I tried OnInit but it seems to fire twice. when I first enter the cell there are 2 of the creatures I want. Activating the button removes one and replaces that one but leaves the first still in the cell. Without OnInit the cage is empty until activated. I thought of trying OnCellLoad or OnCellAttach to cause the activator to activate itself. That would at least prevent an empty cage, at least if they fired reliably,

 

Just thought of an idea. Just place a creature in the cage and have the activator simply disable it.

 

But I would still like to know what is going on with OnInit.

Link to comment
Share on other sites

The "OnInit" will fire twice, one when the game is loaded and one when you enter that cell (where the script is living).


One way to handle that "Twice Fired" is to use 'States'.

Example:


Auto State Waiting

Event OnInit(...)

.......Do something

.......Do something Else

GoToState("WaitingPlayer")

EndEvent

EndState


State WaitingPlayer

Event SomeEvent(....)

.......Do something

.......Do something Else

EndEvent

EndState

Edited by maxarturo
Link to comment
Share on other sites

I tried something like that. I got a compile error saying OnInit needed to be in the Empty State so I removed the whole SetUp State and just had OnInit .

That did not work out.

Anyway it finally works by getting rid of OnInit entirely and just placing a reference and having it disabled and deleted OnActivation.

Sooner or later I might figure out Papyrus. Right now the explanations at CreationKit.com are often rather confusing even with the examples they give.

I really admire those that can make some of the really complicated mods

Thank you for your patience and help for a novice.

Link to comment
Share on other sites

You can do it without the state method by registering for an update. Even tho the OnInit runs twice the update event will only run once as the first wait period will be replaced by the second wait period. Something like:

Event OnInit()
  RegisterForSingleUpdate(5.0) ;five seconds later
EndEvent

Event OnUpdate()
  ;do stuff
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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