Change font size
It is currently Sat Feb 16, 2019 8:54 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 3 posts ]
Author Message
 Post subject: Another NPC follower script
PostPosted: Mon Oct 07, 2013 1:12 am 

Joined: Wed May 09, 2012 11:11 am
Posts: 25
A while back I butchered the dead basic NPC create script at opensimulator.org to create an NPC follower script.
If I remember correctly it was more of a cut,copy,paste from a bunch of scripts, and then poke it with a pointy stick till it stated wiggling.

This one works on mega-regions.
Don't ask me why or how, and in fact it'd be nice to know the how and why, and even better yet, how to get it to follow anyone but the script owner.

I'm thinking though that locations are detected in a relative rather than absolute manner.

here's the script complete with an awful lot of remnants of my butchering. :)

{L_CODE}:
// touch to create a NPC clone of the toucher in front of this emitter
// NPC will move to the toucher, then will greet them.
// Touch again to remove the NPC

key npc3;
vector toucherPos;
vector offset = < 1, 0, 0>;  //1 meter behind and 1 meter above owner's center.

default
{
    touch_start(integer number)
    {
        vector npcPos = llGetPos() + <1,0,0>;
        osAgentSaveAppearance(llDetectedKey(0), "appearance");
        // coud use avatar UUID directly in osNpcCreate, but then NPC appearance is not persisted
        npc3 = osNpcCreate("Im Your ", "Genie", npcPos, "appearance");
        toucherPos = llDetectedPos(0);
        osAvatarPlayAnimation(npc3, "walk");
        //new code below
       
        state hasNPC;
    }
}

state hasNPC
{
    state_entry()
    {
        osNpcMoveToTarget(npc3, toucherPos + <0,0,0>, OS_NPC_NO_FLY);
        string owner_name = osKey2Name(llGetOwner());
        //creates a notecard containing the serialized appearance of the cloned user named test_card_<username>
       //which you can then rename to appearance or redefine above to create a persistant appearance
        osOwnerSaveAppearance("test_card_"+owner_name);
        osNpcSay(npc3, "You've been cloned   "+owner_name);
        osNpcSay(npc3, "touch the cloner again to be rid of me");
        osAvatarStopAnimation(npc3,"walk");
        llSleep(9);
        //osAvatarPlayAnimation(npc3,"diva2");
        osNpcSay(npc3, "I'll do any thing for you");;
        llSleep(5);
               llSetTimerEvent(1.0);
    }
    timer()
    {
        list det = llGetObjectDetails(llGetOwner(),[OBJECT_POS,OBJECT_ROT]);//this will never fail less owner is not in the same sim
        // Owner detected...
        // Get position and rotation
        vector pos   = llList2Vector(det,0);
        rotation rot = (rotation)llList2String(det,1);
        // Offset back one metre in X and up one metre in Z based on world coordinates.
        // use whatever offset you want.
        vector worldOffset = offset;
        // Offset relative to owner needs a quaternion.
        vector avOffset = offset * rot;

        pos += avOffset;       // use the one you want, world or relative to AV.
        osAvatarPlayAnimation(npc3,"walk");
        osNpcMoveToTarget(npc3, pos + <llFrand(2),llFrand(2),0>, OS_NPC_NO_FLY);
        osAvatarStopAnimation(npc3,"walk");
        llSleep(5);
        osAvatarPlayAnimation(npc3,"Girlystand1");
        llSleep(8);
         list ChikChat = ["I'm hungry, when do we eat?", "Have you ever considered marriage?", "Will you buy me some clothes?", "Does my butt look big?"];
    integer Choice = (integer)llFrand(llGetListLength(ChikChat));
    osNpcSay(npc3, llList2String(ChikChat,Choice));
    llSleep(5);
    osAvatarStopAnimation(npc3,"Girlystand1");

    }

    touch_start(integer number)
    {
       osAvatarStopAnimation(npc3,"walk");
       osNpcSay(npc3, "goodbye for now");
       llSleep(5);
        osNpcRemove(npc3);
        npc3 = NULL_KEY;
        state default;
    }
}


Top
 Profile  
 
 Post subject: Re: Another NPC follower script
PostPosted: Mon Oct 07, 2013 6:32 am 
Furious Typer
User avatar

Joined: Sat May 26, 2012 8:56 pm
Posts: 280
That is a basic script, and yes it will follow the owner.. but it could be changed to follow anyone, you just need to add an llSensor to it..


Top
 Profile  
 
 Post subject: Re: Another NPC follower script
PostPosted: Mon Oct 07, 2013 10:44 am 

Joined: Wed May 09, 2012 11:11 am
Posts: 25
Well I guess I'll have to find some example code to work look at and get my pointy stick out again.

In fact the script itself is an unremarkable butcherjob except that the NPC will follow it's owner all over a mega-region.
I just posted it because it'll follow it's owner across borders on a mega-region and that could be useful.


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


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