Jump to content

Photo

Script help, how to monitor NPCs inventory

script papyrus fallout4

  • Please log in to reply
12 replies to this topic

#1
louisthird

louisthird

    Regular

  • Members
  • PipPip
  • 57 posts

Hello Fallout 4 mod community,

 

Huge respect for all of you!  The mods that y'all have been able to pull off with little-to-no documentation is amazing.

 

For a mod I am working on I need to be able to constantly monitor an NPCs inventory i.e. AddInventoryEventFilter(), OnItemAdded(), etc.

 

Where do I hook into to get these Event messages?  A Quest?  or more likely an ObjectReference?

 

I'd love some help and wouldn't mind a mentor if you don't mind answering some occasional questions.

 

Thank you!

-louisthird

 

 



#2
SKK50

SKK50

    Institutum delenda est

  • Premium Member
  • 4,297 posts
If the npc base actor is unique to your mod then attach a script direct to the actor form.

If the npc is a base game actor and you want to avoid hacking base game assets for compatibility then adding the actor to a quest reference alias (or Reference Collection Alias if there will be multiple actors) and attach the script to the alias.

There are many and varied ways of adding actors to aliases which depends on your operating context; how is the actor created and how are they identified as the target.

#3
louisthird

louisthird

    Regular

  • Members
  • PipPip
  • 57 posts

Thanks SKK50!  Is there any way to make it generic for any actor that may be in my mod or one from the base game?  Would the Reference Collection Alias route accomplish this goal?

 

By the way, thanks for the many hours of fun with SKK Combat Stalkers.  Pitting maxed out Combat Stalker enemies vs. maxed out NPCs Travel friendlies has resulted in some epic battles.   :cool:

 

Thanks for your help,

    -louisthird



#4
SKK50

SKK50

    Institutum delenda est

  • Premium Member
  • 4,297 posts

Yes I have found quest RefCollectionAlias is the best way to manage attaching scripts to ad-hoc or variable ObjectReferences running in the game.

 

There are other methods, but quest aliases are the only one that allows different AI packages to be attached to unowned actors. You may not consider this now, but betcha $10 you will want in the fullness of time.

 

If your mod is not creating the actors then the challenge is typically figuring out the logic to identify actors to add into the RefCollectionAlias before you know about them.

 

ps always pleasing to hear about good SKK combat experiences.



#5
louisthird

louisthird

    Regular

  • Members
  • PipPip
  • 57 posts

You are correct that it will not be creating the NPC actors - just monitoring their inventories.

 

Sounds like the Quest Alias is the best route to be generic for all NPC actors.  Absolutely will want that as you recommended (where do I send the money?)  It does sound like a challenge to get the RefCollectionAlias populated with an Actor that is not from the base game.  Any recommendations on this?



#6
louisthird

louisthird

    Regular

  • Members
  • PipPip
  • 57 posts

Quest Aliases > Reference Collection Alias > Find Matching Reference, In Loaded Area, Actors Only, Closest To Player

Match Conditions: PL GetPlayerTeammate == 1.00



#7
IDontEvenKnow

IDontEvenKnow

    Faithful poster

  • Premium Member
  • 1,255 posts

You'll probably want Subject GetPlayerTeammate, otherwise you're checking if the player is their own teammate and the RefCollectionAlias probably won't fill with anything.

 

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. Note that this will reset any script data attached to the quest and any aliases, so if there's any state-sensitive data anywhere in you're script, you'll need separate "controller" and "finder" quests, and AddRefCollection the data in the finder quest over to the controller quest or whatever.

Or, if you already have an external reference, you can always manually AddRef() to your RefCollectionAlias as necessary.



#8
louisthird

louisthird

    Regular

  • Members
  • PipPip
  • 57 posts

Thanks IDontEvenKnow (of which it appears you know much...) !

 

Funny as it is I noticed last night that it said 'PL' on Creation Kit but didn't update this post... but yeah, duh that never would have worked!

  • I also added to conditions:   S   GetInFaction   Faction: 'CurrentCompanionFaction'   ==   1.00

There is no non-vanilla script data attached to my mod in any way... yet!  Having some custom data will depend if I have to save something to update the RefCollectionAlias.

 

IDontEvenKnow, you mentioned to periodically stop/restart the quest... I agree and currently I am researching a way to find out when companions are ADDED.  OnCompanionDismiss() is available, but no Event for added.  I found this old (but gold) post by SKK about the topic https://forums.nexus...rent-companion/ but it does not consider non-vanilla companions.

 

Options I have been pondering:

  • Being notified in the RefCollectionAlias script when a companion is added like OnCompanionAdded(ObjectReference) and calling AddRef() with the reference -- the missing Holy Grail  :sigh:
  • Saving a count of the previous number of companions and running a persistent loop that checks the current number of companions -- if the counts differ, then refresh the quest
  • Running a persistent loop that refreshes the quest on a constant interval -- exposes a window where the data may be out-of-date
  • Hooking to other companion events that indicate they are there and track the receiving actors (they talked, they got hit, etc.) -- if they ever differ, refresh the quest

I really appreciate all your responses!

   -louisthird



#9
louisthird

louisthird

    Regular

  • Members
  • PipPip
  • 57 posts

Tried the constant interval loop and it actually works pretty amazing.



#10
SKK50

SKK50

    Institutum delenda est

  • Premium Member
  • 4,297 posts

For standard companion add or dismiss use

Quest	Property pFollowers Auto Const Mandatory

Self.RegisterForCustomEvent((pFollowers as FollowersScript), "CompanionChange") 

Event FollowersScript.CompanionChange(FollowersScript akSender, Var[] akArgs)

Actor akActor = akArgs[0] as actor
bool bIsCompanion = akArgs[1] as bool

EndEvent

 

For ad-hoc followers, non standard or multiple companions there is no standard base game event for join/leave.

 

Some other notes from old testing;

 

;Followers.Alias_Companion is always in CurrentCompanionFaction 
;Followers.Alias_Companion is in Game.GetPlayerFollowers()
;Followers.Alias_Companion is in condition GetPlayerTeammate
;Followers.Alias_Companion .IsPlayerTeamMate = TRUE
;Followers.Alias_DogmeatCompanion has all the same reporting.
 
;SetPlayerTeammate Follower is in Game.GetPlayerFollowers()
;SetPlayerTeammate Follower is in condition GetPlayerTeammate
;SetPlayerTeammate Follower .IsPlayerTeamMate() = TRUE
 
;Quest follower is in Game.GetPlayerFollowers()
;Quest follower is not in condition GetPlayerTeammate
;Quest follower .IsPlayerTeamMate() = FALSE
;Quest follower like Deacon in Tradecraft, Jack in Cabot, Wasshername in Mass Fusion & etc.






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

Page loaded in: 1.124 seconds