Difference between revisions of "OnPlayerLoadGame - Actor"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>JustinOther
(→‎Examples: Worth mentioning the GlobalVariable needs to be left valueless in the editor)
imported>Antares
m (→‎Notes: Whoops, formatting)
 
(6 intermediate revisions by 2 users not shown)
Line 15: Line 15:


== Examples ==
== Examples ==
*Syntax
*Normal use
<source lang="papyrus">
<source lang="papyrus">
; Event is only sent to the player actor. This would probably be on a magic effect or alias script
; Event is only sent to the player actor. This would probably be on a magic effect or alias script
Line 22: Line 22:
endEvent
endEvent
</source>
</source>
*Say you need something to happen '''exactly''' once every time a save is loaded ''including'' the first and you're using a ReferenceAlias filled with the Player. In the below example with a "Start Game Enabled" quest, we maintain a GlobalVariable (valueless in editor) such that it will invariably reflect the version loaded. Use an OnInit event in the quest's script to catch the first save load...
*Do something exactly once per save load
Say you need something to happen '''exactly''' once every time a save is loaded ''including'' the first and you're using a ReferenceAlias filled with the Player. In the below example with a quest flagged as "Start Game Enabled" and set to "Run Once" from within its [[Quest Data Tab]], we maintain a Float Property (valueless in editor) such that it will invariably reflect the version loaded. Use an [[OnInit]] event in the quest's script to catch the first save load...
<source lang="papyrus">ScriptName YourQuestScript extends Quest
<source lang="papyrus">ScriptName YourQuestScript extends Quest
   
   
GlobalVariable Property fYourModVersionGLOB Auto ; This will not reset in the the quest does and...
Float Property fYourModVersion Auto


Event OnInit()
Event OnInit()
If !fYourModVersionGLOB.GetValue() ; ...the global can be used as a DoOnce to prevent OnInit from firing twice
Maintenance()
fYourModVersionGLOB.SetValue(-1)
Maintenance()
EndIf
EndEvent
EndEvent
   
   
Function Maintenance()
Function Maintenance()
If fYourModVersionGLOB.GetValue() < 1.23 ; Current version
If fYourModVersion < 1.23 ; Current version
If fYourModVersionGLOB.GetValue() == -1
If fYourModVersion
Debug.Trace("Updating from version " + fYourModVersion)
Else
Debug.Trace("Initializing for the first time.")
Debug.Trace("Initializing for the first time.")
Else
Debug.Trace("Updating from version " + fYourModVersionGLOB.GetValue())
EndIf
EndIf
fVersion = 1.23
fYourModVersion = 1.23
EndIf
EndIf
EndFunction</source>
EndFunction</source>
...and your player alias' OnPlayerLoadGame event to catch each consecutive save load...
...and use your player alias' OnPlayerLoadGame event to catch each consecutive save load.
<source lang="papyrus">ScriptName YourPlayerAliasScript extends ReferenceAlias
<source lang="papyrus">ScriptName YourPlayerAliasScript extends ReferenceAlias
   
   
Line 51: Line 49:
Event OnPlayerLoadGame()
Event OnPlayerLoadGame()
QuestScript.Maintenance()
QuestScript.Maintenance()
EndEvent
EndEvent</source>
</source>


== Notes ==
== Notes ==
This event is only sent to the player actor. It is recommended that you handle this event via an alias the player is forced into, or a magic effect on the player.
This event is only sent to the player actor. It is recommended that you handle this event via an alias the player is forced into, or a magic effect on the player.<BR>
This event will not be sent when starting a new game. See the discussion page for more information.


== See Also ==
== See Also ==
*[[Actor Script]]
*[[Actor Script]]

Latest revision as of 10:00, 26 December 2012

Member of: Actor Script (Requires 1.6)

Event called when the player loads a save game. This event is only sent to the player actor. If this is the first save game load where the event is being listened to, and the event is on an alias, and the alias didn't exist at the time the save was made, then the player won't be in the alias by the time the event is sent, and the alias script will not receive the event. It should then receive later events.

Syntax[edit | edit source]

Event OnPlayerLoadGame()

Parameters[edit | edit source]

None.

Examples[edit | edit source]

  • Normal use
; Event is only sent to the player actor. This would probably be on a magic effect or alias script
Event OnPlayerLoadGame()
  Debug.Trace("player loaded a save, do some fancy stuff")
endEvent
  • Do something exactly once per save load

Say you need something to happen exactly once every time a save is loaded including the first and you're using a ReferenceAlias filled with the Player. In the below example with a quest flagged as "Start Game Enabled" and set to "Run Once" from within its Quest Data Tab, we maintain a Float Property (valueless in editor) such that it will invariably reflect the version loaded. Use an OnInit event in the quest's script to catch the first save load...

ScriptName YourQuestScript extends Quest
 
Float Property fYourModVersion Auto

Event OnInit()
	Maintenance()
EndEvent
 
Function Maintenance()
	If fYourModVersion < 1.23 ; Current version
		If fYourModVersion
			Debug.Trace("Updating from version " + fYourModVersion)
		Else
			Debug.Trace("Initializing for the first time.")
		EndIf
		fYourModVersion = 1.23
	EndIf
EndFunction

...and use your player alias' OnPlayerLoadGame event to catch each consecutive save load.

ScriptName YourPlayerAliasScript extends ReferenceAlias
 
YourQuestScript Property QuestScript Auto

Event OnPlayerLoadGame()
	QuestScript.Maintenance()
EndEvent

Notes[edit | edit source]

This event is only sent to the player actor. It is recommended that you handle this event via an alias the player is forced into, or a magic effect on the player.
This event will not be sent when starting a new game. See the discussion page for more information.

See Also[edit | edit source]