FindAllReferencesWithKeyword - ObjectReference

From the Fallout4 CreationKit Wiki
Revision as of 14:48, 3 February 2021 by imported>Scrivener07 (Player is added to the array if the passed in keywords matches that of the keywords of the player.)
Jump to navigation Jump to search

Member of: ObjectReference Script

Finds all references with any required keywords in the loaded area within the given radius of the calling ref.

Syntax

ObjectReference[] Function FindAllReferencesWithKeyword(Form arKeywordOrList, float afRadius) native

Parameters

  • arKeywordOrList: Keyword to look for or form list of keywords which ref must have all of
  • afRadius: Maximum distance from ref to look for a reference

Return Value

An array of references with the required keywords within the radius, empty if none was found.

Examples

; 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

Notes

  • If wanting to grab all actors in the loaded area using the keywords, ActorTypeNPC or ActorTypeHuman, the player will also be added to the array as its race contains both of those keywords. If having the player be in the array is not intended, you need can remove it by checking for its formID of 20(decimal).
int index = actorArray.Length

while index
    index -= 1
    if actorArray[index].GetFormID() == 20
        actorArray.Remove(index)
    endif
endWhile

See Also