Join us in Outworldz at www.outworldz.com:9000 or follow us:

Best Tools for Open simulator - NPC maker for Open simulator

These notes on the NPC Recorder and Controller script is from a presentation on 11-8-2015.

Hello everyone. My name is Ferd Frederix of the Outworldz grid, and I also answer to “Fred Beckhusen”. I’m the President of www.Mitsi.com, a high tech microprocessor design company near Dallas Texas. I have been scripting in virtual worlds for almost 10 years now. You probably first knew me from the open source scripts I maintain at Outworldz.com.

Today I’ll go over some of the features of the NPC controller I developed to run the Outworldz. We used it a lot in the HyperGrid stories as an engine to run NPC’s.

These are just a few of the scripts for NPC controllers that were used to build the Hypergrid Stories. A lot of that code found its way over from the Outworldz, and I am very grateful for the opportunity to contribute. Open source software needs to be used and beat on, and I need the feedback from user to improve it.

I’ll touch on some of these scripts and also a few that didn’t make it to “The Stories” but my focus today is going to be on the All-In-One Recorder. I’ll mainly talk about where it came from what has changed recently, and where it is going.

Please hold any questions until the end, at which time I'll be happy to answer any general questions you might have. For any deep questions that are beyond a general audience level., please speak with me afterwards or email me at fred@outworldz.com and I’ll be happy to help you.

So lets get going!

 

The original script “Puppeteer” came from Wizardry and Steamworks people. It is licensed GNU GPL, which means that you have the freedom to run, copy, distribute, study, change and improve the software.

They make wonderful stuff, and have a large library of scripts at grimore.org and at http://wiki.secondlife.com/wiki/Category:Wizardry_and_Steamworks

I have open sourced a lot of the other scripts such as the alligator attackers in Scene Three, and all the Scene Nine and Scene Three scripts are open sourced and will be published as GPL scripts on the Outworldz Script library.

So what is it?

You need one script, a walk and a stand animation and that is all it takes to make a NPC walk around, sit on things, and chat. It is both an engine and a recorder, so you can slide it around and click it, or just wear the prim on your HUD display. You walk or fly around and click the prim to save your new NPC path. There are 27 commands you can choose. After recording the program, you click Save and then Start, and your NPC will appear and follow all your instructions.

It simplifies complex tasks, such as walking, down to simple Macro-like commands. Walking a NPC requires a lot of scripting because it can get stuck. The recorder will delete it and start over if that happens. It detects when the avatar reaches the destination, and ignore things like Z axes because things tend to move up and down a bit.

The Recorder saves all this in note cards. Once you get familiar with it, you can type or edit the commands into a note card by hand. I find it easiest to walk around and use the recorder to program the routes, and then tweak the note cards by hand

One of the really important new things Nara Malone asked to be added is for a note card to load another note card. Each note card then can thought of as subroutine. Neo Cortex added this feature and sent it to back me. I can tell you that out of the thousands of scripts I maintain in the library, from over 500 authors, this one note card trick its one of the best things every contributed to the library. I am really proud of the collaboration on this project and what it has done to help everybody.

I’ve been working for a very long time, almost two years now, recapturing this code to get it to use link messages as input. I really needed it for our the Outworldz Sims. Link Messages make it very easy for your NPC to interact with people when they touch or bump an object. We have it now, it works. It is so new I have yet to add it to any of the Outworldz, and I am really looking forward to working on that next. I have lots of plans for it and this script is updated very frequently. So here is a tip. Name it NPC something or other, and you can drag and drop a new version into the old prim and it will update itself and delete the old script. That is “NPC whatever” where NPC is all CAPS.

So now you know the secret behind a lot of the Hypergrid Story actors. We change note cards when people bump objects that send a link message.

Here is a sample “Hello World”.

You can record this by pressing the Record button, the Say button , type “Hello World” and then click Save to save it into the !Path Note card.

The note card will look like this:

@spawn=FirstName Last name|<0,0,0>
@say=Hello World
@stop

The first line is the name of the NPC, which can be one or two words, and where it will rez in.

The next @say line should be obvious, but why is there an @stop? I put that the note card will normally loop back to the beginning and repeat. So the @stop makes it quit processing and shut down. This is also a great feature, since as a Link Message can wake it back up again, which we will go over soon.

You can also put in an @delete and the NPC will appear, say Hello World, and disappear.

This simple !Path note card is almost the same thing as a Pose ball with a person sitting on it. The controller will create a NPC, sit it on the Dance Ball, play an animation for 10 seconds, then repeat.

To me, the key to a great NPC is to not have them standing there on a pose ball and dancing. They need to interact with people. They need to Communicate. The need to have outputs and inputs, such as these useful output commands. I’ll get to the inputs next.

This is the big difference between simple NPC’s and this recorder. Since you can inject commands into the NPC on the fly, other scripts such as Aine’s PMAC system can control or make an NPC talk.

It’s now possible to have a realistic artificial life system in Open simulator. Two or more NPC's can talk to each other by listening to what one NPC says, generating a response and sending it back out. NPCs can move about, and live. I recently had to go over to scene there and add ‘ignore NPC chat’ code to the Chat bots that were carrying on a conversation with each other - AI to AI. I had a very pretty fairy Chat bot named “Queue” that arranged herself a Friday night date with an unsuspecting soul. I was really happy to see her pass the Turing test that day.

I used a fairy Chat bot in Scene three along with several other fairies helpers to give out tips to get past the obstacles People don’t know to chat to it, though, since Chat bots always respond to something you say. And if you say nothing, nothing happens and you walk right by. A Chat bot also sends a message in colored chat from the script, and people can spot that it’s a script doing that by the color of the text. But NPC's type in white, just like an avatar. So I used this same NPC controller script to make a Chat bot fairy helper. The command to so this are pretty simple:

@spawn=Windy Fairy|<0,0,0>
@sit=Tree trunk
@stop

This sits the fairy on the tree trunk. It stops. The only other change to get this work is replace the Chat bot scripts llSay command with a link message:

llMessageLinked(LINK_SET,0,”@say=“ + message,””);

This makes the fairy speak to the avatar in white. There is another linked prim in there. I used a collision script to send an @say command through the fairy when you approach her. This is used in several places. There are help messages in other prims so when you bump them the fairies walk out, give you a hint, then leave. This is the key to controlling a NPC – invisible prims that people bump into. I used this a lot to make NPCs move about when an avatar arrives somewhere. So let’s talk about movement for a bit.

Three of these movement commands shown here are new and came from collaboration with Hypergrid Stories people. I’d like to thank everybody there for the wonderful art and ideas – so many it was overwhelming for me.

First up is @teleport. It moves a NPC quickly to a coordinate in the same region. It won’t move it to another sim, dang it. Then along came Hypergrid Stories, and Nara needed to get a NPC from the end of a long story back to the start, and to do it quickly. So we added @teleport. That new command also proved invaluable to me when I had to get a NPC back to the start of a scene.

I also added the @Speed command so tinies and giants can speed up or slow down when they walk correctly. And it’s very useful for birds, too, so they can fly slowly so you can see them. I plan on having tiny fairies flittering about and living in our fantasy sim “Mothergoose” soon. Real ones, this time.

And of course the @touch command is really useful to open doors. That also came from Hypergrid Stories, I think Neo and Nara came up with it. I had always done that in a much more difficult way. This is the beauty of collaboration and open source. We have fairies.

So where do fairies live, and how do they get there?

There are two coordinate systems in the NPC recorder. You set which one to use, in the menu, once. After that, all of the @walk, @run and other coordinates will be based on the position you type or record from the sims perspective or the prims perspective. For absolute mode, the vector < 0,0,0> is the lower left of the sim. The other setting is relative coordinates, and <0,0,0> would be zero meters away from the NPC Prim. So here is a tip: if you find your NPCs all standing around having a prim party at <0,0,0> or near that location, then the menu most likely needs to be changed to the Relative setting, which uses positions that are usually much smaller, like 0,0,0.

Absolute coordinates sounds complicated, but they are easy and familiar. I usually rez a box where I want the NPC to go, and click the little C next to the coordinates in Firestorm, and paste it in the note card.

So if that is so easy, why is there another coordinate system? Because making a herd or a marching band or anything that moved from sim to sim would be hard to do. Absolute specifies every point and sometimes they need to be shifted around. In Relative coordinates, all of the @walk, @run and other coordinates will be based on the position you type or record from the prims perspective. So <0,0,0> is the position of the prim the NPC script is in, and the NPC would appear there.

The above script rezzes the NPC right on top of the NPC box , at <0,0,0> because this prim was set to relative mode coordinates. This is relative to the prim itself, and not the sim. With relative coordinates, all we have to do it shift copy the prim and a second animal will appear and walk next to the other one.

Actually it is a lot of fun to change the last number to a much higher value and watch you NPC fall from the sky. The first time we had a large herd of Zebras going, Debbie stayed up all night to watch them play. It was a simple @wander in relative addressing, with a bunch of shift copies to make a entire herd of zebras. It had a really high cool factor for two lines of NPC language

So if you see any of my herd animals, rats, cows, or avatars at the absolute position of zero, zero zero, you know I forgot to click the menu and make it relative

Here is another great example of when you want to make a NPC move relative to the prim itself and not the sim. I have some sheep that love to follow you. The are “I Love Ewes”. Could be a cat, or a dog, or a mooFerd cow, or any pet NPC.

If the prim that held the above script had a avatar “sense and follow” script in it, the prim would follow the avatars waist. The NPC would try to walk to one meter behind the prim on the Y axis. When the avatar moves, the prim will follow the avatar, and the pet will follow the prim, because the @walk is relative to the prim and not the sim.

So we have discussed the various Outputs so the NPC can be seen to move, sit, walk, make sounds and all that. But how do we interact with our NPC to make in Interactive story? We need it to react to the avatar, to change the behavior as the avatar walks around, sits on things, to make things happen.

Hypergrid story also needed inputs. Lots of ones. So I came up with about a half dozen very simple scripts that send an @ command to the controller when events happen.

We used them to make an @say go to a NPC when you walk into a room. You can use it to have a waiter come over when you sit in a chair. And even more useful is the ability to issue an @note card command to change to an long list of things to do. We also used a HTTP to and from a web server to make games and send chat in the Hypergrid stories.

But how does the NPC get these input commands?

Link Messages

A link message is a simple LSL command that is used almost everywhere. You can add it to any script it to send any command to the NPC

It looks like this:

llMessageLinked(LINK_SET, 0, “@say=Hello World”,””);

And how do we steer the commands to control lots of NPCS at the same time, asynchronously, as the avatars interact with the world?

Turns out its really easy. You can link in additional All-In-One NPC prims! Then the link message command can be used to send to any one, or all of them of them based on Link Number:

llMessageLinked(LINK_SET, 4, “@say=Hello World”,””); for NPC linked in as number 4.

llMessageLinked(LINK_SET, 5, “@say=Hello World”,””); for NPC linked in as number 5.

This has since been extended with external scripts by me, Neo and Amine into NPC sequencers that control many NPCs in parallel. I won’t get into gory details here, but they work by these same link messages, and those scripts extend the command syntax into a who, what and when. Such as NPC, the time, and a command to execute. I have since extended this idea into another controller used in scene 9 that supports NPCs by name.

That type of code looks like this:

Castle Guard, 2,@animate=draw sword|2.

Castle Guard, 1,@say=Stand back!

These cause the Castle guard to draw his sword, wait two seconds, play a typing animation for one second, and say “Stand Back!”

So we use the LSL command for Link Messages. Big deal. Every LSL scripter knows about link messages. How do we use them in a game or to tell stories?

We use Invisible stuff. Secret stuff. So here is a scene from Hypergrid stories. The writers told me it has three NPCs. They have to wait for the avatar to rez in, greet the person, move around, tell a bit of the story, and get then to go down the path. Then when they start to walk Lead the avatar out. Lead them Out. That’s a bit like making a prediction. It’s not easy. Especially about the future.

But there is an easy way to do this. I put an invisible Collider prim that surrounds the teleport arrival location. When the avatar rezzes in, the avatar will surely move and bump that circular prim. We know they can see at that point in time. This triggers all three NPCs to start up by switching note cards with a LINK_SET, so all NPCS hear it. The code that does all that looks like this:

llMessageLinked(LINK_SET, 0, “@note card=Greetings”,””);

That’s it. It makes all three NPCs start their stories… Its kind of unbelievable that all that is really handled by one link message and a simple collision.

This is the actual layout of Scene three at the start. The colliders are the ring and two other prims.

The ring detects the initial movement of the avatar which usually occurs when the avatar can see.

The one on the left sends the raccoon ahead for the avatar to follow. The one at the bottom tells them to go back and stay on the path.

That’s the secret for NPC input control. Use Invisible prims – they are easy to move, easy to position, and easy to program with one simple @say or @note card command. Or any other command you want.

Scene nine is only a bit more complex. It is a party scene, and the NPCs have to get the avatar to one particular spot so he can take control of them. To make it seem more real, there are many more prim colliders here. They make the dancers at the party seem like real people by shouting out greetings when you walk in. You know, the usual “Hey! Look what fell in”, and “Your toenails need work, dude”, you know, that kind of things that old trolls like me hear all the time. The first three on the far right send commands to Namakwa and Dylan, our story tellers, and they tell the avatar what is going on. The others are for speech from the NPCs on the dance floor, where there are 6 dancers, for 8 NPCS all together. We know the avatar will have to walk down the long yellow path to get to the party. As they walk, they trigger various NPCS into chattering a bunch of idle chit chat, with random number generators

The rest is a new sequencer script with the “who, what, when” code to send various @walks to move the NPC around and switch note cards. It’s only about 100 lines of code.

So now you know how to move a NPC about when someone touches, chats or bumps something in the night. What else can I tell you? I have some tips I’ve picked up in answering the many questions that come by email and the comments on the web site.

Do you like rabbits? Because this is how you get great big piles of rabbits. And turtle. If you are wearing the NPC HUD and record your appearance, it causes this along with hair loss and gross toenails. Don’t do it. The HUD you are wearing will record the new appearance of a NPC wearing a HUD. So you end up like I did with piles of rabbits. Or whatever it was before you recorded a new appearance.

If you realize you are wearing the recorder prim and have clicked the Record Appearance Button, stop. Take it off, put it on the ground, and then re-record the appearance. I really need to add a code check to make sure that does not happen. Or else you get rabbits. Lots of rabbits. These are just the remaining rabbits that had not yet fallen off the roof. There’s lots more on the ground.

It took me several long days to figure that out. In spite of 40 years of programming experience, I am still not a smart man when it comes to detecting rabbit and turtle recursion.

While you are at it, look in Appearance at what you are wearing. Get rid of everything that is not essential. Face lights, scripts, clothing, HUDs

Always put on an outfit and take it all off and put it on again. The positions and changes you make are not saved to the server until you take it off, and the Appearance note card won’t be correct unless you do this simple step.

This is really new stuff here, and I am still learning this, too. One thing I learned from Hypergrid Stories is to keep it simple. I used to make one note card with lots of @stops and @go and even used a few @gotos. But it’s really a lot easier to make two line note cards that rez a NPC and then @stop. Then build a new note card to do something simple and trigger it with a collider or a sensor and send a new note card with @note card. It’s more modular, and much easier to debug. You can easily add more notecards and build up your own herds of people.

Another thing to remember is that there are bugs galore in Open simulator. One of them that will haunt you is the Unknown User bug. It shows up because the Real Names section of the server quits working after a while. So an @delete will rebuild the NPC, or you can use @reset to hard-reset the script and make the NPC have the right name again. A simple external timer script can be set to send this by a link message every so often.

Open simulator is really Alpha software, everybody. So help me help you and others by telling me about bugs. Use the comment section on the web site, Google Plus, or email me, send me code, lets talk about it, please.

One thing I notice a lot in sims is they are not very optimized. Textures are all too large. There are trees with individually modeled leaves for sale on Kitely at their show room. For sale. Holy cow. Monstrous trees. In addition to lag monsters like that, there is a lot of bad physics floating around in mesh. NPCs need help with physics, especially mesh physics.

There were thousands of vertexes in each of these mesh steps, and now there are 8. Make your server happy and your NPCs happy. Check your physics. All the giant rocks in this sim that people walk on are phantom now. Make your server happy right now, go set everything to Phantom. And then un-phantom some of them or replace the floors and such with invisible prims so you can walk again.

If you dig into the Open simulator source code you will find out why your NPC rabbits fall through ceilings. They are made to be low lag and so the set their vertical position at ¼ the rate of an avatar. So they tend to sink through objects.

Bullet also has problems with mesh that is tilted in two directions. Tilted mesh, especially in two planes at the same time that is steep, is very more easy to fall through, even with high physics set at upload time. The only solution I have found is to avoid tilted mesh, put land up against it, or prop it up with prims.

We’ve covered what the recorder is, a bit of how to use it, and now, where is it going? It is really up to you, just as much as it is to me. It is open source, so you can change it as you want. And hopefully help me squash some bugs. Please, let me know about your changes. It’s actually very rare for people to send me code patches. Neo was the first person in a long time, and I really, really appreciated it.

But I do have some ideas what could happen next.

@sync would be nice to get the avatars to be all in the same state. It would help with a marching band that has to turn a corner, for example.

I think that @follow and @lead are obviously useful commands. Its just a bit of rotation math to make it lead you, or follow on one side. I used this type of logic in Second Life to make birds fly around and land on my arm. I’d love to see that here again and watch them land on my Book of Magic. I can do it with prim birds and an old script. But NPC birds have realistic wing and leg movements. Bird flight can be very beautiful, especially in a virtual world. NPCs birds could look very real here.

I don’t think that Pathfinding will ever come to Opensimulator. But a rudimentary one could be added to the system with llCastRay, if it ever gets released. I heard it is finally working.. That would probably be best done by an add on script.

I mentioned some other NPC scripts when I started this talk . There’s a lot of them, so many I could talk for hours, But one game we have been playing for many years in Second Life and that is finally here also happens to use NPCs. It’s being introduced at the Avatar Fest next week. Look for the ship that’s frozen in ice. You can click-fight the NPC skeletons for their treasure.

We have a larger one in the very depths of the mountain at Phaze Dragons to play with too, with lots of monsters.

We just put online two new levels at the Frankie game sim in the Outworldz, using NPC code originally developed for Hypergrid story

So that what we just did, there is still a lot of things to finish, then there is what I want to do

NPCs are perfect for Machinima. A friend of ours, Su Didi is from the UK , and she lives in the Outworldz. She asked us to help remake an old British TV show, “Bill and Ben, the Flower Pot Men” which was no longer protected by copyright. It was a lot easier to do with NPCs and the all in one than with live people. For one thing, the NPC would open doors with @touch perfectly, but we humans were too busy laughing and crashing into walls and blaming each other on who was supposed to click the door this time and missed it or forgot. That was huge fun, but the film was always off just a bit. With NPC’s each ‘take’ was be repeated perfectly, then tweaked until it was what I wanted.

So that’s what we just did with NPCS, then there is what I want to do next.

We almost have a Dinotopia sim ready - we still need to add NPC people and more NPC dinosaurs. You can visit us in the Mother Goose sim that connects to Dinotopia, just take the bridge across, and try the five passenger NPC Apatosaurus dinosaur now. We’ll have more there along with our first shop fill of freebies very soon.

What else? Its mostly practical NPC development to wring out more bugs.

We are going to back through the Outworldz and add what we imagined years ago. We want the village to come alive with NPC people. People that live there, wash clothes and try to sell you something. We want the Virunga Lodge clerk to check guests in, we want Ruh and Geri to take guests to their rooms to get the supplies they need, we want a virtual waiter to serve them dinner and a virtual guide to take you on a wild ride and then a hunt in our Virtual Africa for the endangered mountain gorillas of the Virungas. With cameras of course

We have the technology now.

Thank you everybody, for coming and listening to me. I’ll open the floor to questions and remember, contact me, fred at mitsi.com with bugs and fixes, please!

Back to the Best Free Tools in Second Life and OpenSim.