Zadock,
here is the meat and potatoes, and for anyone else who has never created a NPC bot and have him walk around.
first you need to make 2 or 3 changes to your OpenSim.ini file
find the [Xengine] section and make sure it is enabled = true
also set AllowOSFunctions=true
finally OSFunctionThreatLevel = VeryHigh
Save the .ini file
now find the [NPC] section and if its not already set, make it so. Enabled = true
and make sure the semicolon is removed from in front of those lines. (uncomment)
now fire up your sim
Rez a box, Edit, Create new Script.
Wipe out whats already on the script and paste in this
Code:
key npc;
default
{
state_entry()
{
llListen(10,"",NULL_KEY,"");
}
listen(integer channel, string name, key id, string msg)
{
if (msg != "")
{
if (msg == "create")
{
osOwnerSaveAppearance("appearance");
npc = osNpcCreate("Jane", "Doe", <115, 165, 23>, "appearance");
}
else if (msg == "remove" && npc != NULL_KEY)
{
osNpcSay(npc, "You will pay for this with your liiiiiivvveeessss!!!.....");
osNpcRemove (npc);
}
else if (msg == "say" && npc != NULL_KEY)
{
osNpcSay(npc, "I am your worst Nightmare!!!!");
}
else if (msg == "move" && npc != NULL_KEY)
{
osNpcMoveTo(npc, llGetPos() + <9,9,0>);
}
else if (msg == "movetarget" && npc != NULL_KEY)
{
osNpcMoveToTarget(npc, llGetPos() + <9,9,5>, OS_NPC_FLY|OS_NPC_LAND_AT_TARGET);
}
else if (msg == "movetargetnoland" && npc != NULL_KEY)
{
osNpcMoveToTarget(npc, llGetPos() + <9,9,5>, OS_NPC_FLY);
}
else if (msg == "movetargetwalk" && npc != NULL_KEY)
{
osNpcMoveToTarget(npc, llGetPos() + <9,9,0>, OS_NPC_NO_FLY);
}
else if (msg == "rot" && npc != NULL_KEY)
{
vector xyz_angles = <0,0,45>; // This is to define a 45 degree change
vector angles_in_radians = xyz_angles * DEG_TO_RAD; // Change to Radians
rotation rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
rotation rot = osNpcGetRot(npc);
osNpcSetRot(npc, rot * rot_xyzq);
}
else if (msg == "animate" && npc != NULL_KEY)
{
osAvatarPlayAnimation(npc, "stabbed+die_2");
llSleep(3);
osAvatarStopAnimation(npc, "stabbed+die_2");
}
else if (msg == "save" && npc != NULL_KEY)
{
osNpcSaveAppearance(npc, "appearance");
}
else if (msg == "load" && npc != NULL_KEY)
{
osNpcLoadAppearance(npc, "appearance");
}
else if (msg == "clone")
{
osOwnerSaveAppearance("appearance");
}
else if (msg == "stop" && npc != NULL_KEY)
{
osNpcStopMoveToTarget(npc);
}
else
{
llOwnerSay("I don't understand [" + msg + "]");
}
}
}
}
This script is taken directly from the wiki, I had nothing to do with writing it , its a bit clunky but its good enough for a first bot. I havent modified it in any way, you can do that.
Now heres a crash course in scripting.
Firstly understand the vector coordinates (where you are on the region) 3 part number giving x and y and z(height) coords, example if your land is at 25 meters high and you stand in the exact center of the region your coords are 128,128,25, and this is always expressed as a vector <128, 128, 25> this is extremely important because of bot navigation, you'll play with a few vectors in the script, so for this exercise, move your avatar to close to <115,165,XXX> (where x is just standing at ground level) this is because thats where the bot will rez.
Read the script carefully from the top and find this part
Code:
llListen(10,
thats telling us the script is listening for commands on channel 10, (change this if you feel the need) this means any commands are typed into chat with the prefix /10 (slash ten)
read on to
Code:
if (msg == "create")
this line says "if the message is 'create' then do it" so to create a NPC simply type /10 create, (space between /10 and create) and it wont display anything in chat because thats channel 0, message gets sent to the system.
Anyway the magic has happened and a bot has appeared on the scene. (hopefully)
Any changes you make to the script wont take effect until you remove and recreate the bot (rebot

)
scroll down the script a little and find this conditional
Code:
else if (msg == "say" && npc != NULL_KEY)
{
osNpcSay(npc, "I am your worst Nightmare!!!!");
}
thats saying (if anyone types "/10 say" into chat then bot says "I am your worst nightmare" so whatever you change that line to, the bot will speak it on the "/10 Say" message.
the next line reads
Code:
else if (msg == "move" && npc != NULL_KEY)
{
osNpcMoveTo(npc, llGetPos() + <9,9,0>);
}
so whenever you type "/10 move" the bot will move 9 meters North and 9 meters East. Obviously change these dimensions to suit yourself.
Lets add a new command, copy and paste this in right after that command (make sure the code goes in after the curly brace "}" and before then next "else if")
Code:
else if (msg == "back" && npc != NULL_KEY)
{
osNpcMoveTo(npc, llGetPos() + <-9,-9,0>);
}
So typing /10 move makes him move north east, and typing /10 back makes him move back south west.
llGetPos() means "get the position where it is now" so the whole line says "from wherever you are now, move 9m East and 9m North, (or -9,-9 which is south west) that can be modified to put the bot in an absolute position instead of relative to where he is standing, by removeing the llGetPos() + and setting the vector to an absolute say <128,128,25>
Code:
osNpcMoveTo(npc,<128,128,25>);
and on command he will walk directly to the middle of the region.
To make him walk back and forth between 2 places lets add another 2 commands
Code:
else if (msg == "middle" && npc != NULL_KEY)
{
osNpcMoveTo(npc,<128,128,25>);
}
else if (msg == "somewhere" && npc != NULL_KEY)
{
osNpcMoveTo(npc,<88,90,25>);
}
When you type /10 middle, he moves to the middle, type /10 somewhere he moves to that place, and so on
We have played with 2 ossl functions here osNpcMoveTo() and osNpcSay(), that should be enough to get anyone started. This script and other essential reading can be found here
http://opensimulator.org/wiki/OSSLNPC Hope theres something in there for someone
Cam