2021-10-05 22:15:58 +00:00
Scriptname _00E_PlayerSetUpScript extends ObjectReference
2021-12-15 06:49:12 +00:00
{Initializes all the necessary Quests, maintains the player, contains various OnPlayerLoadGame() failsafes. This script is important for proper updating, do not overwrite it.}
2021-10-05 22:15:58 +00:00
2021-12-29 21:20:10 +00:00
Float Property CURRENT_PATCH_VERSION = 2.12 AutoReadOnly
2021-10-05 22:59:59 +00:00
2021-10-05 22:15:58 +00:00
;=====================================================================================
; EVENTS
;=====================================================================================
Event OnInit()
2021-12-15 06:49:12 +00:00
If self != (PlayerREF as ObjectReference)
return
EndIf
2021-10-05 22:15:58 +00:00
; needs the IsInMenuMode() check to prevent stuck messages when FS is not loaded
While Utility.IsInMenuMode()
Utility.WaitMenuMode(0.1)
EndWhile
2022-08-01 01:33:22 +00:00
CheckForgottenStories()
2022-08-01 12:43:38 +00:00
_00E_Func_CheckSKSE.Run()
_00E_Func_CheckEnderalDLL.Run()
2021-12-15 06:49:12 +00:00
If fPatchVersion == 0.00
fPatchVersion = CURRENT_PATCH_VERSION
2021-10-05 22:15:58 +00:00
EndIf
2021-12-15 06:49:12 +00:00
GoToState("RealPlayer")
PlayerREF.SetActorValue("speedMult", 95)
PlayerREF.SetActorValue("Healrate", 0)
EnableDisableKillmove()
; Added in 1.5.8.0
; starts all quests that are in the formlist
Int iIndex = QuestsToStart.GetSize()
2021-12-29 21:20:10 +00:00
While iIndex > 0
2021-12-15 06:49:12 +00:00
iIndex -= 1
Quest kQuest = QuestsToStart.GetAt(iIndex) as Quest
kQuest.Start()
endwhile
2021-10-05 22:15:58 +00:00
2022-08-01 00:44:56 +00:00
If Game.GetModByName("Enderal_FS_More_Affinities.esp") != 255
Game.QuitToMainMenu()
Debug.MessageBox("Enderal_FS_More_Affinities.esp is outdated and does not work with Enderal SE. Please, uninstall or update the mod.")
EndIf
2021-10-05 22:15:58 +00:00
EndEvent
Event OnPlayerLoadGame()
If self == (PlayerREF as ObjectReference) ; A check just in case. Most likely this condition is always True
2022-08-01 01:33:22 +00:00
CheckForgottenStories()
2022-08-01 12:43:38 +00:00
_00E_Func_CheckSKSE.Run()
_00E_Func_CheckEnderalDLL.Run()
2021-10-05 22:15:58 +00:00
Maintenance()
If GetState() != "RealPlayer" ; Post-1.2.5.0 version update
GoToState("RealPlayer")
EndIf
EndIf
EndEvent
State RealPlayer
;/ Event OnBeginState()
Debug.Trace(self + ": OnBeginState RealPlayer")
EndEvent /;
EndState
2021-10-05 22:59:59 +00:00
;=====================================================================================
; 2.0.6
;=====================================================================================
Function UpdateMQ12b_206()
2022-07-28 20:04:13 +00:00
_00E_MQ12b_Functions MQ12bFunctions = Game.GetForm(0x2EBAD) as _00E_MQ12b_Functions
2021-10-05 22:59:59 +00:00
Quest MQ15 = Game.GetFormFromFile(0x0002EBB0, "Skyrim.esm") as Quest
2022-07-28 20:04:13 +00:00
If MQ12bFunctions.GetCurrentStageID() >= 135 && MQ15.GetCurrentStageID() < 5
2021-10-05 22:59:59 +00:00
MQ12bFunctions.OldReenableDisabledNPC()
EndIf
EndFunction
;=====================================================================================
; 2.0.8
;=====================================================================================
Function Update_208()
; Obsolete abilities cleanup
_00E_FS_NQ07_Functions FS_NQ07_Quest = Game.GetFormFromFile(0x0001CA09, "Enderal - Forgotten Stories.esm") as _00E_FS_NQ07_Functions
2022-07-28 20:04:13 +00:00
Int iFS_NQ07Stage = FS_NQ07_Quest.GetCurrentStageID()
2021-10-05 22:59:59 +00:00
If iFS_NQ07Stage >= 5 && iFS_NQ07Stage < 410
FS_NQ07_Quest.UpdateAarosCarryTraySpell()
Else
RemoveObsoleteSpell(0x0009A893, "Skyrim.esm", 0x000F649A, "Skyrim.esm")
EndIf
RemoveObsoleteSpell(0x0010D339, "Skyrim.esm", 0x000F649A, "Skyrim.esm")
RemoveObsoleteSpell(0x0006FFAF, "Skyrim.esm", 0x000F6498, "Skyrim.esm")
RemoveObsoleteSpell(0x000F64A0, "Skyrim.esm", 0x000F6498, "Skyrim.esm")
; Refill _00E_AnimTest_SC package arrays where needed
FillAnimTestPackages(0x00137889, "Skyrim.esm", 0x00070657, "Skyrim.esm")
FillAnimTestPackages(0x0013788A, "Skyrim.esm", 0x00070657, "Skyrim.esm")
FillAnimTestPackages(0x0013789F, "Skyrim.esm", 0x00070657, "Skyrim.esm")
FillAnimTestPackages(0x001378A2, "Skyrim.esm", 0x00070657, "Skyrim.esm")
FillAnimTestPackages(0x001378AA, "Skyrim.esm", 0x00070657, "Skyrim.esm")
FillAnimTestPackages(0x001378AB, "Skyrim.esm", 0x00070657, "Skyrim.esm")
FillAnimTestPackages(0x00147E12, "Skyrim.esm", 0x00070657, "Skyrim.esm")
FillAnimTestPackages(0x00147E14, "Skyrim.esm", 0x00070657, "Skyrim.esm")
FillAnimTestPackages(0x0010D336, "Skyrim.esm", 0x00070645, "Skyrim.esm")
FillAnimTestPackages(0x0010D33B, "Skyrim.esm", 0x00070645, "Skyrim.esm")
FillAnimTestPackages(0x00147DEA, "Skyrim.esm", 0x00070645, "Skyrim.esm")
FillAnimTestPackages(0x00147E37, "Skyrim.esm", 0x00070645, "Skyrim.esm")
; "Gypsy minstrels" update
Keyword performSpotKwd = Game.GetFormFromFile(0x000FB905, "Skyrim.esm") as Keyword
(Game.GetFormFromFile(0x00044EBC, "Skyrim.esm") as _00E_BardPlayInstrumentScript).LinkedPlayMarkerKeyword = performSpotKwd
(Game.GetFormFromFile(0x00046D79, "Skyrim.esm") as _00E_GypsyMinstrelsControlScript).UpdateWaypoint()
EndFunction
Function RemoveObsoleteSpell(Int idNPC, String esmNPC, Int idSpell, String esmSpell)
Spell obsoleteSpell = Game.GetFormFromFile(idSpell, esmSpell) as Spell
(Game.GetFormFromFile(idNPC, esmNPC) as Actor).RemoveSpell(obsoleteSpell)
EndFunction
Function FillAnimTestPackages(Int idNPC, String esmNPC, Int idPackage, String esmPackage)
Package newPackage = Game.GetFormFromFile(idPackage, esmPackage) as Package
(Game.GetFormFromFile(idNPC, esmNPC) as _00E_AnimTest_SC).UpdateFillPackages(newPackage)
EndFunction
2021-10-05 22:15:58 +00:00
2021-10-12 02:10:35 +00:00
;=====================================================================================
2021-12-09 20:28:54 +00:00
; 2.0.10
2021-10-12 02:10:35 +00:00
;=====================================================================================
2021-11-29 02:47:56 +00:00
Function Update_210()
2021-10-12 02:10:35 +00:00
Spell abSoulcaller = Game.GetFormFromFile(0x002F0EA, "Enderal - Forgotten Stories.esm") as Spell
If PlayerREF.HasSpell(abSoulcaller)
PlayerREF.RemoveSpell(abSoulcaller)
Utility.Wait(1)
PlayerREF.AddSpell(abSoulcaller, False)
EndIf
Perk perkBloodlust = Game.GetFormFromFile(0x00069D38, "Skyrim.esm") as Perk
_ResetPerk(perkBloodlust)
_00E_PlayerhousingMaster.GetMaster().Update_209()
2021-10-14 08:03:09 +00:00
; Previous versions may have silence tracks stuck
Levelsystem.RemoveSilence()
2021-10-12 02:10:35 +00:00
EndFunction
2021-12-29 21:20:10 +00:00
;=====================================================================================
; 2.0.12
;=====================================================================================
Function Update_212()
2022-07-29 22:05:32 +00:00
PlayerREF.AddPerk(Game.GetFormFromFile(0x14CF8, "Enderal - Forgotten Stories.esm") as Perk) ; _00E_SE_WerewolfBlockFurniturePerk
PlayerREF.AddPerk(Game.GetFormFromFile(0x14CFA, "Enderal - Forgotten Stories.esm") as Perk) ; _00E_SE_DismantlePerk
PlayerREF.AddPerk(Game.GetFormFromFile(0x14CF9, "Enderal - Forgotten Stories.esm") as Perk) ; _00E_SE_2_0_12_UpgradePerk
2021-12-29 21:20:10 +00:00
EndFunction
2021-10-05 22:15:58 +00:00
;=====================================================================================
; ALL UPDATES
;=====================================================================================
Function EnableDisableKillmove()
; it seems like that this ini setting does not do stuff by itself (or it is bugged)
; therefore we need to read it from the file and change the global with which the killmoves are conditioned
2021-12-11 15:36:03 +00:00
If Utility.GetINIBool("bVATSDisable:VATS") == false
2021-10-05 22:15:58 +00:00
KillMove.SetValueInt(1)
2021-12-11 15:36:03 +00:00
Else
KillMove.SetValueInt(0)
2021-10-05 22:15:58 +00:00
EndIf
2021-12-11 15:36:03 +00:00
2021-10-05 22:15:58 +00:00
EndFunction
Function SetAutoSaveInterval()
; updates the autosave interval
_00E_AutoSaveSystem_Functions AutoSaveSystem_Functions = Game.GetFormFromFile(0x00048141, "Skyrim.esm") as _00E_AutoSaveSystem_Functions
AutoSaveSystem_Functions.UpdateAutoSaveInterval()
EndFunction
Function FailsafeMQ05PrologueAliases()
; failsafe for issue 1536, fills empty aliases
If MQ05PrologueFunctions == None
2021-12-29 21:20:10 +00:00
MQ05PrologueFunctions = Game.GetForm(0x00033A5B) as _00E_MQ05Prologue_Functions
2021-10-05 22:15:58 +00:00
EndIf
MQ05PrologueFunctions.FillEmptyAliasesFailsafe()
EndFunction
Function RefreshMountNamesOnLoad()
2022-07-29 22:05:32 +00:00
_00E_NQ06_Functions NQ06Functions = Game.GetForm(0x725BA) as _00E_NQ06_Functions
2021-10-05 22:15:58 +00:00
NQ06Functions.RefreshNamesOnSaveLoad()
EndFunction
2021-10-12 02:10:35 +00:00
Function _ResetPerk(Perk p)
If PlayerREF.HasPerk(p)
PlayerREF.RemovePerk(p)
PlayerREF.AddPerk(p)
2021-10-05 22:59:59 +00:00
EndIf
EndFunction
Function ResetArmorWeightPerks()
; Perks modifying armor weights need some push on each game load to work.
; The push is needed only if the player is over-encumbered on game load.
; If the player is not over-encumbered, the push is not needed because checking the inventory, picking up items, sheathing/drawing a weapon will reset the perks anyway.
If PlayerREF.IsOverEncumbered()
2021-10-12 02:10:35 +00:00
_ResetPerk(_00E_Class_Keeper_P05_C_Conditioning)
_ResetPerk(_00E_Class_Vagrant_P05_B_Lightweight)
2021-10-05 22:59:59 +00:00
EndIf
EndFunction
2021-10-05 22:15:58 +00:00
;=====================================================================================
; MAINTENANCE
;=====================================================================================
2022-08-01 01:33:22 +00:00
function CheckForgottenStories()
; If Enderal - Forgotten Stories.esm is not loaded, kick the player back to main menu
if (Game.GetForm(0x4320E) as GlobalVariable).GetValue() as Int != 1
Utility.wait(2.0)
Game.QuitToMainMenu()
Debug.MessageBox("Enderal - Forgotten Stories.esm is not loaded! The game will not run properly. Open Data Files and enable it.")
return
EndIf
endfunction
2021-10-05 22:15:58 +00:00
Function Maintenance()
2022-07-29 22:05:32 +00:00
if fPatchVersion <= 1.62
2021-11-29 02:47:56 +00:00
Debug.MessageBox("A savegame was loaded which was made before the release of Enderal SE. In this save, several new features won't be available and there is a chance that you'll encounter grave bugs. Please, start a new game.")
Game.QuitToMainMenu()
return
endif
if fPatchVersion < CURRENT_PATCH_VERSION
2021-10-05 22:59:59 +00:00
If fPatchVersion < 2.06
UpdateMQ12b_206()
EndIf
If fPatchVersion < 2.08
Update_208()
EndIf
2021-11-29 02:47:56 +00:00
If fPatchVersion < 2.10
Update_210()
2021-10-12 02:10:35 +00:00
EndIf
2021-12-29 21:20:10 +00:00
If fPatchVersion < 2.12
Update_212()
EndIf
2021-10-05 22:59:59 +00:00
fPatchVersion = CURRENT_PATCH_VERSION
2021-11-29 02:47:56 +00:00
endif
2021-10-05 22:15:58 +00:00
; changes to the actor value healrate will not persist in consecutive saves
; every time a save gets loaded the healrate needs to be set to 0, otherwise it will go back again to default at 0.7
; this is called before active magic effects of potions or spells are applied to the player which could also alter the value
PlayerREF.SetActorValue("Healrate", 0)
2021-12-29 21:20:10 +00:00
; Workaround for broken physics on loading saves, made on a mount
If PlayerREF.IsOnMount()
PlayerREF.Dismount()
EndIf
2021-10-05 22:15:58 +00:00
EnableDisableKillmove()
2021-10-05 22:59:59 +00:00
ResetArmorWeightPerks()
2021-12-29 21:20:10 +00:00
2021-10-05 22:15:58 +00:00
SetAutoSaveInterval()
FailsafeMQ05PrologueAliases()
RefreshMountNamesOnLoad()
2021-12-04 01:30:32 +00:00
2022-08-01 00:44:56 +00:00
SendModEvent("Enderal_GameLoaded")
2021-10-05 22:15:58 +00:00
EndFunction
;=====================================================================================
; PROPERTIES
;=====================================================================================
float fPatchVersion
_00E_MQ05Prologue_Functions Property MQ05PrologueFunctions Auto
Actor Property PlayerREF Auto
FormList Property QuestsToStart Auto
2021-10-05 22:59:59 +00:00
GlobalVariable Property KillMove Auto
Perk Property _00E_Class_Keeper_P05_C_Conditioning Auto
Perk Property _00E_Class_Vagrant_P05_B_Lightweight Auto
2021-10-14 08:03:09 +00:00
_00E_QuestFunctions Property Levelsystem Auto