MSFD Detecting when the player does a load from saved game
Some reasons to test for player loading a saved game:
1) To continue custom music (mp3 type music resets on load).
2) To keep a NPC running or sneaking.
3) To reset an object to its proper scale (if outside of range 0.5 to 2.0).
There are a number of ways to do this:
JOG proposed the use of SetJournalIndex:
if ( ( getjournalindex "dummy" ) != 100 )
Messagebox "You just reloaded, Cheater!!!"
setjournalindex "dummy" 100
endif
"Dummy" is any journal-topic that has no text for index 100.
Setjournalindex will set the index to the new value, no matter if an entry exists for this value or not, but when you reload, the index will be reset (see SetJournalIndex for more information).
MentalElf suggested that GetForceRun, GetForceSneak, GetScale can all be used to detect when the player has just loaded a save game. This is due to ForceRun and ForceSneak being cleared during a load from saved game, and scale is set to within the range 0.5 to 2.0. In my opinion ForceRun is best, as ForceSneak puts the NPC into a crouch posture.
; (NPC object)
if ( GetForceRun == 0 )
; Player just loaded a saved game
; Handle game load here.
ForceRun
Endif
A different option is to use start scripts ( available only with Tribunal and Bloodmoon): Here are two examples by Dinkum Thinkum:
begin DT_DoOnce_TribStartScript02
;script to demonstrate a 'DoOnce' Tribunal Start Script that runs once
; each time a saved game is loaded with the mod enabled
;by DinkumThinkum
;script executes 'Do Once' code section once
; each time the mod is loaded as part of a game
;start of 'Do Once' code to be run each time a saved game is loaded with this mod enabled.
MessageBox, "You will see this message everytime you load a saved game with this mod enabled.", "OK"
;end of 'Do Once' code.
StopScript DT_DoOnce_TribStartScript02
end DT_DoOnce_TribStartScript02
begin DT_DoOnce_TribStartScript01
;script to demonstrate a 'DoOnce' Tribunal Start Script
; by DinkumThinkum
;script executes 'Do Once' code section once, when the mod is loaded
; with a saved game that does not include the mod (or with a new game)
;script executes 'Reload' code section once, each time a save game
; made with the mod is reloaded with the mod enabled
;either code section can be omitted, but all the control structures will still be needed
;Note: BOTH 'StopScripts' are necessary. Trust me...
;DT_DoOnce_TSS01 - Global variable, won't be reset by StopScript (initialized to 0)
if ( DT_DoOnce_TSS01 == 1 )
;start of 'Reload' code, to be run once each time mod is reloaded
MessageBox, "You have loaded this mod with a saved game made with the mod enabled.", "OK"
;end of 'Reload' code
StopScript DT_DoOnce_TribStartScript01
Return
endif
;start of 'Do Once' code, to be run only when the mod is first loaded.
MessageBox, "You have loaded this mod with a saved game that was made without this mod enabled.", "OK"
;end of 'Do Once' code.
set DT_DoOnce_TSS01 to 1
StopScript DT_DoOnce_TribStartScript01
end DT_DoOnce_TribStartScript01