Sticz Posted April 13, 2013 Share Posted April 13, 2013 How can I get a script to run if there is only 1 npc in a cell (or even within a certain distance)? I am trying to get a theft-type of script going and want witnesses to be avoided. Sticz Link to comment Share on other sites More sharing options...
Lanceor Posted April 14, 2013 Share Posted April 14, 2013 What exactly do you want to do? There are some complex ways of counting the number of NPCs in a cell or a certain distance, but it can be quite CPU intensive. Perhaps the easiest way is an invisible area of effect spell and all that it does when it affects an actor is change a certain variable by 1. Link to comment Share on other sites More sharing options...
Sticz Posted April 14, 2013 Author Share Posted April 14, 2013 Well, I tried this script: if (Player.GetNumRefs 35 > 1)Player.ModCrimeGold 500 and it works, but it also counts dead actors as witnesses as well. How can I only count lving/conscious actors? Sticz Link to comment Share on other sites More sharing options...
WarRatsG Posted April 14, 2013 Share Posted April 14, 2013 GetHighActors has worked well for me in the past. It returns an array of all actors currently in high level processing - which includes those within the player's cell. Once you have the array, a few If statements in a while loop is all you need to narrow down who counts as a witness. I'll write you a script fragment that you can merge into an existing script... Array_var Actors ;Array_Var = Array Variable Ref TempRef ;The actor being evaluated Short Key ;The array key currently being used Short detected ;You'll see what I mean. Begin <something> Let Actors := GetHighActors ;Returns actors in the cell, and all other actors with High-level AI processing. Let Key := ar_Size Actors ;Returns how many variables are in the array. While Key > 0 ;"While Loops" will repeat so long as the expression is true. Let Key -= 1 Let TempRef := Actors[Key] If TempRef.GetDetected Player == 0 Continue ;Continue is like a return, but for a while loop. ElseIf ;;;Any other checks, like maybe the witness is in the Thieves' Guild ;;;If player passes all checks Continue ;;;If Player fails a check Set Detected to 1 Break ;Ends the loop immediately, no point in checking anyone else. endif endif Loop Let Actors := ar_Null ;Clean up the array, to avoid keeping unneeded data If Detected == 1 ;;;Do stuff Else ;;;Do other stuff endif End I strongly recommend that you avoid using this method in a gamemode block. While loops can be fairly CPU intensive. Link to comment Share on other sites More sharing options...
Sticz Posted April 14, 2013 Author Share Posted April 14, 2013 Hmmm, I can see where the code calls for variables, but I am not sure where to put this. Do I place this before the gamemode sequences? Sticz Link to comment Share on other sites More sharing options...
WarRatsG Posted April 14, 2013 Share Posted April 14, 2013 You can put it in a GameMode sequence if you have to, but make sure that the while loop does not run too often. A well placed Return call should do the trick, but it depends on how your other scripts work. Essentially, just use it whenever you need to find out if there are any witnesses nearby. Link to comment Share on other sites More sharing options...
Recommended Posts