Advertisement
skk50

FO4 Papyrus RefCollectionAlias scavenge timer

Apr 5th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. ;**************************************************************************
  2. ;FO4 Papyrus RefCollectionAlias scavenge timer
  3. ;Ensure no dead spawned NPCs hang around in a RefCollectionAlias due to missed
  4. ;OnDeath() alias script events which can happen during simultaneous events,
  5. ; or when NPC 3d is unloaded between uGridsToLoad and fLODFadeOutMultActors
  6. ;**************************************************************************
  7.  
  8. GlobalVariable Property pGlobalName Auto Mandatory
  9. RefCollectionAlias Property Alias_Name Auto
  10.  
  11. Int iScavengeTimer = 30
  12. Float fScavengeTimer = 60.0 ;Player sprint 500 NPC run 350, deltaT to 3D unload at 15K separation
  13.  
  14. ;**************************************************************************
  15.  
  16. Event OnTimer(int iTimer)
  17.  
  18. If iTimer == iScavengeTimer
  19. Scavenge()
  20. Endif
  21.  
  22. EndEvent
  23.  
  24. ;**************************************************************************
  25.  
  26. Function Scavenge()
  27.  
  28. Bool bCleanup = FALSE
  29. Int iIndex = 0
  30.  
  31. While iIndex < Alias_Name.GetCount()
  32. ObjectReference ThisREF = Alias_Name.GetAt(iIndex)
  33. If (ThisREF as Actor).IsDead() == TRUE ;This is normally done by ONDeath attached to RefAlias
  34. Alias_Name.RemoveRef(ThisREF) ;Remove persistent hold
  35. Elseif ThisREF.Is3DLoaded() == FALSE ;One or more live NPCs are stuck with 3D unloaded
  36. bCleanup = TRUE
  37. EndIf
  38. iIndex +=1
  39. EndWhile
  40.  
  41. If Alias_Name.GetCount() == 0 || bCleanup == TRUE ;None left or stuck
  42. Cleanup()
  43. Else ;Keep going
  44. pGlobalName.SetValue(Alias_Name.GetCount()) ;Global is used in quest objective
  45. pQuestName.UpdateCurrentInstanceGlobal(pGlobalName) ;Global is used in quest objective
  46. StartTimer(fScavengeTimer, iScavengeTimer)
  47. Endif
  48.  
  49. EndFunction
  50.  
  51. ;**************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement