The girl with the big afro is a scripted NPC

Mini Tutorial: How to create a NPC (Non Playing Character)

[Update 04-07-2013: I have added a NPC kill script to the download. To delete all the NPC’s on a region, drop the NPCkill.lsl script in a prim and touch it.]
[Update 10-07-2013: Replaced the NPC puppeteer script with an updated version. Some bug fixing things.]

Hi @ all!

Cool thing you might wanna know: I have a guitar museum on Metro, and I have Jimmy Page walking around there and do stuff!

Like this on your favorite social media thing! Make it trending and stuff.!!

Another cool fact is that you can have a celeb walking, dancing, talking, etc, etc on your region as well! (like this too on your preferred social media! This won’t work on Tell-sell channels though!)
And it’s really easy!

Just a couple of scripts, an avatar that you can copy, a notecard and a prim to control the NPC.
That’s it!
No huds, no resetting scripts after a region restart, no fuzz. Just create a copy of the avatar you are using, tell it what to do, and forget about it!

Snapshot_001

 

Doing some groundwork.
First you will need to download some things and check your server if you are able to use these scripts.

There are 3 scripts in the zip file.

  1. OSSLFunctionCheckThreatLevelVeryHigh.lsl- This script checks your server if you are able to use the scripts. If you run your own server, you can change things, more about this later. Script Author: Shelenn Ayres
  2. NPC Appearance Generator Script.lsl – This script generates a notecard with some info about the NPC. (shape, skin, clothing, attachments, etc)
  3. NPC Puppeteer Script.lsl – This is the main script.

 

Unzip them to your hard-drive.
Create 3 empty scripts in your inventory, name them as the scripts on your hard-drive. Copy and paste the scripts from your hard-drive in the scripts in your inventory.  (you can open the scripts with notepad or a similar program.)

Also, create a notecard and name this Script (case-sensitive)

Find a nice standing animation and rename it to Stand (case-sensitive)

Find a nice walk animation and rename it to Walk (case-sensitive)

About OSSL functions.
The scripts in this tutorial assume that NPCs and OSSl scripting is enabled in the OpenSim configuration. In order to enable them, the following changes must be made in the OpenSim.ini configuration file:

    ; Turn on OSSL
    AllowOSFunctions = true

    ; This can be further filtered for
    ; just the NPC OSSL functions needed.
    OSFunctionThreatLevel = VeryHigh

[NPC]
    ;# {Enabled} {} {Enable Non Player Character (NPC) facilities} {true false}
    Enabled = true

You can use the OSSLFunctionCheckThreatLevelVeryHigh.lsl script to test your server in-world. Create a prim and drop the script in it. Watch local chat to see the results.

Snapshot_002

 

More information about Thread levels can be found here: http://opensimulator.org/wiki/Threat_level and here you can read about enabling functions: http://opensimulator.org/wiki/OSSL_Enabling_Functions

If you don’t have access to your server, you’ll have to ask the person who does have access to do the necessary changes for you.

Creating the NPC.
Here begins the fun!

Create a prim on the ground and drop the NPC Appearance Generator Script.lsl in the content tab of the prim. DO NOT TOUCH IT!!
Now you can go wild with your appearance. Change shape, skin, clothing, hair, etc. (The NPC I have walking around is wearing a spanker! lol)
When you are satisfied with how your NPC is going to look, touch the prim.
This saves all that info in to a notecard called ‘appearance’
Remove the NPC Appearance Generator Script.lsl from the prim.

Telling the NPC what to do where.
This system uses a notecard to tell the NPC what to do.
Here is a list of what is possible: (Command – Example – Result)

  • @spawn – @spawn=Alter Ego|<137.262848, 132.939011, 22.705553> – Will rez an NPC called Alter Ego at the coordinates <137.262848, 132.939011, 22.705553>
  • @walk – @walk=<138.980637, 137.669067, 22.77791> – Will make the NPC walk to the coordinates <138.980637, 137.669067, 22.77791>
  • @say – @say=OMG, Oddy is soo cool! – Will make he NPC say on local chat OMG, Oddy is soo cool!
  • @pause – @pause=2 – Will pause and stand for 2 animation cycles.
  • @stop – @stop – Will halt all script execution leaving the NPC standing.
  • @delete – @delete – Will delete the current rezzed NPC.
  • @animate – @animate=Dance,10 – Will trigger the animation in the primitive’s inventory named Dance for 10 seconds.
  • @goto – @goto=LABEL – Will jump to the label LABEL and consume the jump.
  • @rotate – @rotate=90 – Will rotate the NPC 90 degrees around the positive sense of the z axis.
  • @sit – @sit=Chair – Will scan for an object named Chair and will make the NPC sit on it.
  • @stand – @stand – Will make the NPC stand up if it is currently sitting on a primitive.
  • @wander – @wander=3|1 – Will make the NPC wander in a 3 meter radius for 1 animations cycle.

Here is a notecard I am using:

@spawn=Big Afro|<42.5899, 120.153, 21.75>
REPEAT
@walk=<39.2955, 127.519, 21.75>
@pause=3
@walk=<39.2955, 147.878, 21.75>
@pause=1
@walk=<47.75, 159.75, 21.75>
@say=OMG, this is cool!
@pause=5
@walk=<67.75, 147.75, 21.75>
@pause=1
@walk=<67.75, 107.646, 21.75>
@say=Ah! Useful stuff here!
@walk=<40.2822, 107.646, 21.75>
@goto=REPEAT

I have added the label REPEAT after the first line so my NPC will start over again after it complete all the commands in the notecard.

Save the notecard!

Putting things together.
Edit the prim you used for creating the appearance notecard. Check if the notecard is still in the prims content tab.
Drop the Stand and Walk animations and the Script notecard in the prim.
Finally, add the NPC Puppeteer Script.lsl to the prim.

Putting things together.
Putting things together.

If you have to reset the script for some reason, delete the stuff that is in the description field of the prim before resetting!

Have fun folks!

 

14 thoughts on “Mini Tutorial: How to create a NPC (Non Playing Character)”

  1. Great stuff!! I am just trying it out. But there she stands , goes, says … I used the REPEAT like you, then unfortunately deleted the box in order to delete HER … but there she stands! refuses to leave! Another same box with just @delete on the card didn’t help. How do I get RID of her??

    1. I received all the stuff you have send me in Metro, no worries:-) You’ll have a shop assistant soon!

  2. Found some bugs:

    The @sit command will fail to sit in some circumstances. The bug is in line 256:
    llSensorRepeat(wasKeyValueGet(“sit”, llGetObjectDesc()), “”, PASSIVE|ACTIVE, TWO_PI, 96, 1);

    It is scanning not 96 meters, but 6.26 (TO_PI) and the spherical area is not a sphere.

    The fix is to swap the TWO_PI and 96 as follows:
    llSensorRepeat(wasKeyValueGet(“sit”, llGetObjectDesc()), “”, PASSIVE|ACTIVE, 96,TWO_PI, 1);

    Also, the ‘help’ says to use a comma in @animate=Dance,10. That is incorrect, it should be @animate=Dance|10, as all commands are separated by a |

    Lastly, the @wander will work only one time. (All his help tips use it only once, aha). If used twice, the NPC will behave unpredictably and wander off a great distance. I am still trying to figure that one out. I suspect a variable is not being re-initialized correctly the second and further times.

  3. Here is another: If the @sit prim cannot be located, the NPC will hang.

    Add this to state sit and it will continue if the prim is missing or out of range

    no_sensor()
    {
    llSensorRemove();
    llSetObjectDesc(wasKeyValueDelete(“sit”, llGetObjectDesc()));
    state script;
    }

  4. Thank you for this great tutorial. One problem I am having is when I make the appearance note card, some of the attachments such as glasses or a sculpt pant legs will rez in the spawn stage in duplicate and then hang in the air. I’m not missing these parts on the NPC -- but the duplicate parts seem to be a part of the overall appearance and can not be remove without removing the NPC.
    I am guessing that perhaps this duplication is a result of duplicate UUID numbers in the attachments in my inventory. Any thoughts?

  5. Try taking off and reattaching everything so the attachment points are saved in the server. Then remake the appearance notecard. And please, let us know if it worked.

  6. Hiya Oddy

    Many thanks for this. I’m using this for NPCs in a murder mystery event in Kitely, and will be keeping some of them running afterwards. Stop by sometime and check out the bartender at the pub, Bart Ander :-)

  7. Hello,

    maybe tthis is a silly question. Can i make the scripts for “How to create a NPC” working in Linden’s Secondlife?

    1. Hello Hakimba. Sorry for the late reply!

      The answer is tricky. You can use NPC’s in second Life, but not with these set of scripts. These scripts are specific for OpenSim…

Leave a Reply