Jump to content

Photo

Script help, how to monitor NPCs inventory

script papyrus fallout4

  • Please log in to reply
12 replies to this topic

#11
louisthird

louisthird

    Regular

  • Members
  • PipPip
  • 57 posts

... Do note that the Story Manager only auto-fills aliases when the quest first starts up, so you'll probably have to periodically stop and restart the quest to update the actors in the RefCollectionAlias. ...

 

IDontEvenKnow - Do you have a short example of how you would periodically start and restart the quest?  I imagine it would involve the use of StartTimer(), but I have been having trouble getting it to reliably work.  How would you do it? ... Looking for some best practice advice here because how I am doing it is likely not.

 

This is what I was trying below.  Maybe I need to be doing SecretFormula_QuestScript.Reset(), etc.?  Or maybe my script code extending Quest needs to match the Quest name: SecretFormula_Quest ?  LMK.  Thanks!

Scriptname SecretFormula_QuestScript extends Quest

import MCM

Quest Property SecretFormula_Quest Auto Const
int timerId = 8675309 Const

Function CheckRunning()
  If SecretFormula_Quest.IsRunning()
    Debug.Notification("Secret Formula is running")
  Else
    Debug.Notification("Secret Formula is not running")
  EndIf
EndFunction

Function ForceRestart()
  SecretFormula_Quest.Reset()
EndFunction

Event OnQuestInit()
  Debug.Notification("Secret Formula Initializing")
EndEvent

Event OnReset()
  SecretFormula_Quest.Stop()
  SecretFormula_Quest.Start()
  StartTimer(MCM.GetModSettingInt("louisthird_SecretFormula", "iSecretFormulaRefreshTimeInSeconds:Main"), timerId)
EndEvent

Event OnQuestShutdown()
  CancelTimer(timerId)
EndEvent

Event OnTimer(int aiTimerId)
  If aiTimerId == timerId
    SecretFormula_Quest.Reset()
  EndIf
EndEvent

Edited by louisthird, 12 August 2020 - 03:50 AM.


#12
SKK50

SKK50

    Institutum delenda est

  • Premium Member
  • 4,291 posts

I would like to say that using Events is more elegant than timers if you can find an event that keys into the likely change.

 

I have abandoned mods that I could not find an event for rather than add more tight timers, but that's just my quality threshold.

 

The code in the controlling quest is simple;

Quest Property pFolowrFinderQuest Auto Const Mandatory 
Float fQuestResetTimer = 60.0
Int iQuestResetTimer = 10 
Bool bIsThisFunctionActive = False

OnTimer(Int iTimer) 
   If (iTimer == iQuestResetTimer) 
      pFollowerFinderQuest.Stop()
      pFollowerFinderQuest.Start()
      If (bIsThisFunctionActive == TRUE)
         Self.StartTimer(fQuestResetTimer, iQuestResetTimer)
      Endif
   EndIf
EndEvent

Because quest stop and start are latent/synch calls which wait for completion before returning.

 

Edit: of course you need to actually set the active flag and START the timer on some event or user input ... 

 

Alternative to using story manager to fill a quest alias is:

OnTimer(Int iTimer) 
   If (iTimer == iFindFollowersTimer) 
      Actor[] PlayerFollowers = Game.GetPlayerFollowers()
      Int iIndex = 0
      While (iIndex < PlayerFollowers.Length)
           Actor ThisFollower = PlayerFollowers[iIndex]
	   ;Do stuff to ThisFollower 
	   iIndex +=1
      EndWhile
      If (bIsThisFunctionActive == TRUE)
         Self.StartTimer(fFindFollowersTimer, iFindFollowersTimer)
      Endif
   EndIf
EndEvent


#13
louisthird

louisthird

    Regular

  • Members
  • PipPip
  • 57 posts

SKK's way of not using Story Manager worked smooth for tracking the companions for a mod like I am working on that is more script based (i.e. not a quest mod like talking to a character or finding a grasshopper statue).

 

As a side note: the whole stopping and starting the quest did not work.  This was the reason that I tried the non-Story Manager approach which is working well.

 

I'm almost done... just dealing with a little more scope creep on my part.  Gotta stop myself before the mod description is: "this mod replaces the entire Fallout 4 engine..."

 

Take care,

    -louisthird







Also tagged with one or more of these keywords: script, papyrus, fallout4

Page loaded in: 1.138 seconds