Change font size
It is currently Sun May 19, 2013 7:09 pm

Forum rules


Image



Post a new topicPost a reply Page 1 of 2   [ 19 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: NPCs-help please
PostPosted: Sat Sep 10, 2011 9:27 am 

Joined: Mon Feb 14, 2011 10:47 am
Posts: 12
Greetings everybody,
I enabeld the npc section in the opensim ini and rezzed a clone of myselfe, it looks pretty nice.
Maybe I m a noob :-)
How can I animate the bot or let them walk arround ?
Thx for you help


Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Mon Sep 12, 2011 4:26 pm 
Furious Typer
User avatar

Joined: Mon Aug 10, 2009 11:53 pm
Posts: 171
What exactly are you wanting to do? There are all sorts of commands to get the NPC to do what you want it to do, but of course what end result you want will greatly determine just what your script will look like.

Animating your NPC also requires you to enable osAvatarPlayAnimation and osAvatarStopAnimation - which forces said avatar to perform said animation (in this case you feed those commands the npc's key).

Making the NPC walk or fly is also just a matter of script functions. osNpcMoveTo is the most basic, combined with osNpcSetRot, etc.

There are several working script examples here in the forums if you search a bit. Many of us have been working on some of the more 'iffy' aspects of directional behavior, etc.

Do some searching just a few posts back on 'pointing your nose' and several other posts specific to NPC scripts and you will find others have created nice scripts for NPCs to move, walk, talk, and have even hooked in chatbot scritps!

Take care,

- Hap

_________________
Sorry, I was just thinking upon the immortal words of Socrates who said ... "I drank what?? ... "
- Real Genius


Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Tue Sep 13, 2011 12:05 pm 

Joined: Sat Jul 24, 2010 5:07 pm
Posts: 20
Brian Thefis wrote:
Greetings everybody,
I enabeld the npc section in the opensim ini and rezzed a clone of myselfe, it looks pretty nice.
Maybe I m a noob :-)
How can I animate the bot or let them walk arround ?
Thx for you help


I could post a very long message, talking about how to make an NPC do all that stuff, and more.
However, i think it would be easier to point at http://opensimulator.org/wiki/OSSLNPC , which is a very good place to start reading about all the NPC functions that OSSL has to offer.
Additionally, http://opensimulator.org/wiki/Category:OSSL_Functions may have a few pointers for you as well.

Happy scripting!


Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Mon Jan 23, 2012 7:52 am 
Furious Typer
User avatar

Joined: Mon Jul 12, 2010 4:43 am
Posts: 124
Brian Thefis wrote:
Greetings everybody,
I enabeld the npc section in the opensim ini and rezzed a clone of myselfe, it looks pretty nice.
Maybe I m a noob :-)
How can I animate the bot or let them walk arround ?
Thx for you help

here is a quick and easy script I created to walk your NPC around the block :P
http://forums.osgrid.org/viewtopic.php?p=17369#p17369


Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Thu May 31, 2012 10:59 am 

Joined: Thu May 31, 2012 10:56 am
Posts: 15
As a Noob, reading and searching for everything I can on using NPC's. I dont understand why every reply isnt "learn how to script first" I read a lot of basic how to's, which make me feel like an utter retard, cause I have no scripting experience. So, if you want NPC's might as well learn to script, cause there is no simple explanations out there.


Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Fri Jun 01, 2012 2:42 am 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 391
Location: England UK
Hi Zadock,

You are correct in your assumption that you must learn LSL before scripting, at least to some point. It would be very arrogant of anyone to simply reply to any question 'learn to script first!' Questions are asked and asked in lou of obtaining an answer. The answer is obviously the key to the question, but not knowing the level of LSL experience the 'asker' has usually a generic answer will follow.

If one were to ask the question "how do I create an LSL database driver super computer to run 1000 NCPs on a region. Oh and I havent the faintest clue about LSL"; then the answer would be to learn LSL first. Infact usually asking "how do i create X script" will usually yeild little results, but on the other hand asking "how do I set the color of a prim" would yeild an answer of "use llSetColor, or llSetPrimitiveParams".

Myself, I prefer to give pointers to answers as this enables the 'asker' to learn as opposed to simply copy/pasting. Though I digress. Everyone has different levels with LSL. Myself, I regard myself as intermediate. I have seen some scripts that confuse the hell out of me, but at the same time, I have written some scripts that are simple to me that confuse the hell out of others. I even have some scripts that are a few 1000 lines long and though I wrote them, confuse me when i go to edit them later, as I didnt comment the relevant sections! Yes, I'm lazy that way :|

NPCs are what I would class as mid-intermediate level scripting. Others would think they are easy, some may think not. Creating an NPC script that does one thing, say getting the NPC to speak 'hellow world' is pretty easy. Getting the NPC to move, interact with avatars, run an AI chatbot, sit, use objects etc is pretty complex, though not hard as such. It only seems that way. If you break it down into little bits, each thing as its own entity it makes it much easier. Obviously you need to understand the LSL syntax to some degree to do this.

Learning LSL is pretty straight forward, provided you don't try and bite off more than you can chew. Start small. Make some simple scripts to do things like make prims change colour/alpha. Doors that open/close. A prim that emits light on touch. Also use other scripts as examples of the syntax. Reverse engineer them to learn, though like I said start small. There are some good resources out there such as the LSL wiki that give examples of how to use the code. Don't think you will learn everything over night. Its taken me years of tinkering to learn what I know now and it is only with time and experience will you learn how to script a solution for your problem and understanding the LSL functions needed to create a solution.

Anyway, enough waffle, and sorry for the OT post. Here are some links:

http://wiki.secondlife.com/wiki/LSL_Tutorial
http://wiki.secondlife.com/wiki/LSL_Portal
http://www.instructables.com/id/Getting ... cond-Life/
http://people.cc.ku.edu/~grobe/intro-to-LSL/
http://lslwiki.net/lslwiki/wakka.php?wakka=HomePage
http://opensimulator.org/wiki/Category:OSSL_Functions

_________________
"...And then one day you'll find, ten years have got behind you, no one told you when to run, you missed the starting gun"
~Pink Floyd


Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Fri Jun 01, 2012 3:15 am 
Furious Typer

Joined: Mon Apr 25, 2011 6:48 pm
Posts: 70
Adelle,

That is quality advise, as that is how I learned. I've been developing 20+ years using the same method you outlined above. It's been a great career, and I've worked at some great places.

Zadock, you are absolutely right, but scripting isn't hard. Many times, we look at a task and think, UGH! The reality is that breathing is more difficult than most tasks. It's all in our own perspective. I've taught guitar classes for a number of years. My students tell me the best advise I ever gave was this: Don't go home and practice, go home and PLAY.

The difference in semantics creates a difference in perception. It is that difference that separates those that do from those that do not. Remember the words of wise old Yoda, "Do or do not, there is no try." Trying is a perception that makes a task difficult, and thus leads to utter failure. How many people have you met that are always saying I'm gonna try this or that. Do they EVER succeed?

---SHAMELESS PLUG ALERT--- :D
Having said as much, take a look at my post, http://forums.osgrid.org/viewtopic.php?f=5&t=4192, and give the scripts a try. I'd love the feedback. Take a peek at the scripts, and learn. Who knows, you'll probably teach me something in the process.

There used to be an example simple script on the OpenSim site for the NPC functions. I began playing with that script, which led to the project referred to above. I didn't know LSL when I started that project, waaaay back in Sept. 2011.

Good Luck!!!

Shad MOrdre


Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Fri Jun 01, 2012 8:19 am 

Joined: Thu May 31, 2012 10:56 am
Posts: 15
Thank you Adele and Shad for your advice. i admit to a bit of frustration, when haveing asked a question, I receive a reply to use this or that "function". I didnt even know what a function was four days ago. I am progressing, I have a standalone running and am developing basic building skills as well as looking at very simple scripts. I would also ask that anyone who provides a script, give a basic idea of what to do and where to place it. I was unaware that the prims had to be worn for certain scripts and became very frustrated at how everone was enjoying the script, and I was at a loss as to why my prim sitting on the ground did nothing.

Thanks and I am going to keep ploughing through.


Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Fri Jun 01, 2012 11:32 am 
OSG Elite
User avatar

Joined: Sat Jun 14, 2008 12:28 am
Posts: 360
Location: Australia
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 :D )
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


Last edited by Cam Chevalier on Sun Jun 03, 2012 8:54 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: NPCs-help please
PostPosted: Fri Jun 01, 2012 11:39 am 
OSG Elite

Joined: Wed Aug 05, 2009 1:59 am
Posts: 417
Thanks Cam!

Gonna clone myself 15 million times so I can build more stuffs :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 19 posts ]
Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net