Jump to content

Papyrus Scripting and Enabling Quest Alias References.


Recommended Posts

I apologize in advance if I am totally overlooking something or unaware of a broken rule I am violating, I am far from a Papyrus Skyrim coding expert and barely a novice. Okay, so this is the setup;

 

I have a quest. The quest is triggered and one of the reference aliases, an NPC, is spawned at a location. Okay, fine.

 

I select “Initially Disabled” for the NPC, so they’re created when the quest runs, but they’re initially disabled. We’ll enable them later.

 

This is how we’ll enable them; We have a very simple script that runs an OnInit, placed in the Quest scripts section. It runs when the Quest runs.

 

After a period of time with a single update event, we Enable the NPC the Quest created.

 

Seems simple, I have some things working, but the NPC still won’t be enabled.

 

Scriptname Sin7War_TimedEnable5 extends Quest

ReferenceAlias property myAlias auto

ObjectReference property SelfRef auto

 

Event OnInit()

Debug.Notification("OnInit Event activated.")

myAlias.ForceRefTo(SelfRef)

RegisterForSingleUpdate(120.0)

EndEvent

 

Event OnUpdate()

Debug.Notification("Event OnUpdate activated..")

SelfRef.Enable()

EndEvent

 

Note, earlier I tried to DIRECTLY enable the NPC Ref alias in the quest. Apparently you cannot do that? For example, this stated earlier line gives the compiler fits; myAlias.Enable(), it gives me: Enable is not a function or does not exist.

 

Okay, so we can’t Enable the refAlias directly. It seems to only work on ObjectReferences. So I look around, I find ForceRefTo and try to shove the reference into that created ObjectReference holder, so I can actually enable the script.

 

That compiles. I of course go to the Quest section, properties for the script, and fill in the property for ReferenceAlias myAlias (The NPC), while keeping ObjectReference SelfRef default and unfilled. It runs in Skyrim, I get both ^ of my debug notifications. NPC still does not enable. So I assume the reference is not being put into SelfRef.

 

I am at a loss. How can I enable an NPC initially disabled by the quest? I can’t point at it in the Cell Window, because of course it is not created yet. I have to use the reference set up by the quest, but I get “Enable is not a function or does not exist” with everything except ObjectReference.

 

Bonus Question: Is there a little snippet of code that allows me to generate a random number between two values? If I can somehow get my above script attempt to work, I’d like to use a random value between two sets of numbers for my SingleUpdate.

 

Thank you in advance for taking the time to read this, even if you don't have an answer.

Link to comment
Share on other sites

Thank you, this seems to have put everything in working order! The end result from your aid;

 

Scriptname Sin7War_TimedEnable5 extends Quest

ReferenceAlias property myAlias auto
Event OnInit()
;Debug.Notification("OnInit Event activated.")
int random = Utility.RandomInt(120, 1200)
RegisterForSingleUpdate(random)
EndEvent
Event OnUpdate()
;Debug.Notification("Event OnUpdate activated..")
myAlias.GetActorReference().Enable()
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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