Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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...

 

  Reveal hidden contents

 

 

I strongly recommend that you avoid using this method in a gamemode block. While loops can be fairly CPU intensive.

Posted

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

Posted

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.

  • Recently Browsing   0 members

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