NPC Test 001

several cloned NPCs

As I mentioned in my previous post (OpenSim Server-Side NPC Experiments: Day One), I’ve been fiddling with the existing server-side NPC support within OpenSim. As stated, I didn’t have much luck with my initial experiments. Luckily, I received an email the next day from bodzette Coignet who has been experimenting with the same code. In the message, bodzette gave me a couple of tips that got my research moving along the right track. Within an hour, I had a “working” NPC running on my sim! Since I’m certainly not the only one interested in running NPCs on their OpenSim installations, I’m going to break down for you what must be done to create them, discuss their many limitations, bring up a few ideas for how the existing bots might be used, and then go on to ramble about possibilities for better implementations of the code.

Before we get into the heart of the how’s & why’s, let’s take a look at my experiments so far. As you’ll see in the above video, the existing code allows the NPC to be created, say things in local chat, play avatar animations, and be removed from the sim. It also contains code that should allow the NPC to walk to a new location, however this code seems to be non-functional (I’ll be pestering Diva Canto a bit about that – hers looked like they were walking all over the place haha). Not much else is currently implemented, but the existing code should be enough of a guide to expand upon these abilities. You’ll also see that I can create several of the same NPC, but that I can only maintain control of the last one summoned…

Now then, let’s talk about how to create an NPC on your OpenSim server… First and foremost, you’re going to need an older version of OpenSim than many of you are probably using. As reported on Mantis, all current osNPC functions fail on the 0.7.x versions. To get this working, bodzette Coignet advised that I backtrack & install OpenSim v0.6.9, in which the code still functions. Since I’ve done so much work on my existing sim & don’t want to risk losing it, I installed OpenSim 0.6.9 on my local machine & just tested things out here at home.

NPC Test 000

my first test, NPCs with no avatars

Preparing For The NPC

Once the 0.6.9 binaries are extracted (or compiled, if you’re making it from source) configure OpenSim as you normally would. When you’re ready, you’ll need to make the following modifications to your OpenSim.ini file (located in the /bin directory). Open it with your favorite text editor & search for the [XEngine] section.

(1) Find the line that reads
AllowOSFunctions = false
and change it to
AllowOSFunctions = true

(2) Look for the line that reads
OSFunctionThreatLevel = VeryLow
and change it to
OSFunctionThreatLevel = VeryHigh

The VeryHigh threat level is needed to implement avatar animations. If you only wish to create NPCs, remove NPCs, make them walk & talk, etc., then you can set it to
OSFunctionThreatLevel = High
instead.

(3) Go to the bottom of the [XEngine] section (just above where [GridInfo] starts) and add the following lines of text:
; osNPC specific functions
; note: these are High threat level functions
Allow_osNpcCreate = true
Allow_osNpcMoveTo = true
Allow_osNpcRemove = true
Allow_osNpcSay = true
; and these let us animate the NPCs
; note: these two are VeryHigh threat level functions
Allow_osAvatarPlayAnimation = true
Allow_osAvatarStopAnimation = true

(4) Save & close OpenSim.ini

(5) Start your simulator running and go through the usual setup procedures, creating your master avatar account, regions, etc.

(6) Once the sim is up and running, create a new user taking note of their firstname, lastname & the UUID that the system provides.

(7) Log into your simlator as this new user & configure their appearance however you’d like them (note: clothing will persist to the new NPC, but attachments will not – I’m looking into why this is). When you’re done, logout.

Your NPC is now almost ready to use… You’ve set everything necessary in the INI files & you’ve created an NPC account with it’s own unique appearance & UUID. Great! Now let’s look at bringing it to life on your sim!

NPC Test 002

animating an NPC

Scripting The NPC

(1) Log back into your sim with your own master account. Fix your appearance if necessary, etc.

(2) Create a prim & name it NPC Starter or something of the sort. It can be placed anywhere you’d like & look however you want, the details are unimportant.

(3) Create a new script in the prim & rename it to NPC Controller or something similar. Edit the script and replace it’s contents with the following script (which is heavily commented for those who want more info) [Click Here To Download The Script]:

// BEGIN

// osNPC script for OpenSim v0.6.9 and below
// does not function on OpenSim v0.7x
//
// original script by Haplo Voss, modified here & there by Kenneth Rougeau
// see the following link for more details
// http://opensimulator.org/mantis/view.php?id=5148&nbn=2
//
// Additions will have to be made to your OpenSim.ini files
// in the [XEngine] section. Add the following lines:
// Allow_osNpcCreate = true
// Allow_osNpcMoveTo = true
// Allow_osNpcRemove = true
// Allow_osNpcSay = true
// Allow_osAvatarPlayAnimation = true
// Allow_osAvatarStopAnimation = true
//
// For more information & available functions, read this:
// http://opensimulator.org/wiki/OSSL_Enabling_Functions
//
// Function notes, for future reference:
// key osNpcCreate(string firstname, string lastname, vector position, vector cloneFrom)
// osNpcMoveTo(key npc, vector position
// osNpcSay(key npc, string message)
// osNpcRemove(key npc)
// osAvatarPlayAnimation(key avatar, string animation)
// osAvatarStopAnimation(key avatar, string animation)
//
// For more information & more functions, see this post by Snowcrash:
// http://www.mail-archive.com/opensim-dev@lists.berlios.de/msg03329.html
//
// The following code should be placed inside a prim in-world
//
// Create a new user on your simulation & then replace the
// firstname, lastname, starting location & UUID below
// with those of your own intended NPC avatar.
//
// Commands:
// Use Channel 10 to issue NPC commands
// create = creates the NPC
// remove = kills the NPC
// say = have the NPC speak
// move = make the NPC move
// animate = NPC plays an animation

key npc;
default
{
state_entry(){
llListen(10,””,NULL_KEY,””);
}
listen(integer channel, string name, key id, string msg){
if (msg != “”){
if (msg == “create”){
npc = osNpcCreate (“Jane”, “Doe”, <115, 165, 23>, “d004fdd5-c08c-45c8-9ab2-7b1f4d5f6abc”);
}
//else if (msg == “remove” && npc != NULL_KEY){
else if (msg == “remove”){
osNpcSay (npc, “You will pay for this with your liiiiiivvveeessss!!!…..”);
osNpcRemove (npc);
}
//else if (msg == “say” && npc != NULL_KEY){
else if (msg == “say”){
osNpcSay (npc, “I am your worst Nightmare!!!!”);
}

//else if (msg == “move” && npc != NULL_KEY){
else if (msg == “move”){
osNpcMoveTo (npc, llGetPos()+<9,9,0>);
}
//else if (msg == “animate” && npc != NULL_KEY){
else if (msg == “animate”){
osAvatarPlayAnimation (npc, “stand_1″);
llSleep(3);
osAvatarStopAnimation (npc, “stand_1″);
}
}
}
}

// END

(4) In the script, find the line that reads
npc = osNpcCreate (“Jane”, “Doe”, <115, 165, 23>, “d004fdd5-c08c-45c8-9ab2-7b1f4d5f6abc”);

change “Jane” to your NPCs first name
change “Doe” to your NPCs last name
change <115, 165, 23> to the coordinates where you want the NPC to spawn
change “d004fdd5-c08c-45c8-9ab2-7b1f4d5f6abc” to your NPCs UUID

(5) Save and then close the script.

Your NPC is now ready to spawn and speak. It’s not much, but it’s a start :)

Spawning & Controlling The NPC

(1) Use the following command in local chat to spawn your NPC:
/10 create

If all went as planned, your NPC should spawn at the coordinates you indicated in your script.

(2) Use the following command to have your NPC speak:
/10 say

They should speak the pre-programmed line of text, found in the script above.

(3) Try the following command & you’ll see that it’s currently not working:
/10 move

This _should_ autopilot the NPC to a new location, but does not…

(4) Use the following command to remove the NPC:
/10 remove

NPC Test 003

several cloned NPCs, missing hair attachments

Animating The NPC

Now, I did not cover the other existing command, animate, because there’s still more to be done if you want to use it… In order for the NPC to execute an animation, that animation file must exist in the NPC Starter prim’s Contents.

(1) Edit your NPC Starter prim & open the Contents tab.

(2) Drag & drop any animation you’d like to use into the contents of the prim.

(3) Edit the NPC Controller script & find the following snippet:
osAvatarPlayAnimation (npc, “stand_1″);
llSleep(3);
osAvatarStopAnimation (npc, “stand_1″);

(4) change “stand_1” in both places to the name of the animation you placed in the prim.

(5) Save, Reset, and close the script.

(6) Spawn another NPC with the command
/10 create

(7) Wait for it to rez completely & then issue the following command:
/10 animate

Your NPC should perform the specified animation for 3 seconds and then stop.

When you’re done, you can remove your NPC by issuing the command:
/10 remove

As I’d stated earlier, I was able to create multiple copies of the same NPC by using the
/10 create
command over and over again, but I could only keep control of the last bot that was spawned (ie, I could not remove or animate any of the previous bots, who would remain standing there until the simulator was shutdown).

Uses For The Existing NPCs

While the existing NPCs certainly seem to be exceedingly limited, I could see them being used for quite a few purposes, such as greeters & information points, “quest givers” and the like. I have not tested them to see if they have their own “health” meters, so I’ve no idea as to their potential “mob” uses, but since they currently don’t move anyway there’s not much use for them there anyway…

Since the NPC is controlled via scripts in an in-world object, I’m sure that the above script could be elaborated upon to perform a number of tasks. My next task will be to see if I can directly tie in some chatbot functions or perhaps direct it out to an existing AIML (artificial intelligence markup language) chatbot elsewhere (ie, Pandorabots or my local Program E and Program # installations).

OpenSim

The Future Of OpenSim NPCs

While I am certainly thrilled that OpenSim is interested in implementing server-side NPC code (woohoo!!), I also think the entire current implementation will have to be rethought & then recreated. For one thing, I’m none too sure as to why the current developers decided that the NPCs should be spawned and created from within the simulator. I imagine it would be better to have this done from the console itself, much like the current “create user” command already does.

Better yet, perhaps creation of NPCs could be handled through an INI file, like the regions are. Maybe something like this:
[RegionName NPCs]
NPC_firstname = “Jane”
NPC_lastname = “Doe”
NPC_UUID = “d004fdd5-c08c-45c8-9ab2-7b1f4d5f6abc”
NPC_spawnpoint = <115, 165, 23>
NPC_scriptfile = ./npc-scripts/Jane_Doe.lsl

Just a rough idea… I honestly have no idea how the existing code works & haven’t taken the time to compare the old & new versions of the source to see what’s changed, let alone how it might be fixed… But I believe that if the code is going to be improved & expounded upon, then it’s up to those of us who are interested in the project to roll up our sleeves and see what we can do.

If memory serves, OpenSim itself is built using the libopenmetaverse library, and so we should be able to copy/hack/paste portions of existing code into place to get whatever we want out of it… Granted, my experiences with this are limited to creating client-side bot programs and little more, but certainly that’s something to think about. I’ll be poking around at the existing code further and will post my results, whatever they be.

I, for one, do not consider myself a programmer by any stretch of the imagination. I’m a hard-core tinkerer with an eye for patterns and anomalies. I learn by taking things apart & seeing how they work, fiddling around until functions become apparent. I also research until my eyes hurt & persistently ask questions of those who know more than me (just ask anyone I’ve hounded on IRC haha).

That said, if anyone out there wants to bounce ideas off of each other & see what we can do to improve OpenSim server-side NPCs for everyone, I’d be quite happy to discuss it. Drop me a line here or directly via email: kpr2[at]kennethrougeau.com

Have fun & I’ll see you around the metaverse!
- Ken

Kenneth Rougeau - opensim

Kenneth Rougeau - Off the Grid


Similar Posts:

Add to Del.cio.us RSS Feed Add to Technorati Favorites Stumble It! Digg It!
    www.sajithmr.com

Tags: , , , , , , , , , ,

2 Comments on OpenSim Server-Side NPC Experiments: Day Two

  1. Nilmara Salgado says:

    Help with NPC (OpenSimulator)

    Good morning,

    I am studying NPC (OpenSimulator). However, when tested NPC + notecard my avatar turned “red smoke”. I’ve tried several things and not restore.

    It has happened to you?

    I’m there some days with this error
    thank you very much

    • Kenneth Rougeau says:

      Hi there. I haven’t been experimenting with OpenSim much lately, though I have meant to return to it and see what new advances have been made. I wish I could assist you further with your own NPC, but I’m not sure just what the problem might be off of the top of my head. Best of luck to you!

Leave a Reply

css.php
  • RSS
  • Twitter
  • Facebook
  • LinkedIn
  • MySpace
  • Flickr
  • DeviantArt
  • YouTube