corrade-lsl-templates – Diff between revs 29 and 31

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 29 Rev 31
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 //
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
4 // 4 //
5 // This script is a simple teleport button that makes Corrade teleport to 5 // This script is a simple teleport button that makes Corrade teleport to
6 // your current location. 6 // your current location.
7 // 7 //
8 // For more information on Corrade, please see: 8 // For more information on Corrade, please see:
9 // http://grimore.org/secondlife/scripted_agents/corrade 9 // http://grimore.org/secondlife/scripted_agents/corrade
10 // 10 //
11 /////////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////////
12   12  
13 /////////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////////
14 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 14 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
15 /////////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////////
16 string wasKeyValueGet(string k, string data) { 16 string wasKeyValueGet(string k, string data) {
17 if(llStringLength(data) == 0) return ""; 17 if(llStringLength(data) == 0) return "";
18 if(llStringLength(k) == 0) return ""; 18 if(llStringLength(k) == 0) return "";
19 list a = llParseString2List(data, ["&", "="], []); 19 list a = llParseString2List(data, ["&", "="], []);
20 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); 20 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
21 if(i != -1) return llList2String(a, 2*i+1); 21 if(i != -1) return llList2String(a, 2*i+1);
22 return ""; 22 return "";
23 } 23 }
24 24
25 /////////////////////////////////////////////////////////////////////////// 25 ///////////////////////////////////////////////////////////////////////////
26 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 26 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
27 /////////////////////////////////////////////////////////////////////////// 27 ///////////////////////////////////////////////////////////////////////////
28 string wasKeyValueEncode(list data) { 28 string wasKeyValueEncode(list data) {
29 list k = llList2ListStrided(data, 0, -1, 2); 29 list k = llList2ListStrided(data, 0, -1, 2);
30 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); 30 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
31 data = []; 31 data = [];
32 do { 32 do {
33 data += llList2String(k, 0) + "=" + llList2String(v, 0); 33 data += llList2String(k, 0) + "=" + llList2String(v, 0);
34 k = llDeleteSubList(k, 0, 0); 34 k = llDeleteSubList(k, 0, 0);
35 v = llDeleteSubList(v, 0, 0); 35 v = llDeleteSubList(v, 0, 0);
36 } while(llGetListLength(k) != 0); 36 } while(llGetListLength(k) != 0);
37 return llDumpList2String(data, "&"); 37 return llDumpList2String(data, "&");
38 } 38 }
39   39  
40 /////////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////////
41 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 41 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
42 /////////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////////
43 // escapes a string in conformance with RFC1738 43 // escapes a string in conformance with RFC1738
44 string wasURLEscape(string i) { 44 string wasURLEscape(string i) {
45 string o = ""; 45 string o = "";
46 do { 46 do {
47 string c = llGetSubString(i, 0, 0); 47 string c = llGetSubString(i, 0, 0);
48 i = llDeleteSubString(i, 0, 0); 48 i = llDeleteSubString(i, 0, 0);
49 if(c == "") jump continue; 49 if(c == "") jump continue;
50 if(c == " ") { 50 if(c == " ") {
51 o += "+"; 51 o += "+";
52 jump continue; 52 jump continue;
53 } 53 }
54 if(c == "\n") { 54 if(c == "\n") {
55 o += "%0D" + llEscapeURL(c); 55 o += "%0D" + llEscapeURL(c);
56 jump continue; 56 jump continue;
57 } 57 }
58 o += llEscapeURL(c); 58 o += llEscapeURL(c);
59 @continue; 59 @continue;
60 } while(i != ""); 60 } while(i != "");
61 return o; 61 return o;
62 } 62 }
63   63  
64 /////////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////////
65 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 65 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
66 /////////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////////
67 // unescapes a string in conformance with RFC1738 67 // unescapes a string in conformance with RFC1738
68 string wasURLUnescape(string i) { 68 string wasURLUnescape(string i) {
69 return llUnescapeURL( 69 return llUnescapeURL(
70 llDumpList2String( 70 llDumpList2String(
71 llParseString2List( 71 llParseString2List(
72 llDumpList2String( 72 llDumpList2String(
73 llParseString2List( 73 llParseString2List(
74 i, 74 i,
75 ["+"], 75 ["+"],
76 [] 76 []
77 ), 77 ),
78 " " 78 " "
79 ), 79 ),
80 ["%0D%0A"], 80 ["%0D%0A"],
81 [] 81 []
82 ), 82 ),
83 "\n" 83 "\n"
84 ) 84 )
85 ); 85 );
86 } 86 }
87   87  
88 // callback URL 88 // callback URL
89 string callback = ""; 89 string callback = "";
90   90  
91 // configuration data 91 // configuration data
92 string configuration = ""; 92 string configuration = "";
93   93  
94 default { 94 default {
95 state_entry() { 95 state_entry() {
96 llSetTimerEvent(1); 96 llSetTimerEvent(1);
97 } 97 }
98 link_message(integer sender, integer num, string message, key id) { 98 link_message(integer sender, integer num, string message, key id) {
99 if(sender != 1 || id != "configuration") return; 99 if(sender != 1 || id != "configuration") return;
100 configuration = message; 100 configuration = message;
101 state off; 101 state off;
102 } 102 }
103 timer() { 103 timer() {
104 llMessageLinked(LINK_ROOT, 0, "configuration", NULL_KEY); 104 llMessageLinked(LINK_ROOT, 0, "configuration", NULL_KEY);
105 } 105 }
106 attach(key id) { 106 attach(key id) {
107 llResetScript(); 107 llResetScript();
108 } 108 }
109 on_rez(integer num) { 109 on_rez(integer num) {
110 llResetScript(); 110 llResetScript();
111 } 111 }
112 changed(integer change) { 112 changed(integer change) {
113 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { 113 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
114 llResetScript(); 114 llResetScript();
115 } 115 }
116 } 116 }
117 state_exit() { 117 state_exit() {
118 llSetTimerEvent(0); 118 llSetTimerEvent(0);
119 } 119 }
120 } 120 }
121   121  
122 state off { 122 state off {
123 state_entry() { 123 state_entry() {
124 llReleaseControls(); 124 llReleaseControls();
125 llSetColor(<.5,0,0>, ALL_SIDES); 125 llSetColor(<.5,0,0>, ALL_SIDES);
126 } 126 }
127 touch_end(integer num) { 127 touch_end(integer num) {
128 state on; 128 state on;
129 } 129 }
130 attach(key id) { 130 attach(key id) {
131 llResetScript(); 131 llResetScript();
132 } 132 }
133 on_rez(integer num) { 133 on_rez(integer num) {
134 llResetScript(); 134 llResetScript();
135 } 135 }
136 } 136 }
137   137  
138 state on { 138 state on {
139 state_entry() { 139 state_entry() {
140 llSetColor(<0,.5,0>, ALL_SIDES); 140 llSetColor(<0,.5,0>, ALL_SIDES);
141 state url; 141 state url;
142 } 142 }
143 attach(key id) { 143 attach(key id) {
144 llResetScript(); 144 llResetScript();
145 } 145 }
146 on_rez(integer num) { 146 on_rez(integer num) {
147 llResetScript(); 147 llResetScript();
148 } 148 }
149 } 149 }
150   150  
151 state url { 151 state url {
152 state_entry() { 152 state_entry() {
153 // DEBUG 153 // DEBUG
154 llOwnerSay("Requesting URL..."); 154 llOwnerSay("Requesting URL...");
155 llRequestURL(); 155 llRequestURL();
156 } 156 }
157 touch_end(integer num) { 157 touch_end(integer num) {
158 llSetColor(<.5,0,0>, ALL_SIDES); 158 llSetColor(<.5,0,0>, ALL_SIDES);
159 llResetScript(); 159 llResetScript();
160 } 160 }
161 http_request(key id, string method, string body) { 161 http_request(key id, string method, string body) {
162 if(method != URL_REQUEST_GRANTED) return; 162 if(method != URL_REQUEST_GRANTED) return;
163 callback = body; 163 callback = body;
164 // DEBUG 164 // DEBUG
165 llOwnerSay("Got URL..."); 165 llOwnerSay("Got URL...");
166 state teleport; 166 state teleport;
167 } 167 }
168 attach(key id) { 168 attach(key id) {
169 llResetScript(); 169 llResetScript();
170 } 170 }
171 on_rez(integer num) { 171 on_rez(integer num) {
172 llResetScript(); 172 llResetScript();
173 } 173 }
174 changed(integer change) { 174 changed(integer change) {
175 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { 175 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
176 llResetScript(); 176 llResetScript();
177 } 177 }
178 } 178 }
179 } 179 }
180   180  
181 state teleport { 181 state teleport {
182 state_entry() { 182 state_entry() {
183 // DEBUG 183 // DEBUG
184 llOwnerSay("Teleporting..."); 184 llOwnerSay("Teleporting...");
-   185
-   186 /*
-   187 * These calculations achieve the following:
-   188 * - teleport Corrade in front of you at a distance the size of your bounding box,
-   189 * - make Corrade turn towards 1m in front of its position after the teleport
-   190 * The reason for doing this is that radar object detection is dependent on the
-   191 * position that Corrade is facing.
-   192 */
-   193
-   194 // Get the avatar global position and rotation.
-   195 list details = llGetObjectDetails(llGetOwner(), [OBJECT_POS, OBJECT_ROT]);
-   196
-   197 // Extract the position and rotation.
-   198 vector pos = llList2Vector(details, 0);
-   199 quaternion rot = llList2Rot(details, 1);
-   200 // Compute the scale of the avatar (side of cuboid).
-   201 list box = llGetBoundingBox(llGetOwner());
-   202 vector a = llList2Vector(box, 0);
-   203 vector b = llList2Vector(box, 1);
-   204 float size = b.x - a.x;
-   205
-   206 vector position = <size, 0, 0> * rot + llGetPos();
-   207 vector lookAt = (<1, 0, 0> + <size, 0, 0>) * rot + llGetPos();
-   208
185 llInstantMessage( 209 llInstantMessage(
186 (key)wasKeyValueGet( 210 (key)wasKeyValueGet(
187 "corrade", 211 "corrade",
188 configuration 212 configuration
189 ), 213 ),
190 wasKeyValueEncode( 214 wasKeyValueEncode(
191 [ 215 [
192 "command", "teleport", 216 "command", "teleport",
193 "group", wasURLEscape( 217 "group", wasURLEscape(
194 wasKeyValueGet( 218 wasKeyValueGet(
195 "group", 219 "group",
196 configuration 220 configuration
197 ) 221 )
198 ), 222 ),
199 "password", wasURLEscape( 223 "password", wasURLEscape(
200 wasKeyValueGet( 224 wasKeyValueGet(
201 "password", 225 "password",
202 configuration 226 configuration
203 ) 227 )
204 ), 228 ),
205 "entity", "region", 229 "entity", "region",
206 "region", wasURLEscape( 230 "region", wasURLEscape(
207 llGetRegionName() 231 llGetRegionName()
208 ), 232 ),
209 "deanimate", "True", 233 "deanimate", "True",
210 "position", llGetPos(), 234 "position", wasURLEscape((string)position),
-   235 "turnto", wasURLEscape((string)lookAt),
211 "callback", wasURLEscape(callback) 236 "callback", wasURLEscape(callback)
212 ] 237 ]
213 ) 238 )
214 ); 239 );
-   240
215 llSetTimerEvent(60); 241 llSetTimerEvent(60);
216 } 242 }
217 timer() { 243 timer() {
218 // DEBUG 244 // DEBUG
219 llOwnerSay("Teleport failed..."); 245 llOwnerSay("Teleport failed...");
220 llSetColor(<.5,0,0>, ALL_SIDES); 246 llSetColor(<.5,0,0>, ALL_SIDES);
221 llResetScript(); 247 llResetScript();
222 } 248 }
223 touch_end(integer num) { 249 touch_end(integer num) {
224 llSetColor(<.5,0,0>, ALL_SIDES); 250 llSetColor(<.5,0,0>, ALL_SIDES);
225 llResetScript(); 251 llResetScript();
226 } 252 }
227 http_request(key id, string method, string body) { 253 http_request(key id, string method, string body) {
228 llHTTPResponse(id, 200, "OK"); 254 llHTTPResponse(id, 200, "OK");
229 if(wasKeyValueGet("command", body) != "teleport" || 255 if(wasKeyValueGet("command", body) != "teleport" ||
230 wasKeyValueGet("success", body) != "True") { 256 wasKeyValueGet("success", body) != "True") {
231 // DEBUG 257 // DEBUG
232 llOwnerSay("Teleport failed with failure message: " + 258 llOwnerSay("Teleport failed with failure message: " +
233 wasURLUnescape( 259 wasURLUnescape(
234 wasKeyValueGet( 260 wasKeyValueGet(
235 "error", 261 "data",
236 body 262 body
237 ) 263 )
238 ) 264 )
239 ); 265 );
240 llSetColor(<.5,0,0>, ALL_SIDES); 266 llSetColor(<.5,0,0>, ALL_SIDES);
241 llResetScript(); 267 llResetScript();
242 } 268 }
243 // DEBUG 269 // DEBUG
244 llOwnerSay("Teleport succeeded..."); 270 llOwnerSay("Teleport succeeded...");
245 llSetColor(<.5,0,0>, ALL_SIDES); 271 llSetColor(<.5,0,0>, ALL_SIDES);
246 llResetScript(); 272 llResetScript();
247 } 273 }
248 attach(key id) { 274 attach(key id) {
249 llResetScript(); 275 llResetScript();
250 } 276 }
251 on_rez(integer num) { 277 on_rez(integer num) {
252 llResetScript(); 278 llResetScript();
253 } 279 }
254 changed(integer change) { 280 changed(integer change) {
255 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { 281 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
256 llResetScript(); 282 llResetScript();
257 } 283 }
258 } 284 }
259 state_exit() { 285 state_exit() {
260 llSetTimerEvent(0); 286 llSetTimerEvent(0);
261 } 287 }
262 } 288 }
263   289  
264
Generated by GNU Enscript 1.6.5.90.
290
Generated by GNU Enscript 1.6.5.90.
265   291  
266   292  
267   293