A Virsion Of Avatar Follower ( HUD )

Thread Started By cb489

2128
0
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rate Thread
#1
Without dialogbox:

Insert these scripts in an object, wear as HUD and Type someone's full username on channel 15 to follow:
Code:
integer CHANNEL = 15;  // That's "f" for "follow", haha

float DELAY = 0.5;   // Seconds between blinks; lower for more lag
float RANGE = 3.0;   // Meters away that we stop walking towards
float TAU = 1.0;     // Make smaller for more rushed following

// Avatar Follower script, by Dale Innis
// Do with this what you will, no rights reserved
// See https://wiki.secondlife.com/wiki/AvatarFollower for instructions and notes

float LIMIT = 60.0;   // Approximate limit (lower bound) of llMoveToTarget

integer lh = 0;
integer tid = 0;
string targetName = "";
key targetKey = NULL_KEY;
integer announced = FALSE;

init() {
  llListenRemove(lh);
  lh = llListen(CHANNEL,"",llGetOwner(),"");
}

stopFollowing() {
  llTargetRemove(tid);  
  llStopMoveToTarget();
  llSetTimerEvent(0.0);
  llRegionSayTo(llGetOwner(),0,"No longer following.");
}

startFollowingName(string name) {
  targetName = name;
  llSensor(targetName,AGENT,1000,PI);  // This is just to get the key
}

startFollowingKey(key id) {
  targetKey = id;
  llRegionSayTo(llGetOwner(),0,"Now following "+targetName);
  keepFollowing();
  llSetTimerEvent(DELAY);
}

keepFollowing() {
  llTargetRemove(tid);  
  llStopMoveToTarget();
  list answer = llGetObjectDetails(targetKey,[OBJECT_POS]);
  if (llGetListLength(answer)==0) {
    if (!announced) llOwnerSay(targetName+" seems to be out of range.  Waiting for return...");
    announced = TRUE;
  } else {
    announced = FALSE;
    vector targetPos = llList2Vector(answer,0);
    float dist = llVecDist(targetPos,llGetPos());
    if (dist>RANGE) {
      tid = llTarget(targetPos,RANGE);
      if (dist>LIMIT) {
          targetPos = llGetPos() + LIMIT * llVecNorm( targetPos - llGetPos() ) ;
      }
      llMoveToTarget(targetPos,TAU);
    }
  }
}

default {

  state_entry() {
    llRegionSayTo(llGetOwner(),0,"/"+(string)CHANNEL+" [name of person to magically follow]");
    init();
  }

  on_rez(integer x) {
    llResetScript();   // Why not?
  }

  listen(integer c,string n,key id,string msg) {
    if (msg == "off") {
      stopFollowing();
    } else {
      startFollowingName(msg);
    }
  }

  no_sensor() {
    llRegionSayTo(llGetOwner(),0,"Did not find anyone named "+targetName);
  }

  sensor(integer n) {
    startFollowingKey(llDetectedKey(0));  // Can't have two ppl with the same name, so n will be one.  Promise.  :)
  }

  timer() {
    keepFollowing();
  }

  at_target(integer tnum,vector tpos,vector ourpos) {
    llTargetRemove(tnum);
    llStopMoveToTarget();  
  }

}
Code:
// :CATEGORY:HUD
// :NAME:Improved_HUD_positioner
// :AUTHOR:Fred Beckhusen (Ferd Frederix)
// :CREATED:2010-06-22 15:17:05.390
// :EDITED:2013-09-18 15:38:55
// :ID:399
// :NUM:555
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
//// The HUD positioner is designed to set the HUD into a 'preferred' position whenever it get attached.
// If the user moves it, and re-attaches it to the same spot, it ignores the hard-coded settings.   It keeps a list of offsets from the top, bottom, left and right and moves the prim when it is first attached by that offset.  Ity also forces the prim to face in a know direction, just in case it is accidentally rotated by the end-user.// // If the HUD pops off-screen, wear another HUD, press Ctrl-3 to go into edit mode, click the other HUD, and use the scroll wheel to zoom out.  You will see a line representing the edge of the 'normal' screen, and outside of it, hopefully, you will see the misplaced HUD.
// You can then grab it and move it back on-screen.
// :CODE:
// This script was originally designed for a small HUD.  You will probably need to edit the offsets that are in the script unless your HUD is also very small.     The best way to do this is to wear the HUD, edit it, and look at the coordinates that appear in screen.   These are offsets from the 'default' positions of the viewer.   Move the prim to the correct position, and notice the X and Y and Z numbers change?   You will need to change the Y and Z those numbers and put them in this scripts if you HUD is to go into another position.
//
// For example, if you attach something to the right side top or the right side bottom, the prim's center will normally be along the right edge.   This script moves it to the left by trYoffset = 0.185 when at the top right, and brYoffset=0.125 when at the bottom right edge so that it can clear the little hump in some viewers. Another example is attaching to the very bottom, which is really bottom center.  The script will move the prim vertically by BVerticalOffset = 0.080 to clear the nav bars, and leave the Y axis alone by adding to Y a 0.
// ______           _  ______            _           _
// |  ___|         | | |  ___|          | |         (_)
// | |_ ___ _ __ __| | | |_ _ __ ___  __| | ___ _ __ ___  __
// |  _/ _ \ '__/ _` | |  _| '__/ _ \/ _` |/ _ \ '__| \ \/ /
// | ||  __/ | | (_| | | | | | |  __/ (_| |  __/ |  | |>  <
// \_| \___|_|  \__,_| \_| |_|  \___|\__,_|\___|_|  |_/_/\_\
//
// fred@mitsi.com
// author Fred Beckhusen (Ferd Frederix)
//

integer  lasttarget;

default
{

    attach( key id)
    {

        if (id)
        {
            integer target = llGetAttached();

            vector position = llGetLocalPos();

            if (target == lasttarget )
                return;

            lasttarget = target; // save the position we just set

            float Y = 0.0;
            float Z = 0.0;
            float trYoffset = 0.185;     // right edge
            float brYoffset = 0.125;     // right edge
            float otherYoffset = 0.080;      // move right from left edge
            float VerticalOffset = 0.2;        // move down for room for hover text
            float CenterOffset = 0.7;        // left and right center offset to left and right edge
            float BVerticalOffset = 0.080;     // Bottom Z.


            if (target == ATTACH_HUD_CENTER_2)
            {
                Y = CenterOffset; Z = 0.0;       // move to left edge
            }
            else if (target == ATTACH_HUD_TOP_RIGHT)
            {
                Y = trYoffset; Z = -VerticalOffset;      // down for room for hovertext
            }
            else if (target == ATTACH_HUD_TOP_CENTER)
            {
                Y = 0; Z = -VerticalOffset;
            }
            else if (target == ATTACH_HUD_TOP_LEFT)
            {
                Y = -otherYoffset; Z = -VerticalOffset;
            }
            else if (target == ATTACH_HUD_CENTER_1)
            {
                Y = -CenterOffset; Z = 0.0;      // move to right edge
            }
            else if (target == ATTACH_HUD_BOTTOM_LEFT)
            {
                Y = -otherYoffset; Z = BVerticalOffset;
            }
            else if (target == ATTACH_HUD_BOTTOM)
            {
                Y = 0.0; Z = BVerticalOffset;
            }
            else if (target == ATTACH_HUD_BOTTOM_RIGHT)
            {
                Y = brYoffset; Z = BVerticalOffset ;       // 2 x to miss buttons
            }
            else
            {
                llOwnerSay("You must attach this as a HUD");
                return;

            }

            vector newtarget = <0.0,Y,Z>;
            llSetPos (newtarget);

            rotation  myrot = llEuler2Rot( <0.0,90.0,270.0> * DEG_TO_RAD);
            llSetLocalRot(myrot);


        }
    }


}
With dialogbox:
Code:
integer CHANNEL = 15;
integer delay = 8;
string msgbox = "Choose a person in to magically follow:";
string timeout = "Dialog menu timeout.";
list button =["Off"];
default
{
  touch_start(integer total_number)
    {
       llSensor("",NULL_KEY,AGENT,100,PI);
       llSetTimerEvent(delay);
      
    }
    sensor(integer peeps)
    {
        while(peeps--)
        {
            button += llKey2Name(llDetectedKey(peeps));
        }
        llDialog(llGetOwner(),msgbox,button,CHANNEL);
        llListen(CHANNEL,"",llGetOwner(),"");
    }
    no_sensor()
    {
        llRegionSayTo(llGetOwner(),0,"No avatar in range, please move closer.");
    }
    listen(integer channel, string name, key id, string cmd)
    {
        llSetStatus(STATUS_PHYSICS, TRUE);
        llMessageLinked(LINK_THIS, 1, cmd, "");
        llResetScript();
    }
    timer()
    {
        llRegionSayTo(llGetOwner(),0,timeout);
        llResetScript();
    }
}
 
Code:
float DELAY = 0.5;   // Seconds between blinks; lower for more lag
float RANGE = 3.0;   // Meters away that we stop walking towards
float TAU = 1.0;     // Make smaller for more rushed following

// Avatar Follower script, by Dale Innis
// Do with this what you will, no rights reserved
// See https://wiki.secondlife.com/wiki/AvatarFollower for instructions and notes

float LIMIT = 60.0;   // Approximate limit (lower bound) of llMoveToTarget

integer lh = 0;
integer tid = 0;
string targetName = "";
key targetKey = NULL_KEY;
integer announced = FALSE;
stopFollowing() {
  llTargetRemove(tid);  
  llStopMoveToTarget();
  llSetTimerEvent(0.0);
  llRegionSayTo(llGetOwner(),0,"No longer following.");
}

startFollowingName(string name) {
  targetName = name;
  llSensor(targetName,NULL_KEY,AGENT,100.0,PI);  // This is just to get the key
}

startFollowingKey(key id) {
  targetKey = id;
  llRegionSayTo(llGetOwner(),0,"Now following "+targetName);
  keepFollowing();
  llSetTimerEvent(DELAY);
}

keepFollowing() {
  llTargetRemove(tid);  
  llStopMoveToTarget();
  list answer = llGetObjectDetails(targetKey,[OBJECT_POS]);
  if (llGetListLength(answer)==0) {
    if (!announced) llRegionSayTo(llGetOwner(),0,targetName+" seems to be out of range.  Waiting for return...");
    announced = TRUE;
  } else {
    announced = FALSE;
    vector targetPos = llList2Vector(answer,0);
    float dist = llVecDist(targetPos,llGetPos());
    if (dist>RANGE) {
      tid = llTarget(targetPos,RANGE);
      if (dist>LIMIT) {
          targetPos = llGetPos() + LIMIT * llVecNorm( targetPos - llGetPos() ) ;
      }
      llMoveToTarget(targetPos,TAU);
    }
  }
}

default {
on_rez(integer x) {
    llResetScript();   // Why not?
  }

  link_message(integer sender_num, integer num, string msg, key id) {
    if (num==1) {
        if (msg == "Off") {
      stopFollowing();
      llSetStatus(STATUS_PHYSICS, FALSE);
    } else {
      startFollowingName(msg);
    }
    }
  }

  no_sensor() {
    llRegionSayTo(llGetOwner(),0,"Did not find anyone named "+targetName);
  }

  sensor(integer n) {
    startFollowingKey(llDetectedKey(0));  // Can't have two ppl with the same name, so n will be one.  Promise. :)
  }

  timer() {
    keepFollowing();
  }

  at_target(integer tnum,vector tpos,vector ourpos) {
    llTargetRemove(tnum);
    llStopMoveToTarget();  
  }

}
The bellow script is common to both types:
Code:
// :CATEGORY:HUD
// :NAME:Improved_HUD_positioner
// :AUTHOR:Fred Beckhusen (Ferd Frederix)
// :CREATED:2010-06-22 15:17:05.390
// :EDITED:2013-09-18 15:38:55
// :ID:399
// :NUM:555
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
//// The HUD positioner is designed to set the HUD into a 'preferred' position whenever it get attached.
// If the user moves it, and re-attaches it to the same spot, it ignores the hard-coded settings.   It keeps a list of offsets from the top, bottom, left and right and moves the prim when it is first attached by that offset.  Ity also forces the prim to face in a know direction, just in case it is accidentally rotated by the end-user.// // If the HUD pops off-screen, wear another HUD, press Ctrl-3 to go into edit mode, click the other HUD, and use the scroll wheel to zoom out.  You will see a line representing the edge of the 'normal' screen, and outside of it, hopefully, you will see the misplaced HUD.
// You can then grab it and move it back on-screen.
// :CODE:
// This script was originally designed for a small HUD.  You will probably need to edit the offsets that are in the script unless your HUD is also very small.     The best way to do this is to wear the HUD, edit it, and look at the coordinates that appear in screen.   These are offsets from the 'default' positions of the viewer.   Move the prim to the correct position, and notice the X and Y and Z numbers change?   You will need to change the Y and Z those numbers and put them in this scripts if you HUD is to go into another position.
//
// For example, if you attach something to the right side top or the right side bottom, the prim's center will normally be along the right edge.   This script moves it to the left by trYoffset = 0.185 when at the top right, and brYoffset=0.125 when at the bottom right edge so that it can clear the little hump in some viewers. Another example is attaching to the very bottom, which is really bottom center.  The script will move the prim vertically by BVerticalOffset = 0.080 to clear the nav bars, and leave the Y axis alone by adding to Y a 0.
// ______           _  ______            _           _
// |  ___|         | | |  ___|          | |         (_)
// | |_ ___ _ __ __| | | |_ _ __ ___  __| | ___ _ __ ___  __
// |  _/ _ \ '__/ _` | |  _| '__/ _ \/ _` |/ _ \ '__| \ \/ /
// | ||  __/ | | (_| | | | | | |  __/ (_| |  __/ |  | |>  <
// \_| \___|_|  \__,_| \_| |_|  \___|\__,_|\___|_|  |_/_/\_\
//
// fred@mitsi.com
// author Fred Beckhusen (Ferd Frederix)
//

integer  lasttarget;

default
{

    attach( key id)
    {

        if (id)
        {
            integer target = llGetAttached();

            vector position = llGetLocalPos();

            if (target == lasttarget )
                return;

            lasttarget = target; // save the position we just set

            float Y = 0.0;
            float Z = 0.0;
            float trYoffset = 0.185;     // right edge
            float brYoffset = 0.125;     // right edge
            float otherYoffset = 0.080;      // move right from left edge
            float VerticalOffset = 0.2;        // move down for room for hover text
            float CenterOffset = 0.7;        // left and right center offset to left and right edge
            float BVerticalOffset = 0.080;     // Bottom Z.


            if (target == ATTACH_HUD_CENTER_2)
            {
                Y = CenterOffset; Z = 0.0;       // move to left edge
            }
            else if (target == ATTACH_HUD_TOP_RIGHT)
            {
                Y = trYoffset; Z = -VerticalOffset;      // down for room for hovertext
            }
            else if (target == ATTACH_HUD_TOP_CENTER)
            {
                Y = 0; Z = -VerticalOffset;
            }
            else if (target == ATTACH_HUD_TOP_LEFT)
            {
                Y = -otherYoffset; Z = -VerticalOffset;
            }
            else if (target == ATTACH_HUD_CENTER_1)
            {
                Y = -CenterOffset; Z = 0.0;      // move to right edge
            }
            else if (target == ATTACH_HUD_BOTTOM_LEFT)
            {
                Y = -otherYoffset; Z = BVerticalOffset;
            }
            else if (target == ATTACH_HUD_BOTTOM)
            {
                Y = 0.0; Z = BVerticalOffset;
            }
            else if (target == ATTACH_HUD_BOTTOM_RIGHT)
            {
                Y = brYoffset; Z = BVerticalOffset ;       // 2 x to miss buttons
            }
            else
            {
                llOwnerSay("You must attach this as a HUD");
                return;

            }

            vector newtarget = <0.0,Y,Z>;
            llSetPos (newtarget);

            rotation  myrot = llEuler2Rot( <0.0,90.0,270.0> * DEG_TO_RAD);
            llSetLocalRot(myrot);


        }
    }


}
Reply




Forum Jump:

1 Guest(s)
Share this:

About Second Life Copybot

Second Life CopyBot Forum is a place where you can get items for Second Life and other vitual worlds for free. With our CopyBot viewers you can export and import any content from these virtual worlds and modify them in 3D software such as Blender, 3D studio Macx etc...