enderalse/source/scripts/_00E_MQ12b_NPCControl.psc

115 lines
3.1 KiB
Plaintext

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
If RegisteredDisabledNPCs.Find(akMoveActor) >= 0 || 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)
nRegisteredDisabledNPCs += 1
; In case an actor slips in here, RegisteredDisabledNPCs may have an empty slot in the middle, and it's fine
int iSlot = nRegisteredDisabledNPCs - 1
if iSlot <= 127
RegisteredDisabledNPCs[iSlot] = akMoveActor
;Debug.Trace("Registered disabled " + akMoveActor.GetBaseObject().GetName() + " " + (akMoveActor as String))
else
; Added overflow to the ghosted
_RegisterGhostedNPC(akMoveActor)
endif
EndFunction
Function _RegisterGhostedNPC(Actor akMoveActor)
nRegisteredGhostedNPCs += 1
int iSlot = nRegisteredGhostedNPCs - 1
if iSlot <= 127
RegisteredGhostedNPCs[iSlot] = akMoveActor
;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