Jump to content

[Papyrus] Help with "FindAllReferencesOfType"


Recommended Posts

I made a script that contains the following state, but I'm having trouble getting it to work.

State SCRIPTSTATE
    Event OnBeginState(string asOldState)
        ObjectReference[] NPCs = ActiRef.FindAllReferencesOfType(MY_FORM_LIST, 2000.0)
        NPCs.Kill()
    EndEvent

My goal is to have the activator that this script is attached to run Kill() on all the NPCs listed in MY_FORM_LIST within 2000(Measurement type?) of the activator. I have not however been able to get this to work as of yet and I'm not Papyrus smart enough to figure out why. I've done a lot of searching for information on "FindAllReferencesOfType" but have found only the wiki page and 1 example of actual use on another website. I'm completely new to using form lists too, so together they've put me in a bind. Thanks in advance. :)

Link to comment
Share on other sites

On a random side note, I'd just like to say how glad I am this forum exists. So many people have been able to provide information that I haven't been able to find on my own. Not only that, but I've also been able to help others with their questions too while waiting for answers on my own! So thanks to all of you out there that take the time to share your knowledge with us just starting out with Papyrus. It REALLY makes a difference. :smile:

Edited by someoneyouknow
Link to comment
Share on other sites

Is there a reason you are using states for this instead of the OnActivate event?

 

Edit: also the kill() function needs to be run on an actor not an objectreference. replace your Objectreference[] NPCs with Actor[] NPCs and see if that works if not you might have to do each one separate using a while loop or use a RefCollectionAlias instead and use KillAll(). And add As Actor[] behind FindAllReferencesOfType(MY_FROM_LIST, 2000.0).

Edited by LoneRaptor
Link to comment
Share on other sites

Just for the sake of teaching you a little something about arrays..

Event OnBeginState(String asOldState)
    ObjectReference[] NPCs = ActiRef.FindAllReferencesOfType(MY_FORM_LIST, 2000.0)
    Int Index = NPCs.Length
    While Index
        Index -= 1
        NPCs[Index].Kill()
    EndWhile
EndEvent
Edited by Lisselli
Link to comment
Share on other sites

  • Recently Browsing   0 members

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