Difference between revisions of "OnPlayerLoadGame - Actor"

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search
imported>Qazaaq
(The notes about the 1.5 patch and remote event declaration are inaccurate.)
imported>Qazaaq
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{Template:Inaccurate Article}}
[[Category:Scripting]]
[[Category:Papyrus]]
[[Category:Events]]
'''Member of:''' [[Actor Script]]
'''Member of:''' [[Actor Script]]


Line 12: Line 8:
</source>
</source>


After Patch 1.5:
== Parameters ==
None
 
== Examples ==
The player is unique in that it is almost always bad practice to modify the [[Actor]] form directly.
This is due to compatibily reasons concerning ''The Rule of One''.
There are several techniques to avoid violating this rule.
 
=== Example ===
This example is straight forward but violates ''The Rule of One'' because it requires the player [[Actor]] to be modified.
<source lang="papyrus">
<source lang="papyrus">
Event Actor.OnPlayerLoadGame(actor aSender)
Scriptname Example extends Actor
 
Event OnPlayerLoadGame()
    Debug.TraceSelf(self, "OnPlayerLoadGame", "The player actor has reloaded the game.")
EndEvent
</source>
</source>


== Parameters ==
*aSender: The actor sending the event.


== Examples ==
=== Alternative ===
A [[ReferenceAlias Script|ReferenceAlias]] or [[ActiveMagicEffect Script|ActiveMagicEffect]] will receive events from the [[Actor]] they are attached to.
 
 
'''A quest alias pointed at the player'''
<source lang="papyrus">
Scriptname Example extends ReferenceAlias
 
Event OnPlayerLoadGame()
    Debug.TraceSelf(self, "OnPlayerLoadGame", "The player actor has reloaded the game.")
EndEvent
</source>
 
 
'''A magic effect on the player'''
<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
Scriptname Example extends ActiveMagicEffect
 
Event OnPlayerLoadGame()
Event OnPlayerLoadGame()
  Debug.Trace("player loaded a save, do some fancy stuff")
    Debug.TraceSelf(self, "OnPlayerLoadGame", "The player actor has reloaded the game.")
endEvent
EndEvent
</source>
</source>


After Patch 1.5:
 
=== Remoting ===
With [[Remote Papyrus Event Registration]], this event may also be handled from ''any'' script object.  
<source lang="papyrus">
<source lang="papyrus">
;This event is on a quest (like HC_ManagerScript)
Scriptname Example extends ScriptObject
Event Actor.OnPlayerLoadGame(actor aSender)
 
  Debug.Trace("player loaded a save, do some fancy stuff")
Event OnInit()
if false == Game.GetPlayer().HasPerk(myCoolPerk) ; Let's check to see if the player has the cool new perk.
    RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerLoadGame")
Game.GetPlayer().AddPerk(myCoolPerk) ; If they don't, then add it.
    Debug.TraceSelf(self, "Actor.OnPlayerLoadGame", "This script has initialized and is now listening for the 'OnPlayerLoadGame' event.")
Debug.Trace("Player now has" +myCoolPerk)
EndEvent
endif
 
endEvent
Event Actor.OnPlayerLoadGame(Actor akSender)
    Debug.TraceSelf(self, "Actor.OnPlayerLoadGame", "The player actor has reloaded.")
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 will fire for the '''first time''' on the next load. See also ''OnInit''.
*After Patch 1.5, event is also handled via quest.
*This event will fire for the '''first time''' on the next load.


== See Also ==
== See Also ==
*[[Actor Script]]
*[[Actor]]
*[[OnInit - ScriptObject]]
*[[ReferenceAlias Script]]
*[[ActiveMagicEffect Script]]
*[[Remote Papyrus Event Registration]]
 
 
[[Category:Scripting]]
[[Category:Papyrus]]
[[Category:Events]]

Latest revision as of 13:16, 2 December 2018

Member of: Actor Script

Event called when the player loads a save game. This event is only sent to the player actor.

Syntax[edit | edit source]

Event OnPlayerLoadGame()

Parameters[edit | edit source]

None

Examples[edit | edit source]

The player is unique in that it is almost always bad practice to modify the Actor form directly. This is due to compatibily reasons concerning The Rule of One. There are several techniques to avoid violating this rule.

Example[edit | edit source]

This example is straight forward but violates The Rule of One because it requires the player Actor to be modified.

Scriptname Example extends Actor

Event OnPlayerLoadGame()
    Debug.TraceSelf(self, "OnPlayerLoadGame", "The player actor has reloaded the game.")
EndEvent


Alternative[edit | edit source]

A ReferenceAlias or ActiveMagicEffect will receive events from the Actor they are attached to.


A quest alias pointed at the player

Scriptname Example extends ReferenceAlias

Event OnPlayerLoadGame()
    Debug.TraceSelf(self, "OnPlayerLoadGame", "The player actor has reloaded the game.")
EndEvent


A magic effect on the player

Scriptname Example extends ActiveMagicEffect

Event OnPlayerLoadGame()
    Debug.TraceSelf(self, "OnPlayerLoadGame", "The player actor has reloaded the game.")
EndEvent


Remoting[edit | edit source]

With Remote Papyrus Event Registration, this event may also be handled from any script object.

Scriptname Example extends ScriptObject

Event OnInit()
    RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerLoadGame")
    Debug.TraceSelf(self, "Actor.OnPlayerLoadGame", "This script has initialized and is now listening for the 'OnPlayerLoadGame' event.")
EndEvent

Event Actor.OnPlayerLoadGame(Actor akSender)
    Debug.TraceSelf(self, "Actor.OnPlayerLoadGame", "The player actor has reloaded.")
EndEvent


Notes[edit | edit source]

  • This event will fire for the first time on the next load. See also OnInit.

See Also[edit | edit source]