Change font size
It is currently Thu Nov 22, 2018 6:11 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 5 posts ]
Author Message
 Post subject: NPC path
PostPosted: Mon Sep 05, 2011 3:38 am 
Furious Typer
User avatar

Joined: Mon Aug 10, 2009 11:53 pm
Posts: 258
Hi all I don't want to mess up Roken's NPC post, so here is a couple of cheezy scripts I threw together tonight. Obviously a bit on the primitive side but it will get you going if you want a NPC or two walking around. Note that the actual path script has a 'while' loop in it. Not the best for lag if you have long paths - someone may be able to re-write this in short order much better. Anyway without further ado...

Path creation script:
Drop this script in a prim, wear it on your HUD. Start walking! Just click it every time you want your NPC to move to that spot. So click at point A go a ways, click point B, then C, etc. Then it will path along those points.

Currently this is written so you can keep on clicking then type in '/12 anything' and it will create the notecard 'Path1'. Just copy that into inventory and go on to the next step
{L_CODE}:
vector path_pos;
string path_write;
string notename = "Path1";
default
{
   
    state_entry()
    {
        llListen(12,"",llGetOwner(),"");
    }
    touch_start(integer n)
    {
        path_pos = llDetectedPos(0);
        path_write += (string)path_pos+"\n";
    }
    listen(integer channel, string name, key id, string msg)
    {
        if (msg != "")
        {
            osMakeNotecard(notename,path_write);
            llOwnerSay("Notecard Created");
        }
    }
}

Part2 - NPC path script:
This is written to currently take a notecard named 'Path1' as previously stated. You can rename it however you like. It is one vector per line, as many vectors as you want. The NPC is spawned at the first vector in the notecard. Once you type /10 start - it is off to the races. Please note that it is currently setup to use an animation named 'walk' please use whatever accordingly as the script will of course error out if it cannot find it.
Remember that notecard 'Path1' we put into inventory?? Time to drop it into this same prim or the script won't be happy :D
{L_CODE}:
key npc;
vector curPos;
vector vecTo_targ;
vector nPos;
list path;
integer path_length;
integer pad_Turn = 3; // Larger the number smoother the turn but less accurate
string notecard;      // Smaller the number more accurate but sharper noticeable stop/turn



default
{
    state_entry()
    {
        llListen(10,"",NULL_KEY,""); //
        integer i;
        notecard = "Path1";          // Name of path vector notecard       
       
        for(i=1; i<osGetNumberOfNotecardLines(notecard); i++) {
            path += osGetNotecardLine(notecard, i);
        } // Grab path vectors from notecard and pack into list
       
        path_length=llGetListLength(path);
    }
   
    touch_start(integer num)
    {
        llOwnerSay("\n\nNPC Path Block:\n
        Type /10 (command) to control your NPC.\n
        create - spawn NPC\n
        start - start NPC path\n
        stop - stop and remove the NPC");
    }   

    listen(integer channel, string name, key id, string msg)
    {
        if (msg != "")
        {
            if (msg == "create"){
                osOwnerSaveAppearance("appearance");
                vector spawn = (vector)osGetNotecardLine(notecard, 1);
                npc = osNpcCreate ("Justa", "Walkin", spawn, "appearance");
            }
            else if (msg == "start"){             
                integer x;
                for (x = 1; x < path_length; x++) {
                    vecTo_targ = llList2Vector(path,x);
                    nPos = osNpcGetPos(npc);       
                    if (vecTo_targ.x > 1){                                   
                        osAvatarPlayAnimation(npc,"walk");
                        osNpcSetRot(npc, llRotBetween(<PI,PI,0>,llVecNorm(vecTo_targ - osNpcGetPos(npc))));
                        osNpcMoveToTarget(npc, vecTo_targ, OS_NPC_NO_FLY);
                                       
                            while (llFabs(llVecDist(vecTo_targ, nPos)) > pad_Turn){
                                nPos = osNpcGetPos(npc);
                                llSleep(.5);
                                } // Probably a lower lag way to do this with states or something
                                  // This also locks out the script until the loop is complete
                                  // Which I really really hate! :P                                 
                    }
                else {
                    llSleep(.5); // Stop animation buffer
                                 // no duck walking last couple of feet
                                 // adjust for animation or make a variable
                    osAvatarStopAnimation(npc,"walk");
                }
            }     
               
            }
            else if (msg == "stop"){
                osNpcRemove(npc);
                llResetScript();    // Stop all processes. Kill all NPCs.
            }
            else {
                llOwnerSay("Unkown Command");
            }
        }
    }


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


Top
 Profile  
 
 Post subject: Re: NPC path
PostPosted: Thu Nov 08, 2012 6:09 pm 
User avatar

Joined: Sat Mar 06, 2010 11:18 am
Posts: 30
Location: United Kingdom
Hi,
Just tried these scripts out and they work to a certain point.
I have a 6 sim mega region and I can only get the AV to work in the SW region.
But, even on the SW region the AV walked most of the route then stopped about half way and started walking on the spot.
On the other regions the AV just walks on the spot.
Any ideas would be appreciated.
Cheers

_________________
Youtube Videos : http://www.youtube.com/user/proracermotorsports
Blog : http://www.pro-racer.info


Top
 Profile  
 
 Post subject: Re: NPC path
PostPosted: Fri Nov 09, 2012 2:49 am 
Furious Typer
User avatar

Joined: Fri Aug 19, 2011 7:10 pm
Posts: 236
Location: UK
I'll have a look at some point when I have more time about optimising your while loop. In the meantime, don't worry about hi-jacking my thread. I think it would be useful for someone somewhere to set up an "NPC Script repository". I know that some people more talented than I have done considerable work on scripting NPCs, though often for different scenarios.

As more and more people are using NPCs now, though, there doesn't seem to be a lot of point in everyone constantly reinventing the wheel.

If I had the web space available I'd throw a repo together myself, but I have neither the time to maintain nor a reliable server that I could do it from :(

_________________
50's sim based at Rumbled on OSGrid
happily running on Debian Linux on a VPS since June 10 2013


Top
 Profile  
 
 Post subject: Re: NPC path
PostPosted: Fri Nov 09, 2012 8:02 am 
Site Admin

Joined: Sun Jul 04, 2010 8:20 pm
Posts: 478
samantha, NPC avatars can only access the region they are created in. There are probably a few other things that arent mega-aware (parcels, media, etc)

dan


Top
 Profile  
 
 Post subject: Re: NPC path
PostPosted: Sun Sep 15, 2013 11:25 pm 

Joined: Wed May 09, 2012 11:11 am
Posts: 25
{L_QUOTE}:
samantha, NPC avatars can only access the region they are created in.


That's not entirely true in 2013 under opensim-0.7.5.

Maybe an NPC can't be scripted into crossing into another sub-region in a mega region by itself, but, it "can" follow an actual avatar into another sub-region.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 5 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron


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