a few weeks ago i had the privilege to meet Ohn Lang – a passionate and talented OpenSim scripter and creator who happens to like NPCs. NPC scripting is something that intimidates me (lol, sit scripts scare me!) but have so many practical and fun applications
Ohn Lang will be adding NPCs to Hax Nuit which will bring it to life and truly complete it. in her quest to do so, she has created a pretty amazing script that is free to use and very nicely configured
in her words:
Just wanted to let you know, I finished that action NPC script we were talking about in the comments on your blog. I made a copy/modify/transfer package. The default configured behavior is being demonstrated by the NPC on the ohn freebies world, in the SW corner of the region. The package is set out, bright yellow box. People just need a kitely account to go in and grab it.
The NPC walks, talks, pauses, sits, stands, and animates based on an action configuration card. Automatically re-rezzes on region restart. The default appearance uses Linda Kellie’s Adam skin, Farmboy outfit, and Rugged AO (so he walks studly-like, LOL). The NPC controller can also be configured to rez objects anywhere in the region and these objects can be sat on by the NPC when instructed to do so through the action configuration card. Out of the package, it rezzes, places, and uses three such objects.
This script will be the foundation for the Hax Nuit NPCs. I designed it (hopefully) to be easily extendable and customizable.
I tried to name things in a friendly way. And the code is actually kinda simple :D. The script is long, but that’s because I like clean formatting and whitespace. There are a some global variables, then a few functions (none of them too long or complicated).
Then the default state: starting stuff from fresh, configured objects in inventory rez, NPC gets created, and immediately after it transitions to the NPCidle state. This is the new quasi-default state once the NPC is first created. Each different type of action (moving, talking, animation, etc.) is associated with a different state (such as NPCtalk or NPCgoto). As the NPC cycles through the configured actions, the script will transition to the state for that action type, do the action, then transition right back to the idle state once finished. The idle state is where the script decides what to do next, and consequently which state should be transitioned to.
The action states have very little code in them, so I think they should be easier than average to follow. Because each action is associated with its own state, this makes it easy to extend. Just create a new state for the new action type using the template I provided in the instructions card, add support for the action command and state in the idle state (I provided a template for that too), and boom, script extended. :D
dang, that NPC does more than i do! thank you Ohn for reaching out to say hello, sharing your awesome work, and being a wonderful new friend =)