Papyrus: Formlists w GetDistanceGetHeadingAngle?

Post » Sun Oct 20, 2013 1:10 am

I need to write a script that checks for nearby NPCs in a formlist who are looking at, or at least facing, the player.

Can I use formlists with the GetDistance() and GetHeadingAngle() functions? Or would I have to use an SKSE GetNthForm() loop?

User avatar
Amiee Kent
 
Posts: 3447
Joined: Thu Jun 15, 2006 2:25 pm

Post » Sun Oct 20, 2013 4:54 am

Edit: I read your post again, and it seems GetNthForm(N) is for getting items in containers, not forms in formlists. The function you want is GetAt(Index). In my original post below, I outlined a possible implementation.

You use a while loop to check each NPC in the formlist.

Your formlist would have to be filled with the actor references from the render window, though, not the base forms.

Actor Player = Game.GetPlayer()FormList Property NPCs AutoInt Count = NPCs.GetLength()Actor CurrentNPCFloat DistanceFloat HeadingAngleWhile Count > 0    Count -= 1    CurrentNPC = NPCs.GetAt(Count) as Actor    Distance = CurrentNPC.GetDistance(Player)    HeadingAngle = CurrentNPC.GetHeadingAngle(Player)    If Distance < 200 && HeadingAngle < 15        ; lotsa code    EndIfEndWhile
The amount of local variables I defined is not specifically due to the while loop, but as an optimization, so I don't have to write atrocities like this:

If (NPCs.GetAt(Count) as Actor).GetDistance(Game.GetPlayer()) < 200 && (NPCs.GetAt(Count) as Actor).GetHeadingAngle(Game.GetPlayer()) < 15
User avatar
Christie Mitchell
 
Posts: 3389
Joined: Mon Nov 27, 2006 10:44 pm


Return to V - Skyrim