User:Dz/NPC Scripts

NPC Utility Scripts
These are useful utilites I have developed over time to help me use NPCs in OpenSimulator. Many of them are assembled from bits and pieces of code I have read/seen/fixed/admired. Some of the code snippets appear with permissions, Please do not remove the attributions where they can be found in the comments. The code has been shared, only asking simple consideration. Please respect the wishes of the original authors as I have attempted to do.

Remember, you will need to enable NPC functions,  and may need to set the severity level of allowed osNPC function calls for these scripts to work.

If you have feedback on script errors, please post it to the page discussion User_talk:Dz/NPC_Scripts

NPC BotKiller
Sometimes..things go wrong...and you have a region full of wandering NPC's. Drop this code in a prim and touch it...  It can take a while to remove them all.

PLEASE DON'T NUKE other peoples NPC's.

NPC Router
This script re-directs any NPC that collides with the object to a random destination selected from an internal list.

Once the routers are placed, a text label display can be toggled by touching it. This makes it easy to collect locations

Routers should be placed to facilitate collisions with the avatar capsules.

The real trick of this router design is the rotate calculations. These prevents the NPCs from walking backwards when assigned new targets "behind" them.

NPC Creation Scripts
While NPC's provide a very low overhead way to populate regions, there is still overhead involved. Logging in and out, generating note cards with serialized appearances, and trying to figure out if they are at a destination while moving all consume server resources. Some simple planning can remove/reduce the impact of these operations during "normal" conditions. Generate and check your NPC appearance WAY ahead of time. Sometimes you will find that you have to rebake your appearance AND remove and re-wear all your attachments before they will "clone" properly. Log your NPC's in and out during times when there are few in the region. Allow time between each login.. NPCs wearing scripted attachments might require 5 seconds between each login/logout to minimize the impact of starting/stopping scripts.

Build error correction into your movement plans. If your NPC absolutely positively has to get to , You better have a alternative plan to sending that as a destination to a MOVETO function call once and hoping it arrives....

Animate instead of move. Take advantage of the fact that the siton function can sit an NPC on any prim in the region. Seated NPC's are easy to animate, and they aren't generating avatar capsule collisions.

While the simple generator can be fun to show off, it is also a useful tool to verify that the NPC appearance is what you expect before you place it in your region. Once you start collecting the note cards of different appearances, you will begin to understand the logistics of introducing variety to your sim through NPCs.

Basic Clone Generator
This script generates a clone of the avatar that touches it. The NPC will sit on the generator prim and say hello. Touching the generator again kills the NPC.

Advanced Clone Generator
This script supports the deployment of large numbers of NPC bots. It maintains an internal library of appearance Notecards. Notecards are generated by touching the object and selecting the [Clone Me] button. The user will be required to provide a unique name to store an appearance.

Selecting the [Choose One] menu option will present the user with a menu to select the appearance notecard used to generate the NPC's.

Select [Create Bots] to generate the NPC's. They are created slowly to minimize impact on sim performance. Touching the generator before all NPC's are generated will stop the process.

NPC Animation Scripts
My experience with NPC animation is a combination of a very simple animation override with in-word scripted objects designed to detect collisions, proximity, or seated avatars can provide exceptional results. Limiting the AO tasks to movement animation types (Walk/Run/Fly) reduces the complexity and size of the script.

Using the inworld NPC Routers as targets, we can set up a network of paths between the NPC generators and the region destinations. For instance, in a city simulation, we could place a generator in a subway station, with routers at the intersections on the streets, to drive traffic around the city buildings. Routers at the building entrance can dirent NPC's inside to seating locations. Using scripted poseballs to provide places for the NPC's to interact, also allows non-NPC participation.

Basic NPC AO (Animation Override)
The intent is to provide an efficient way to give NPC's unique combinations of movement ONLY animations. These are simple scripts, easy to duplicate and modify the animations to use. Attach the AO to your HUD before you clone your appearance and generate the NPC. Touch the HUD to toggle it off and back on to make sure it is working. While designed for use with NPC's, these AO's will work just as well with other bot types or regular avatars.

This script monitors change events for a CHANGED_ANIMATION flag. This is vastly more efficient than parsing the list of current animations 3 or 4 times a second to see if you are still walking/standing/flying. There are other reasons NOT to try and use AOs ported from SL on NPC's. Most will fail to work at all, and some will actually animate the avatar that was cloned instead of the NPC.

An AO script is not much use with the animations to go with it. There are a number of good AO animation sets available in some of the public domain OAR and IAR files. I had the pleasure once to meet the creator of the animations contained in the Linda Kellie OAR files. The following scripts are adapted to those animation names so that you can drop them, and the animations (after you DL them) into a single prim and attach it to your HUD.

Rememeber, You must place the HUD on the ground to add animations, and you should take it back into inventory before wearing it to make sure the contents update properly.