Jump to content

How to get the list of the nearest NPCs?


7Ramhat

Recommended Posts

From wiki:

 

; Find all references with the ActorTypeAnimal keyword within 200 distance units of the player
ObjectReference[] kActorArray = Game.GetPlayer().FindAllReferencesWithKeyword(ActorTypeAnimal, 200.0)

; Find all references that match ALL keywords in the actor type formlist within 200 distance units of the player
ObjectReference[] kActorArray = Game.GetPlayer().FindAllReferencesWithKeyword(ActorTypeFormlist, 200.0)

; Find all references that match ANY keyword in the actor type formlist within 200 distance units of the player
Int i = 0
While i < ActorTypeFormlist.GetSize()
ObjectReference[] kActorArray = Game.GetPlayer().FindAllReferencesWithKeyword(ActorTypeFormlist.GetAt(i), 200.0)
i += 1
EndWhile

 

If you want only humanoid actors ( humans, non feral ghouls and some types of synths ) you can use ActorTypeNPC keyword.

 

Another way is to start a quest with RefCollectionAlias and conditions - ActorTypeNPC, GetDistance (your ref) etc.

Edited by kitcat81
Link to comment
Share on other sites

Is there a way to register/listen for the OnLoad event of all NPCs in one group that spawn via leveled list? I may use your method above as a workaround that somehow pings from the player as they walk, but I want to alter all Diamond City guards by script, as they spawn. I could put all 18 into reference aliases, but there are mods that add more guards and I want to handle that dynamically.

 

Plus for other projects it would be useful to have a way to dynamically grab refs for all raiders, all supermutants, etc so that scripts can do something to each one OnLoad.

 

Edit: Your method combined with OnLocationChange and a huge radius might be what I need, but I'm open to other ideas.

Link to comment
Share on other sites

You can add a new script to the actorbase that uses the leveled list in the CK.

i don`t think you can grab references of all actors in game, at least not with papyrus.

Most npc do unload together with the cell. Not just 3d, they fully unload and can`t be manipulated or even found while in this state.

You can dynamically grab references of NPC-s in loaded area.

Keeping hundreds of NPC-s persistent by alias or script can affect the game perfomance.

Link to comment
Share on other sites

Is it true they are only persistent until the reference alias is cleared? I'm thinking of grabbing the guards in radius at OnLocationChange if GetParentCell is Diamond City, equipping them with player specified gear, making any other changes player specifies in MCM, then releasing them.

 

I've been looking for a gold standard for scripted manipulation of NPCs for awhile, so pretty happy to see this thread.

 

Edit (again): Not at home to test, but I may not need reference aliases at all. ObjectReference[] kActorArray handles dynamic sizing and would allow me to address each element/actor by index before the event ends.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...