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

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 9 posts ]
Author Message
 Post subject: NPC Follow Script
PostPosted: Wed Dec 28, 2011 8:13 pm 
Furious Typer

Joined: Tue Dec 08, 2009 1:51 pm
Posts: 63
Here's a simple script to have your clone follow you or anyone that comes close to it. Place it in an item worn by the clone.

{L_CODE}:
float range= 4.0;
key whotofollow = "00000000-0000-0000-0000-000000000000";
vector offset = < -3, 0, 1.0>; //3 meter behind. 1.5 up (bot doesn't seem to walk if not raised a bit)
integer listener;


default
{
    state_entry()
    {
        llSleep(10);// pause it for a bit while it rezes
        llSetTimerEvent(1.0);
    }
    on_rez(integer start_param)
    {
        llResetScript();
    }
    listen(integer channel, string name, key id, string msg)
    {
        if (llToLower(msg) == "stop following me")
        {
            llListenRemove(listener);
            osNpcSay(llGetOwner(), "Sorry, I'll stop following");
            whotofollow = "00000000-0000-0000-0000-000000000000";
            llSleep(60);
            osNpcSay(llGetOwner(), "I'm Not Sorry!!!!");
        }
    }
    timer()
    {
        llSensor("",NULL_KEY,AGENT, range ,PI);
    }
    sensor(integer detected)
    {
         if (osGetAgentIP(llDetectedKey(0)) != "")
        {
            if (llDetectedKey(0) != whotofollow)
            {
            llSay (0,"Now following " + llDetectedName(0));
            whotofollow = llDetectedKey(0);
            listener = llListen(0,"",whotofollow,"");
            }
           
        }
    }
    no_sensor()
    {
        if (whotofollow != "00000000-0000-0000-0000-000000000000")
        {
            list det = llGetObjectDetails(whotofollow,[OBJECT_POS,OBJECT_ROT]);
            vector pos = llList2Vector(det,0);
            rotation rot = (rotation)llList2String(det,1);
            vector worldOffset = offset;
            vector avOffset = offset * rot;
            pos += avOffset;
            osNpcMoveToTarget(llGetOwner(),pos, OS_NPC_NO_FLY );
            }
    }
}



the line
{L_CODE}:
if (osGetAgentIP(llDetectedKey(0)) != "")
is used to detect if the sensor found an agent or an avatar. Else, multiple clones just follow each other.


Last edited by Trex Blessed on Thu Dec 29, 2011 3:47 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: NPC Follow Script
PostPosted: Thu Dec 29, 2011 12:37 pm 
Furious Typer
User avatar

Joined: Sat Jul 16, 2011 3:35 pm
Posts: 164
she works fine captain, I'm following myself now ;)


Top
 Profile  
 
 Post subject: Re: NPC Follow Script
PostPosted: Thu Dec 29, 2011 5:33 pm 
Furious Typer

Joined: Tue Dec 08, 2009 1:51 pm
Posts: 63
Here's another script to identify a NPC through a sensor. I think i saw this requested somewhere before but can't find it so I'll post it here.


{L_CODE}:
// scanner to identify NPC from Avatar
float range= 40.0; // set this

default
{
    touch_start(integer num)
    {
    llSensor("",NULL_KEY,AGENT, range ,PI);
    }
    sensor(integer detected)
    {
    llSay(0,"Found " + (string)detected + " agent(s) within a range of " + (string)((integer)range) + " meters");

    integer i;
    for (i = 0; i < detected; i++)
    {
        //msg = llDetectedName(i);
        if (osGetAgentIP(llDetectedKey(i)) != "")
        {
            llSay(0,llDetectedName(i) + " is an avatar");
        }
        else
        {
            llSay(0,llDetectedName(i) + " is a NPC" );
        }
    }
}
}


Top
 Profile  
 
 Post subject: Re: NPC Follow Script
PostPosted: Tue Jan 24, 2012 8:39 am 
Site Admin

Joined: Sun Jul 04, 2010 8:20 pm
Posts: 478
Recent changes to the llSensor function is probably the reason, try using the NPC flag with llSensor changing the line:

(detects avatars)
{L_CODE}:
llSensor("",NULL_KEY,AGENT, range ,PI);


to
(detect avatars & npc)
{L_CODE}:
llSensor("",NULL_KEY,AGENT|NPC, range ,PI);


or
(detects npc)
{L_CODE}:
llSensor("",NULL_KEY,NPC, range ,PI);


dan


Top
 Profile  
 
 Post subject: Re: NPC Follow Script
PostPosted: Tue Jan 07, 2014 7:12 pm 

Joined: Wed Dec 26, 2012 11:05 pm
Posts: 9
I think that this line:

key whotofollow = "00000000-0000-0000-0000-000000000000";

say that the NPC follows only to this UUID of avatar. Then, when I try to change it, the NPC never follows me. I'm need a script for follow only to one avatar. Can be possible?

Regards.


Top
 Profile  
 
 Post subject: Re: NPC Follow Script
PostPosted: Wed Jan 08, 2014 1:36 am 
Furious Typer
User avatar

Joined: Sat May 26, 2012 8:56 pm
Posts: 280
Basically, if you want the NPC to just follow you, change the llSensor to the key or name of the avatar, so basically your llSensor would look like this

(and I would use llSensorRepeat, thereby negating the need for a timer function)

llSensorRepeat("AvatarName","AvatarKey",AGENT,96,PI,3.0);

You can use either AvatarName or AvatarKey as defined previously in the script.

If you need a script, IM me inworld with your requirements, and I will see what I can do.


Top
 Profile  
 
 Post subject: Re: NPC Follow Script
PostPosted: Wed Jan 08, 2014 12:34 pm 

Joined: Wed Dec 26, 2012 11:05 pm
Posts: 9
Thank you, now is working on :o


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 9 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