Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Follower Avatar_Follower  

Avatar_Follower

Introduction

It can be hard to fo...

Category: Follower
By : Dale Innis
Created: 2010-12-27 Edited: 2010-12-27
Worlds: Second Life

the Zip file

Download all files for Avatar_Follower
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Avatar_Follower_1.lsl
1 integer CHANNEL = 15; // That's "f" for "follow", haha
2
3 float DELAY = 0.5; // Seconds between blinks; lower for more lag
4 float RANGE = 3.0; // Meters away that we stop walking towards
5 float TAU = 1.0; // Make smaller for more rushed following
6
7 // Avatar Follower script, by Dale Innis
8 // Do with this what you will, no rights reserved
9 // See https://wiki.secondlife.com/wiki/AvatarFollower for instructions and notes
10
11 float LIMIT = 60.0; // Approximate limit (lower bound) of llMoveToTarget
12
13 integer lh = 0;
14 integer tid = 0;
15 string targetName = "";
16 key targetKey = NULL_KEY;
17 integer announced = FALSE;
18
19 init() {
21 lh = llListen(CHANNEL,"",llGetOwner(),"");
22 }
23
24 stopFollowing() {
25 llTargetRemove(tid);
27 llSetTimerEvent(0.0);
28 llOwnerSay("No longer following.");
29 }
30
31 startFollowingName(string name) {
32 targetName = name;
33 llSensor(targetName,NULL_KEY,AGENT,96.0,PI); // This is just to get the key
34 }
35
36 startFollowingKey(key id) {
37 targetKey = id;
38 llOwnerSay("Now following "+targetName);
39 keepFollowing();
40 llSetTimerEvent(DELAY);
41 }
42
43 keepFollowing() {
44 llTargetRemove(tid);
46 list answer = llGetObjectDetails(targetKey,[OBJECT_POS]);
47 if(llGetListLength(answer)==0) {
48 if(!announced) llOwnerSay(targetName+" seems to be out of range. Waiting for return...");
49 announced = TRUE;
50 } else {
51 announced = FALSE;
52 vector targetPos = llList2Vector(answer,0);
53 float dist = llVecDist(targetPos,llGetPos());
54 if(dist>RANGE) {
55 tid = llTarget(targetPos,RANGE);
56 if(dist>LIMIT) {
57 targetPos = llGetPos() + LIMIT * llVecNorm( targetPos - llGetPos() ) ;
58 }
59 llMoveToTarget(targetPos,TAU);
60 }
61 }
62 }
63
64 default {
65
66 state_entry() {
67 llOwnerSay("/"+(string)CHANNEL+" [name of person to magically follow]");
68 init();
69 }
70
71 on_rez(integer x) {
72 llResetScript(); // Why not?
73 }
74
75 listen(integer c,string n,key id,string msg) {
76 if(msg == "off") {
77 stopFollowing();
78 } else {
79 startFollowingName(msg);
80 }
81 }
82
83 no_sensor() {
84 llOwnerSay("Did not find anyone named "+targetName);
85 }
86
87 sensor(integer n) {
88 startFollowingKey(llDetectedKey(0)); // Can't have two ppl with the same name, so n will be one. Promise. :)
89 }
90
91 timer() {
92 keepFollowing();
93 }
94
95 at_target(integer tnum,vector tpos,vector ourpos) {
96 llTargetRemove(tnum);
98 }
99
100 }

Back to the Best Free Tools in Second Life and OpenSim.