corrade-lsl-templates – Blame information for rev 36
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
2 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
29 | office | 2 | // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // |
2 | office | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // |
||
5 | // This script is a simple teleport button that makes Corrade teleport to |
||
6 | // your current location. |
||
7 | // |
||
8 | // For more information on Corrade, please see: |
||
9 | // http://grimore.org/secondlife/scripted_agents/corrade |
||
10 | // |
||
11 | /////////////////////////////////////////////////////////////////////////// |
||
12 | |||
13 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 14 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 15 | /////////////////////////////////////////////////////////////////////////// |
16 | string wasKeyValueGet(string k, string data) { |
||
17 | if(llStringLength(data) == 0) return ""; |
||
18 | if(llStringLength(k) == 0) return ""; |
||
19 | list a = llParseString2List(data, ["&", "="], []); |
||
20 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
||
21 | if(i != -1) return llList2String(a, 2*i+1); |
||
22 | return ""; |
||
23 | } |
||
24 | |||
25 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 26 | // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 27 | /////////////////////////////////////////////////////////////////////////// |
28 | string wasKeyValueEncode(list data) { |
||
29 | list k = llList2ListStrided(data, 0, -1, 2); |
||
30 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
||
31 | data = []; |
||
32 | do { |
||
33 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
||
34 | k = llDeleteSubList(k, 0, 0); |
||
35 | v = llDeleteSubList(v, 0, 0); |
||
36 | } while(llGetListLength(k) != 0); |
||
37 | return llDumpList2String(data, "&"); |
||
38 | } |
||
39 | |||
40 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 41 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 42 | /////////////////////////////////////////////////////////////////////////// |
43 | // escapes a string in conformance with RFC1738 |
||
44 | string wasURLEscape(string i) { |
||
45 | string o = ""; |
||
46 | do { |
||
47 | string c = llGetSubString(i, 0, 0); |
||
48 | i = llDeleteSubString(i, 0, 0); |
||
49 | if(c == "") jump continue; |
||
50 | if(c == " ") { |
||
51 | o += "+"; |
||
52 | jump continue; |
||
53 | } |
||
54 | if(c == "\n") { |
||
55 | o += "%0D" + llEscapeURL(c); |
||
56 | jump continue; |
||
57 | } |
||
58 | o += llEscapeURL(c); |
||
59 | @continue; |
||
60 | } while(i != ""); |
||
61 | return o; |
||
62 | } |
||
63 | |||
64 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 65 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 66 | /////////////////////////////////////////////////////////////////////////// |
67 | // unescapes a string in conformance with RFC1738 |
||
68 | string wasURLUnescape(string i) { |
||
69 | return llUnescapeURL( |
||
70 | llDumpList2String( |
||
71 | llParseString2List( |
||
72 | llDumpList2String( |
||
73 | llParseString2List( |
||
74 | i, |
||
75 | ["+"], |
||
76 | [] |
||
77 | ), |
||
78 | " " |
||
79 | ), |
||
80 | ["%0D%0A"], |
||
81 | [] |
||
82 | ), |
||
83 | "\n" |
||
84 | ) |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | // callback URL |
||
89 | string callback = ""; |
||
90 | |||
91 | // configuration data |
||
92 | string configuration = ""; |
||
93 | |||
94 | default { |
||
95 | state_entry() { |
||
96 | llSetTimerEvent(1); |
||
97 | } |
||
98 | link_message(integer sender, integer num, string message, key id) { |
||
99 | if(sender != 1 || id != "configuration") return; |
||
100 | configuration = message; |
||
101 | state off; |
||
102 | } |
||
103 | timer() { |
||
104 | llMessageLinked(LINK_ROOT, 0, "configuration", NULL_KEY); |
||
105 | } |
||
106 | attach(key id) { |
||
107 | llResetScript(); |
||
108 | } |
||
109 | on_rez(integer num) { |
||
110 | llResetScript(); |
||
111 | } |
||
112 | changed(integer change) { |
||
113 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
||
114 | llResetScript(); |
||
115 | } |
||
116 | } |
||
117 | state_exit() { |
||
118 | llSetTimerEvent(0); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | state off { |
||
123 | state_entry() { |
||
124 | llReleaseControls(); |
||
125 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
126 | } |
||
127 | touch_end(integer num) { |
||
128 | state on; |
||
129 | } |
||
130 | attach(key id) { |
||
131 | llResetScript(); |
||
132 | } |
||
133 | on_rez(integer num) { |
||
134 | llResetScript(); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | state on { |
||
139 | state_entry() { |
||
140 | llSetColor(<0,.5,0>, ALL_SIDES); |
||
141 | state url; |
||
142 | } |
||
143 | attach(key id) { |
||
144 | llResetScript(); |
||
145 | } |
||
146 | on_rez(integer num) { |
||
147 | llResetScript(); |
||
148 | } |
||
149 | } |
||
150 | |||
151 | state url { |
||
152 | state_entry() { |
||
153 | // DEBUG |
||
154 | llOwnerSay("Requesting URL..."); |
||
155 | llRequestURL(); |
||
156 | } |
||
157 | touch_end(integer num) { |
||
158 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
159 | llResetScript(); |
||
160 | } |
||
161 | http_request(key id, string method, string body) { |
||
162 | if(method != URL_REQUEST_GRANTED) return; |
||
163 | callback = body; |
||
164 | // DEBUG |
||
165 | llOwnerSay("Got URL..."); |
||
166 | state teleport; |
||
167 | } |
||
168 | attach(key id) { |
||
169 | llResetScript(); |
||
170 | } |
||
171 | on_rez(integer num) { |
||
172 | llResetScript(); |
||
173 | } |
||
174 | changed(integer change) { |
||
175 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
||
176 | llResetScript(); |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | |||
181 | state teleport { |
||
182 | state_entry() { |
||
183 | // DEBUG |
||
184 | llOwnerSay("Teleporting..."); |
||
31 | office | 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 | |||
2 | office | 209 | llInstantMessage( |
210 | (key)wasKeyValueGet( |
||
211 | "corrade", |
||
212 | configuration |
||
213 | ), |
||
214 | wasKeyValueEncode( |
||
215 | [ |
||
216 | "command", "teleport", |
||
217 | "group", wasURLEscape( |
||
218 | wasKeyValueGet( |
||
31 | office | 219 | "group", |
2 | office | 220 | configuration |
221 | ) |
||
222 | ), |
||
223 | "password", wasURLEscape( |
||
224 | wasKeyValueGet( |
||
225 | "password", |
||
226 | configuration |
||
227 | ) |
||
228 | ), |
||
229 | "entity", "region", |
||
230 | "region", wasURLEscape( |
||
231 | llGetRegionName() |
||
232 | ), |
||
233 | "deanimate", "True", |
||
31 | office | 234 | "position", wasURLEscape((string)position), |
235 | "turnto", wasURLEscape((string)lookAt), |
||
2 | office | 236 | "callback", wasURLEscape(callback) |
237 | ] |
||
238 | ) |
||
239 | ); |
||
31 | office | 240 | |
2 | office | 241 | llSetTimerEvent(60); |
242 | } |
||
243 | timer() { |
||
244 | // DEBUG |
||
245 | llOwnerSay("Teleport failed..."); |
||
246 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
247 | llResetScript(); |
||
248 | } |
||
249 | touch_end(integer num) { |
||
250 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
251 | llResetScript(); |
||
252 | } |
||
253 | http_request(key id, string method, string body) { |
||
254 | llHTTPResponse(id, 200, "OK"); |
||
255 | if(wasKeyValueGet("command", body) != "teleport" || |
||
256 | wasKeyValueGet("success", body) != "True") { |
||
257 | // DEBUG |
||
258 | llOwnerSay("Teleport failed with failure message: " + |
||
259 | wasURLUnescape( |
||
260 | wasKeyValueGet( |
||
31 | office | 261 | "data", |
2 | office | 262 | body |
263 | ) |
||
264 | ) |
||
265 | ); |
||
266 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
267 | llResetScript(); |
||
268 | } |
||
269 | // DEBUG |
||
270 | llOwnerSay("Teleport succeeded..."); |
||
271 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
272 | llResetScript(); |
||
273 | } |
||
274 | attach(key id) { |
||
275 | llResetScript(); |
||
276 | } |
||
277 | on_rez(integer num) { |
||
278 | llResetScript(); |
||
279 | } |
||
280 | changed(integer change) { |
||
281 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
||
282 | llResetScript(); |
||
283 | } |
||
284 | } |
||
285 | state_exit() { |
||
286 | llSetTimerEvent(0); |
||
287 | } |
||
288 | } |