Difference between revisions of "FindAllReferencesWithKeyword - ObjectReference"

→‎Notes: Found easier non pulling method to remove the player from the array.
imported>Gawdl3y
 
imported>Scrivener07
(→‎Notes: Found easier non pulling method to remove the player from the array.)
 
(3 intermediate revisions by 2 users not shown)
Line 19: Line 19:
== Examples ==
== Examples ==
<source lang="papyrus">
<source lang="papyrus">
; Find all refs that match the keywords in the merchant listwithin 200 units of the activator
; Find all references with the ActorTypeAnimal keyword within 200 distance units of the player
ObjectReference[] sellarray = ActiRef.FindAllReferencesOfType(MerchantKeywordList, 200.0)
ObjectReference[] kActorArray = Game.GetPlayer().FindAllReferencesWithKeyword(ActorTypeAnimal, 200.0)


; Find all refs with keyword Raider within 200 units of the activator
; Find all references that match ALL keywords in the actor type formlist within 200 distance units of the player
ObjectReference[] raiderrefarray = ActiRef.FindAllReferencesOfType(Raider, 200.0)
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
</source>
== 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 can remove it via [[Find - Array]] and then [[Remove - Array]]:
<source lang="papyrus">
Actor Player = Game.GetPlayer()
ObjectReference[] kActors = Player.FindAllReferencesWithKeyword(ActorTypeNPC, 2048.0)
int playerIndex = kActors.Find(Player as Actor)
kActors.Remove(playerIndex)
</source>
</source>


Anonymous user