Jump to content

Photo

How to get the list of the nearest NPCs?

nearest npc nearest list get list

  • Please log in to reply
7 replies to this topic

#1
VigVam33

VigVam33

    Enthusiast

  • Members
  • PipPip
  • 230 posts

How can I get a list of NPCs that are at a certain distance from the position or reference?



#2
kitcat81

kitcat81

    Faithful poster

  • Supporter
  • PipPipPipPip
  • 1,193 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, 16 September 2017 - 07:53 AM.


#3
VigVam33

VigVam33

    Enthusiast

  • Members
  • PipPip
  • 230 posts

Kitcat thank you, that's exactly what I need. :smile:


Edited by VigVam33, 18 September 2017 - 10:40 AM.


#4
kitcat81

kitcat81

    Faithful poster

  • Supporter
  • PipPipPipPip
  • 1,193 posts

Glad to help :)



#5
ThoraldGM

ThoraldGM

    Old hand

  • Premium Member
  • 532 posts
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.

#6
kitcat81

kitcat81

    Faithful poster

  • Supporter
  • PipPipPipPip
  • 1,193 posts

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.



#7
ThoraldGM

ThoraldGM

    Old hand

  • Premium Member
  • 532 posts
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.

#8
kitcat81

kitcat81

    Faithful poster

  • Supporter
  • PipPipPipPip
  • 1,193 posts

Yes, true  unless  you  set the alias to   be filled with  some particular   actor  using his  reference in the CK.

 

There are different ways to achieve  the same  result. You can choose the one that  fits your goal or your  skills better. 







Also tagged with one or more of these keywords: nearest npc, nearest, list, get list

Page loaded in: 1.163 seconds