Join us in Phaze Demesnes or follow us:

Home   Show All
Category: Contributor: Creator
Pets Kevin the Bird pet follower  

Kevin the Bird pet follower

This is from Kevin the bird - a Pet follower. It stays in one area and runs and up yells hello.

Category: Pets
By : Ferd Frederix
Created: 2013-12-17 Edited: 2013-12-17
Worlds: Second Life + OpenSim

the Zip file

Download all files for Kevin the Bird pet follower
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Script.lsl

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 ////////////////////////////////////////////
2 // Follow Me Script
3 //
4 // Written by Xylor Baysklef
5 // Adapted and added by Garth Fairlight
6 // Adapted by Ferd Frederix
7 ////////////////////////////////////////////
8
9
10 float DIST = 10; // how far to sense avatars
11 string GREET = "39d0abf5-8921-8317-915c-2efcc87e0bfe"; // a sound for Meow
12 string BYE = "0098ae21-325a-ae76-522f-f66e844471c6"; // a sound for a meow
13
14 float X = -2.0; // usually tyhis far back
15 float Y = .0; // rugth in the mioddle
16 float posX;
17 float posY;
18
19 vector POSITION_OFFSET = <0.0, 0.75, -0.8>; // Local coords
20 vector FLY_OFFSET = <2.0, -2.75, 0.0>;
21 vector FLYANGLE = <80, 0, 10>;
22 float DAMP = 8; // damping for flight
23 float TURNSPEED = 10.0;
24
25
26 vector startPos;
27 rotation startRot;
28 integer returning;
29
30 /////////////// CONSTANTS ///////////////////
31 vector last;
32 integer flag;
33 integer playchannel = 1;
34
35 string FWD_DIRECTION = "-y";
36 float SCAN_REFRESH = 0.2;
37 string FOLLOW = "/follow";
38 string STAY = "/stay";
39 integer FOLLOW_STOP = 5000;
40 integer FOLLOW_START = 5001;
41 float MOVETO_INCREMENT = 3.0;
42 ///////////// END CONSTANTS /////////////////
43
44 ///////////// GLOBAL VARIABLES ///////////////
45 key gOwner;
46 rotation gFwdRot;
47 float gTau;
48 float gMass;
49 integer count;
50 integer repeat;
51 /////////// END GLOBAL VARIABLES /////////////
52 float randBetween(float min, float max)
53 {
54 return llFrand(max - min) + min;
55 }
56
57 help()
58 {
59 llWhisper(0,"You can say the following commands:");
60 llWhisper(0,"/follow <-- I will follow you around");
61 llWhisper(0,"/stay <-- I will stay where I am.");
62 llWhisper(0,"/help <-- I will repeat this message.");
63 llWhisper(0,"if I lose you I will IM my position to you unless");
64 llWhisper(0,"I am in a no script area, then I can do nothing.");
65 }
66
67 StartScanning()
68 {
70 llSensorRepeat("", "", AGENT, DIST, PI, SCAN_REFRESH);
71 }
72
73 StopScanning()
74 {
76 llSensorRemove();
77 }
78
79 // Move to a position far away from the current one.
80 MoveTo(vector target)
81 {
82 vector Pos = llGetPos();
83
84 while (llVecDist(Pos, target) > MOVETO_INCREMENT)
85 {
86 Pos += llVecNorm(target - Pos) * MOVETO_INCREMENT;
87 llSetPos(Pos);
88 }
89 llSetPos(target);
90 }
91
92 rotation GetFwdRot()
93 {
94 // Special case... 180 degrees gives a math error
95 if (FWD_DIRECTION == "-x")
96 {
97 return llAxisAngle2Rot(<0, 0, 1>, PI);
98 }
99
100 string Direction = llGetSubString(FWD_DIRECTION, 0, 0);
101 string Axis = llToLower(llGetSubString(FWD_DIRECTION, 1, 1));
102
103 vector Fwd;
104 if (Axis == "x")
105 Fwd = <1, 0, 0>;
106 else if (Axis == "y")
107 Fwd = <0, 1, 0>;
108 else
109 Fwd = <0, 0, 1>;
110
111 if (Direction == "-")
112 Fwd *= -1;
113
114 return llRotBetween(Fwd, <1, 0, 0>);
115 }
116
117 rotation GetRotation(rotation rot)
118 {
119 vector Fwd;
120 Fwd = llRot2Fwd(rot);
121
122 float Angle = llAtan2( Fwd.y, Fwd.x );
123 return gFwdRot * llAxisAngle2Rot(<0, 0, 1>, Angle);
124 }
125
126 default
127 {
129 {
130 posX = X;
131 posY = Y;
132
133 startPos = llGetPos();
134 startRot = llGetRot();
135 llCollisionSound("",0);
136 llSetStatus(STATUS_PHANTOM, TRUE);
137 gOwner = llGetOwner();
138 gFwdRot = GetFwdRot();
139 gMass = llGetMass();
140 gTau = 0.2;
141 llListen(0, "", "", "");
142 llSetTimerEvent(1.5);
143 StartScanning();
144 llMoveToTarget(llGetPos(), gTau);
145 }
146
147 sensor(integer num_detected)
148 {
149 rotation TargetRot;
153 if((llGetAnimation(gOwner) == "Flying") || (llGetAnimation(gOwner) == "FlyingSlow"))
154 {
155 TargetRot = llEuler2Rot( FLYANGLE * DEG_TO_RAD) * GetRotation(Rot);
156 POSITION_OFFSET = FLY_OFFSET;
157 llMessageLinked(LINK_THIS, playchannel, "fly", "");
158 }
159 else
160 {
161 TargetRot = GetRotation(Rot);
162
163
164 // update randimly sometimes
165 if (llFrand(4) < 1)
166 {
167 posX = randBetween(0,X);
168 posY = randBetween(0,2);
169 if (llFrand(1) > 0.5)
170 posY = -posY;
171 }
172
173
174 POSITION_OFFSET = <posX , posY, (-size.z / 2) + 0.1>;
175
176 vector pos = llGetPos();
177 if (llVecDist(pos, last) > 1)
178 {
179 last = pos;
180 if (flag == 0) {
181 llMessageLinked(LINK_THIS, playchannel, "stand", "");
182 llSleep(1.0);
183 }
184 llMessageLinked(LINK_THIS, playchannel, "walk", "");
185 flag++;
186 }
187 else
188 {
189 if (flag)
190 {
191 llMessageLinked(LINK_THIS, playchannel, "sit", "");
192 flag = 0;
193 }
194
195 }
196 }
197 vector Offset = POSITION_OFFSET * Rot;
198 Pos += Offset;
199
200 if (llVecDist(startPos,Pos ) > DIST)
201 {
202 if (returning)
203 {
204 llTriggerSound(BYE,1.0);
205 returning = FALSE;
206 }
207 //llLookAt(startPos,gTau * TURNSPEED, gTau);
208 llRotLookAt(startRot, gTau * TURNSPEED, gTau);
209 llMoveToTarget(startPos, gTau * DAMP);
210 }
211 else
212 {
213 if (! returning)
214 {
215 llTriggerSound(GREET,1.0);
216 returning = TRUE;
217 }
218 //llLookAt(Pos,gTau * TURNSPEED, gTau);
219 llRotLookAt(TargetRot, gTau * TURNSPEED, gTau);
220 llMoveToTarget(Pos, gTau * DAMP);
221 }
222
223
224 count=0;
225 repeat=0;
226 }
227
228
229
230 listen(integer channel, string name, key id, string mesg)
231 {
232 mesg = llToLower(mesg);
233 if ((id == gOwner) && (mesg == FOLLOW))
234 {
235 StartScanning();
236 }
237 else if ((id == gOwner) && (mesg == STAY))
238 {
239 StopScanning();
240 }
241 else if ((id == gOwner) && (mesg == "/help"))
242 {
243 help();
244 }
245 else
246 {
247 integer stop;
248 string word;
249 integer check = FALSE;
250 if((id==gOwner) || (name == llGetObjectName())) { check=TRUE;}
251 if(check == FALSE)
252 {
253 do
254 {
255 stop = llSubStringIndex(mesg, " ");
256 if(stop == -1) { stop = 0;}
257 word = llGetSubString(mesg, 0, stop - 1);
258 mesg = llDeleteSubString(mesg, 0, stop);
259 if((word=="brb") || (word=="afk"))
260 {
261 llSay(0,"We wait, hurry back !");
262 stop = 0;
263 }
264 else if((word=="smoke") || (word=="joint"))
265 {
266 llSay(0,"Can this one smoke?");
267 stop = 0;
268 }
269 else if((word=="cool") || (word=="kewl"))
270 {
271 llSay(0,word + ", yes yes yes ");
272 stop = 0;
273 }
274 else if((word=="hi") || (word=="hello") || (word=="Greetings") || (word=="howdy") || (word=="Gday") || (word=="hej"))
275 {
276 llSay(0,word + " " + name + ", :)");
277 stop = 0;
278 }
279 else if((word=="cya") || (word=="bye") || (word=="goodbye"))
280 {
281 llSay(0,word + " " + name + " :)");
282 stop = 0;
283 }
284 else if((word=="food") || (word=="eat") || (word=="ate"))
285 {
286 float rnd = llFrand(10.0);
287 if(rnd < 5) { llSay(0,"Can this one eat too?");}
288 else { llSay(0,name + ", This one is hungry !");}
289 stop = 0;
290 }
291 else if((word=="fuck") || (word=="Fuck") || (word=="FUCK"))
292 {
293 llSay(0,"Ewwww, the F word");
294 stop = 0;
295 }
296
297 } while(stop != 0);
298 }
299 }
300 }
301
303 {
304 integer choice = (integer)llFrand(6.0);
305 if(choice == 1) { llSay(0,"ALT+F4 will fix u Lag!");}
306 else if(choice == 2) { llSay(0,"They touch this one!");}
307 else if(choice == 3) { llSay(0,"Piss off !");}
308 else if(choice == 4) { llSay(0,"U not my Master!");}
309 else if(choice == 5) { llSay(0,"Dont touch my dick, plz !");}
310 else { llSay(0,"Go play with u self !");}
311 }
312
313 on_rez(integer start_param)
314 {
316 }
317 }