Jump to content

Running script on load


Recommended Posts

So this little piece of code exists on the wiki that appears to be what I was looking for:

ScriptName YourQuestScript extends Quest
 
Float fVersion
 
Event OnInit()
	Maintenance() ; OnPlayerLoadGame will not fire the first time
EndEvent
 
Function Maintenance()
	If fVersion < 1.01 ; <--- Edit this value when updating
		fVersion = 1.01 ; and this
		Debug.Notification("Now running YourModName version: " + fVersion)
		; Update Code
	EndIf
	; Other maintenance code that only needs to run once per save load
EndFunction

;******************************************************

ScriptName YourPlayerAliasScript extends ReferenceAlias
 
YourQuestScript Property QuestScript Auto
 
Event OnPlayerLoadGame()
	QuestScript.Maintenance()
EndEvent

The first bit is self explanatory and just works. It's the second bit that gets me. I assume I need to make an alias for the player and attach the script to that alias? If so, anybody wanna be a peach and hold my hand while walking me through exactly how that is done?

 

Quest Aliases tab > right click > New Reference Alias > Give it a name > select Unique > Player?

 

Is that right? How do I then attach the script to the alias?

 

Any assistance is appreciated.

Link to comment
Share on other sites

I assume I need to make an alias for the player and attach the script to that alias?

 

OnPlayerLoadGame() is sent by the actor reference of the player (RefID: 00000014).

 

So, if the reference alias points at the player, then this event is received by the reference alias script without registration.

Event OnPlayerLoadGame()
	QuestScript.Maintenance()
EndEvent

However, if you don't want to make a quest alias for the player, you can register for this event in the reference alias or the quest script:

ScriptName YourQuestScript extends Quest

YourQuestScript Property QuestScript Auto


Event OnInit()
	Utility.Wait(0.5)
	RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerLoadGame")
EndEvent

Event Actor.OnPlayerLoadGame(Actor akSender)
	QuestScript.Maintenance()
EndEvent

Quest Aliases tab > right click > New Reference Alias > Give it a name > select Unique > Player?

 

Yes, that'd make a quest alias for the player.

 

How do I then attach the script to the alias?

 

Quest Aliases tab > right click > New Reference Alias > Give it a name > select Unique > Player >> Click OK to exit the window "Reference Alias" >> Click OK to exit the window "Quest: [your quest name]". Then reopen the player's quest alias >> Papyrus Scripts >> Add >> New Script.

Edited by LarannKiar
Link to comment
Share on other sites

  • Recently Browsing   0 members

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