Moved disabling NPCs in MQ12b to a separate quest to avoid locking MQ12b

This commit is contained in:
Eddoursul 2024-02-21 17:00:29 +01:00
parent 50ec2d17aa
commit fe9971362f
21 changed files with 153 additions and 173 deletions

BIN
Separate NPC disabler.esp Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,111 @@
Scriptname _00E_MQ12b_NPCControl extends Quest Hidden
; 2.1, Eddoursul: Moved disabling NPCs to a separate quest
Actor[] RegisteredDisabledNPCs
Int nRegisteredDisabledNPCs
Bool bDisabledNPCsLocked
Actor[] RegisteredGhostedNPCs
Int nRegisteredGhostedNPCs
Bool bGhostedNPCsLocked
function OnInit()
RegisteredDisabledNPCs = New Actor[128]
nRegisteredDisabledNPCs = 0
RegisteredGhostedNPCs = New Actor[128]
nRegisteredGhostedNPCs = 0
endfunction
; Queue an NPC
Function PrepareNPC(Actor akMoveActor, Bool bOnlyGhost = False)
If MQ12b.bArkUnderAttackPrelude == False
Return
EndIf
; Validate akMoveActor, could receive "nullptr form" instead of a valid actor from the packages
If akMoveActor == None || akMoveActor.GetActorBase() == None
Return
EndIf
If bOnlyGhost == False && RegisteredDisabledNPCs.Find(akMoveActor) < 0
If akMoveActor.IsDisabled()
Return
EndIf
if SKSE.GetVersion()
if akMoveActor.GetEnableParent() == None
akMoveActor.DisableNoWait()
_RegisterDisabledNPC(akMoveActor)
return
endif
else
akMoveActor.Disable()
if akMoveActor.IsDisabled()
_RegisterDisabledNPC(akMoveActor)
return
endif
endif
EndIf
If RegisteredGhostedNPCs.Find(akMoveActor) < 0 && akMoveActor.IsGhost() == False && ! akMoveActor.IsDisabled()
akMoveActor.SetGhost(True)
_RegisterGhostedNPC(akMoveActor)
EndIf
EndFunction
Function _RegisterDisabledNPC(Actor akMoveActor)
if nRegisteredDisabledNPCs + 1 <= 128
RegisteredDisabledNPCs[nRegisteredDisabledNPCs] = akMoveActor
nRegisteredDisabledNPCs += 1
Debug.Trace("Registered disabled " + akMoveActor.GetBaseObject().GetName() + " " + (akMoveActor as String))
else
; Added overflow to the ghosted
_RegisterGhostedNPC(akMoveActor)
endif
EndFunction
Function _RegisterGhostedNPC(Actor akMoveActor)
if nRegisteredGhostedNPCs + 1 <= 128
RegisteredGhostedNPCs[nRegisteredGhostedNPCs] = akMoveActor
nRegisteredGhostedNPCs += 1
Debug.Trace("Registered ghosted " + akMoveActor.GetBaseObject().GetName() + " " + (akMoveActor as String))
else
; oh well
endif
EndFunction
Function ReEnableNPCs()
MQ12b.bArkUnderAttackPrelude = false
bool bSKSE = SKSE.GetVersion() as bool
int Index = RegisteredDisabledNPCs.length
While Index > 0
Index -= 1
Actor akActor = RegisteredDisabledNPCs[Index]
if akActor != None && ( ! bSKSE || akActor.GetEnableParent() == None )
akActor.EnableNoWait()
Debug.Trace("Re-enabled: " + akActor.GetActorBase().GetName())
RegisteredDisabledNPCs[Index] = None
endif
EndWhile
RegisteredDisabledNPCs = New Actor[1]
Index = RegisteredGhostedNPCs.length
While Index > 0
Index -= 1
Actor akActor = RegisteredGhostedNPCs[Index]
if akActor != None
if akActor.IsDisabled() && ( ! bSKSE || akActor.GetEnableParent() == None )
akActor.EnableNoWait()
endif
akActor.SetGhost(False)
Debug.Trace("Unghosted: " + akActor.GetActorBase().GetName())
RegisteredGhostedNPCs[Index] = None
endif
EndWhile
RegisteredGhostedNPCs = New Actor[1]
EndFunction
_00E_MQ12b_Functions Property MQ12b Auto

View File

@ -2,148 +2,17 @@ Scriptname _00E_MQ12b_Functions extends Quest Conditional
Import Utility
;=====================================================================================
; GENERAL FUNCTIONS
;=====================================================================================
Int CurScriptVersion = 0
Int Property LATEST_SCRIPT_VERSION = 2 AutoReadOnly
Actor[] RegisteredDisabledNPCs
Int nRegisteredDisabledNPCs
Bool bDisabledNPCsLocked
Actor[] RegisteredGhostedNPCs
Int nRegisteredGhostedNPCs
Bool bGhostedNPCsLocked
Function PrepareNPC(Actor akMoveActor, Bool bOnlyGhost = False)
If bArkUnderAttackPrelude == False
Return
EndIf
; Validate akMoveActor, could receive "nullptr form" instead of a valid actor from the packages
If akMoveActor == None || akMoveActor.GetActorBase() == None
Return
EndIf
If akMoveActor.IsDisabled()
Return
EndIf
If bOnlyGhost == False && akMoveActor.GetEnableParent() == None
akMoveActor.Disable()
_RegisterDisabledNPC(akMoveActor)
Return
EndIf
If akMoveActor.IsGhost() == False
akMoveActor.SetGhost(True)
_RegisterGhostedNPC(akMoveActor)
Return
EndIf
EndFunction
Function _RegisterDisabledNPC(Actor akMoveActor)
While bDisabledNPCsLocked
Utility.WaitMenuMode(0.1)
EndWhile
bDisabledNPCsLocked = True
If RegisteredDisabledNPCs.Length == 0 ; Version update
RegisteredDisabledNPCs = New Actor[128]
nRegisteredDisabledNPCs = 0
EndIf
If RegisteredDisabledNPCs.Find(akMoveActor) < 0
If nRegisteredDisabledNPCs >= RegisteredDisabledNPCs.Length
Debug.Notification("MQ12b has problems: reached the limit of stored disabled NPCs")
Else
RegisteredDisabledNPCs[nRegisteredDisabledNPCs] = akMoveActor
nRegisteredDisabledNPCs += 1
EndIf
EndIf
bDisabledNPCsLocked = False
EndFunction
Function _RegisterGhostedNPC(Actor akMoveActor)
While bGhostedNPCsLocked
Utility.WaitMenuMode(0.1)
EndWhile
bGhostedNPCsLocked = True
If RegisteredGhostedNPCs.Length == 0 ; Version update
RegisteredGhostedNPCs = New Actor[128]
nRegisteredGhostedNPCs = 0
EndIf
If RegisteredGhostedNPCs.Find(akMoveActor) < 0
If nRegisteredGhostedNPCs >= RegisteredGhostedNPCs.Length
Debug.Notification("MQ12b has problems: reached the limit of stored ghosted NPCs")
Else
RegisteredGhostedNPCs[nRegisteredGhostedNPCs] = akMoveActor
nRegisteredGhostedNPCs += 1
EndIf
EndIf
bGhostedNPCsLocked = False
EndFunction
Function ReEnableNPCs()
Int Index
ObjectReference ref
Index = 0
While Index < nRegisteredDisabledNPCs
RegisteredDisabledNPCs[Index].EnableNoWait()
RegisteredDisabledNPCs[Index] = None
Index += 1
EndWhile
RegisteredDisabledNPCs = New Actor[1]
Index = 0
While Index < nRegisteredGhostedNPCs
RegisteredGhostedNPCs[Index].SetGhost(False)
RegisteredGhostedNPCs[Index] = None
Index += 1
EndWhile
RegisteredGhostedNPCs = New Actor[1]
; Old ways of enabling NPCs, for backward compatibility
OldReenableDisabledNPC()
If CurScriptVersion == 0
_00E_Func_ReferenceFormList.Enable(MQ12b_SC11_NPCsRef)
MQ12b_SiegeNPCs.Revert()
OldRemoveGhostFlag()
EndIf
EndFunction
Function OldReenableDisabledNPC() ; For version updates with CurScriptVersion < 2
If CurScriptVersion < 2
_00E_Func_ReferenceFormList.Enable(MQ12b_AllDisabledNPCs)
EndIf
EndFunction
Function OldRemoveGhostFlag() ; For version updates with CurScriptVersion == 0
If CurScriptVersion == 0 && Self.IsCompleted() == 1
int Index = MQ12b_UnGhostNPCs_OnVersionUpdate1580.GetSize()
While Index > 0
Index -= 1
(MQ12b_UnGhostNPCs_OnVersionUpdate1580.GetAt(Index) as Actor).SetGhost(False)
EndWhile
EndIf
EndFunction
;=====================================================================================
; FUNCTIONS
;=====================================================================================
Function SetUp()
CurScriptVersion = LATEST_SCRIPT_VERSION
iCrimeGoldBeforeMQ12bNonViolent = A_CrimeFaction.GetCrimeGoldNonViolent()
iCrimeGoldBeforeMQ12bViolent = A_CrimeFaction.GetCrimeGoldViolent()
@ -168,12 +37,6 @@ Function SetUp()
Ordenshueter.GetReference().MoveTo(MQ12b_SC1_Orderguard01)
Ordenshueterin.GetReference().MoveTo(MQ12b_SC1_Orderguard02)
CurScriptVersion = LATEST_SCRIPT_VERSION
RegisteredDisabledNPCs = New Actor[128]
nRegisteredDisabledNPCs = 0
RegisteredGhostedNPCs = New Actor[128]
nRegisteredGhostedNPCs = 0
bArkUnderAttackPrelude = True
SkyrimOvercastRain.SetActive(True)
@ -462,6 +325,8 @@ EndFunction
Function StartSC07()
bArkUnderAttackPrelude = False ; stop disabling NPCs
_00E_Func_SetNPCAsCompanion.SetNPCAsCompanion(_00E_MC_TealorREF, False)
SetObjectiveCompleted(10)
@ -918,7 +783,7 @@ Function CompleteQuestAndStartMQ12c()
MQ12b_SC6_NehrimeseGateLinker.Disable()
Ark_MyradRef.MoveToMyEditorLocation()
MQ12b_DisableThisDudeHeIsAnnoyingREF.Enable()
bArkUnderAttackPrelude = False
bArkUnderAttackPrelude = False ; also disabled earlier in StartSC07()
bArkUnderAttack = False
bArkUnderAttackFinalScene = False
Weather.ReleaseOverride()
@ -935,14 +800,15 @@ Function CompleteQuestAndStartMQ12c()
_00E_EPHandler.GiveEP(__Config_RewardEXP)
AllowIdleChatter.SetValue(1)
Self.CompleteQuest()
ReEnableNPCs()
DisablePanicTriggerbox()
MQ12c.SetCurrentStageID(5)
GoToState("Aftermath")
RegisterForSingleUpdateGameTime(24)
Steam.UnlockAchievement("END_SIEGE_01")
SiegeNPCControl.ReEnableNPCs()
EndFunction
Function DisablePanicTriggerbox() ;extra function because it gets also called from _00E_PlayerSetUpScript
@ -977,22 +843,23 @@ EndFunction
State WaitForNight
Event OnBeginState()
Event OnBeginState()
TimeScale.SetValue(100)
RegisterForSingleUpdate(5)
EndEvent
Event OnUpdate()
If (GameHour.GetValue() <= 4 || GameHour.GetValue() >= 21)
TimeScale.SetValue(0.1)
Else
TimeScale.SetValue(100)
RegisterForSingleUpdate(5)
EndIf
EndEvent
EndEvent
Event OnUpdate()
If (GameHour.GetValue() <= 4 || GameHour.GetValue() >= 21)
TimeScale.SetValue(0.1)
GoToState("")
Else
RegisterForSingleUpdate(5)
EndIf
EndEvent
EndState
@ -1305,3 +1172,5 @@ EffectShader Property BerserkerFXS Auto
_00E_GypsyMinstrelsControlScript Property GypsyMinstrelsControl Auto
Perk Property _00E_ArkSiegeLockedGatesPerk Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto

View File

@ -5,11 +5,11 @@ Scriptname PF_MQ12b_SC11_StayPutScript_0013390A Extends Package Hidden
;BEGIN FRAGMENT Fragment_0
Function Fragment_0(Actor akActor)
;BEGIN CODE
MQ12b.PrepareNPC(akActor, True)
SiegeNPCControl.PrepareNPC(akActor, True)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
_00E_MQ12b_Functions Property MQ12b Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto

View File

@ -5,12 +5,12 @@ Scriptname PF_MQ12b_SC3_GenericCitizenF_0011B0C8 Extends Package Hidden
;BEGIN FRAGMENT Fragment_0
Function Fragment_0(Actor akActor)
;BEGIN CODE
MQ12b.PrepareNPC(akActor, True)
SiegeNPCControl.PrepareNPC(akActor, True)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
_00E_MQ12b_Functions Property MQ12b Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto

View File

@ -5,11 +5,11 @@ Scriptname PF_MQ12b_SC3_GuardFleePkg_0011B0CC Extends Package Hidden
;BEGIN FRAGMENT Fragment_0
Function Fragment_0(Actor akActor)
;BEGIN CODE
MQ12b.PrepareNPC(akActor, True)
SiegeNPCControl.PrepareNPC(akActor, True)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
_00E_MQ12b_Functions Property MQ12b Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto

View File

@ -5,11 +5,11 @@ Scriptname PF_MQ12b_SC3_NormalCitizenCh_00046F24 Extends Package Hidden
;BEGIN FRAGMENT Fragment_0
Function Fragment_0(Actor akActor)
;BEGIN CODE
MQ12b.PrepareNPC(akActor, True)
SiegeNPCControl.PrepareNPC(akActor, True)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
_00E_MQ12b_Functions Property MQ12b Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto

View File

@ -5,11 +5,11 @@ Scriptname PF_MQ12b_SC3_NormalCitizenFl_0011B0CB Extends Package Hidden
;BEGIN FRAGMENT Fragment_0
Function Fragment_0(Actor akActor)
;BEGIN CODE
MQ12b.PrepareNPC(akActor)
SiegeNPCControl.PrepareNPC(akActor)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
_00E_MQ12b_Functions Property MQ12b Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto

View File

@ -5,11 +5,11 @@ Scriptname PF_MQ12b_SC3_NormalCitizenFl_0011B181 Extends Package Hidden
;BEGIN FRAGMENT Fragment_0
Function Fragment_0(Actor akActor)
;BEGIN CODE
MQ12b.PrepareNPC(akActor)
SiegeNPCControl.PrepareNPC(akActor)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
_00E_MQ12b_Functions Property MQ12b Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto

View File

@ -5,11 +5,11 @@ Scriptname PF_MQ12b_SC4_CitizenFleePkgL_0011B182 Extends Package Hidden
;BEGIN FRAGMENT Fragment_0
Function Fragment_0(Actor akActor)
;BEGIN CODE
MQ12b.PrepareNPC(akActor)
SiegeNPCControl.PrepareNPC(akActor)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
_00E_MQ12b_Functions Property MQ12b Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto

View File

@ -5,11 +5,11 @@ Scriptname PF_MQ12b_SC4_GuardSandboxMar_0011B180 Extends Package Hidden
;BEGIN FRAGMENT Fragment_0
Function Fragment_0(Actor akActor)
;BEGIN CODE
MQ12b.PrepareNPC(akActor, True)
SiegeNPCControl.PrepareNPC(akActor, True)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
_00E_MQ12b_Functions Property MQ12b Auto
_00E_MQ12b_NPCControl Property SiegeNPCControl Auto