aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/locator_beacon_script.lsl
diff options
context:
space:
mode:
Diffstat (limited to 'locator_beacon_script.lsl')
-rw-r--r--locator_beacon_script.lsl130
1 files changed, 130 insertions, 0 deletions
diff --git a/locator_beacon_script.lsl b/locator_beacon_script.lsl
new file mode 100644
index 0000000..4441993
--- /dev/null
+++ b/locator_beacon_script.lsl
@@ -0,0 +1,130 @@
1// Onefang's locator beacon script version 1.0.
2
3// A lot of this is just my tweaked up warpPos(), the rest is mostly trivial.
4// So I'll put this into the public domain.
5
6integer SIM_CHANNEL = -65767365;
7float offset = 128.0;
8integer jumpSize = 512;
9
10goThere(vector destPos)
11{
12 float distance = llVecDist(llGetPos(), destPos);
13
14 if (distance > 0.001)
15 {
16 integer jumps = 0;
17 integer time = llGetUnixTime();
18 float oldDistance = 0;
19 //llSetPos(destPos); // This is not any faster, and only has a range of 10 meters.
20 //destPos += <0.0, 0.0, 2.0>; // Try to work around that damned Havok 4 bug.
21
22 // We call the central routine several times to free the massive amount of memory used.
23 do
24 {
25 jumps += warpPos(distance, destPos);
26 distance = llVecDist(llGetPos(), destPos);
27 }
28 while (distance > 1.0 && ((llGetUnixTime() - time) < 2)); // Long jump, no limit.
29
30 // OK, this is just being paranoid, but has been known to be needed in the past.
31 while ((distance > 0.001) && (0.001 < (distance - oldDistance)) // Failsafe.
32 && ((--jumps) > 0) && ((llGetUnixTime() - time) < 5)) // Time out.
33 {
34 llOwnerSay("Short hop from " + (string) llGetPos() + " of " + (string) distance + ". Jumps " + (string) jumps);
35 llSetPos(destPos);
36 oldDistance = distance;
37 distance = llVecDist(llGetPos(), destPos);
38 llSleep(0.5);
39 }
40 if (distance > 0.001)
41 {
42 llShout(0, "Failed to get to " + (string) destPos + ", I am @ " + (string) llGetPos());
43 llInstantMessage(llGetOwner(), "Failed to get to " + (string) destPos + ", I am @ " + (string) llGetPos());
44 }
45 }
46}
47
48integer warpPos(float distance, vector destPos)
49{ // R&D by Keknehv Psaltery, 05/25/2006
50 // with a little pokeing by Strife, and a bit more
51 // some more munging by Talarus Luan
52 // Final cleanup by Keknehv Psaltery
53 // Extended distance by onefang Rejected.
54 // More optimizations by 1fang Fang.
55
56 // Compute the number of jumps necessary.
57 integer jumps = (integer) (distance / 10.0) + 1;
58 list rules = [PRIM_POSITION, destPos]; // The start for the rules list.
59 integer count = 1;
60
61 // Try and avoid stack/heap collisions.
62 if (jumps > jumpSize)
63 {
64 jumps = jumpSize;
65 llOwnerSay("Extra warp needed");
66 }
67 while ((count = count << 1 ) < jumps)
68 rules += rules;
69
70 //Changed by Eddy Ofarrel to tighten memory use some more
71 llSetPrimitiveParams(rules + llList2List(rules, (count - jumps) << 1, count));
72//llOwnerSay("Jumps " + (string) jumps + " free " + (string) llGetFreeMemory());
73 return jumps;
74}
75
76init()
77{
78 vector scale = llGetScale();
79
80 offset = scale.z / 2;
81 llListen(SIM_CHANNEL, "", NULL_KEY, "");
82}
83
84default
85{
86 state_entry()
87 {
88 init();
89 }
90
91 on_rez(integer param)
92 {
93 SIM_CHANNEL = param;
94 init();
95 }
96
97 attach(key attached)
98 {
99 init();
100 }
101
102 listen(integer channel, string name, key id, string message)
103 {
104 if ("beacon " == llGetSubString(message, 0, 6))
105 {
106 vector pos = (vector) llGetSubString(message, 7, -1);
107
108 if (ZERO_VECTOR != pos)
109 {
110 pos.z += offset;
111 // OpenSim bug, first one doesn't quite get there, second one needed.
112 // Happens with llSetPos() as well, llSetPrimitiveParams() at least does them both at once.
113 // Need warpPos anyway, which hides this bug.
114 goThere(pos);
115 llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 1.0]);
116 llSetAlpha(1.0, ALL_SIDES);
117 }
118 }
119 else if ("nobeacon" == message)
120 llDie();
121 }
122
123 touch_start(integer num_detected)
124 {
125 vector pos = llGetPos();
126
127 pos.z -= offset;
128 llMapDestination(llGetRegionName(), pos, pos);
129 }
130}