2 // logic system master script
3 // copyright john jamison, imagilearning?
5 // modified by fred huffhines / chris koeritz.
10 vector TEXT_COLOR = <0.6, 0.84, 0.8>; // label color.
11 float RADARTIME = 10.0; // how frequently radar fires.
12 float RANGE = 50.0; // range of the sensor sweeps.
13 integer MAX_AVATAR_AWOLS = 5;
14 // number of times the avatar is allowed to be missed by sensor.
15 // we have seen some unreliability of sensors, so a single miss is not a definite problem.
16 list RESET = ["Restart", "CANCEL"]; // used in a menu someplace?
17 string Choicetimer = "2"; // how long they get to make their choice?
19 // global variables...
20 integer current_awols;
22 key lquery = NULL_KEY;
40 integer CHOICE1POINTS;
41 integer CHOICE2POINTS;
42 integer CHOICE3POINTS;
43 integer CHOICE4POINTS;
44 integer CHOICE5POINTS;
45 integer CHOICE6POINTS;
46 integer CHOICE7POINTS;
47 integer CHOICE8POINTS;
50 string CurrentNoteCard;
51 string resettext = " ";
59 CHOICE = [ CHOICE1TEXT, CHOICE2TEXT, CHOICE3TEXT, CHOICE4TEXT ];
60 llSetText("[System Ready]", TEXT_COLOR, 1);
64 // leave the current setup and completely restart the script.
67 llSay(0, "restarting now because " + reason);
71 // starts looking for our registered user.
74 llSensorRemove(); // clear any existing sensor.
75 //llSay(0, "sweeping for " + user + " aka " + llKey2Name(user));
76 llSensorRepeat("", user, AGENT, RANGE, 2 * PI, RADARTIME); // look for our customer.
79 // what this did before made no sense...
80 // but now it serves to reset the device if the avatar wandered off.
81 handle_sensor(integer numDetected)
83 integer proceed = FALSE;
85 for (i = 0; i < numDetected; i++) {
86 if (llDetectedKey(i) == user) proceed = TRUE;
88 if (proceed) return; // keep running like we were.
89 else reboot("we no longer saw our user here."); // reboot, since we don't see our user.
92 // processes commands coming from other scripts or other parts of the object.
93 handle_link_message(string str, key id)
97 llSetText ("System in use by " + llKey2Name (id), TEXT_COLOR, 1);
98 CurrentNoteCard = llGetObjectDesc();
99 CHANNEL = llRound (llFrand (-394304));
100 llListen (CHANNEL, "", NULL_KEY, "");
101 start_sensor_sweeps();
102 lquery = llGetNotecardLine (CurrentNoteCard, line);
106 // handles notecard data as it is read.
107 process_incoming_data(key query_id, string data)
109 list split_data = llParseString2List (data, [":"], []);
110 string cmd = llToLower(llList2String(split_data, 0));
112 //hmmm: terribly repetitive code here. clean up, shorten.
113 if (cmd == "choicetimer") {
114 Choicetimer = llList2String (split_data, 1);
117 llSay(0, llList2String (split_data, 1));
119 lquery = llGetNotecardLine (CurrentNoteCard, line);
121 if (cmd == "whisper") {
122 llWhisper(0, llList2String (split_data, 1));
124 lquery = llGetNotecardLine (CurrentNoteCard, line);
126 if (cmd == "givenotecard") {
127 llGiveInventory (user, llList2String (split_data, 1));
129 lquery = llGetNotecardLine (CurrentNoteCard, line);
131 if (cmd == "channelsay") {
132 llSay((integer) llList2String (split_data, 1), llList2String (split_data, 2));
134 lquery = llGetNotecardLine (CurrentNoteCard, line);
136 if (cmd == "channelshout") {
137 llShout ((integer) llList2String (split_data, 1),
138 llList2String (split_data, 2));
140 lquery = llGetNotecardLine (CurrentNoteCard, line);
142 if (cmd == "channelwhisper") {
143 llSay((integer) llList2String (split_data, 1), llList2String (split_data, 2));
145 lquery = llGetNotecardLine (CurrentNoteCard, line);
147 if (cmd == "resettext") {
148 resettext = llList2String (split_data, 1);
152 /// CurrentNoteCard = llGetObjectDesc();
154 reboot("notecard said to end processing.");
157 if (cmd == "giveobject") {
158 llGiveInventory (user, llList2String (split_data, 1));
160 lquery = llGetNotecardLine (CurrentNoteCard, line);
162 ///TALK TO VB AS THIS NEXT PART NEEDS A MEDIA RELAY FOR IT TO WORK
163 if (cmd == "videourl") {
164 if (llList2String (split_data, 3) != "") {
165 llParcelMediaCommandList ([PARCEL_MEDIA_COMMAND_URL,
166 llList2String (split_data, 1) + ":" +
167 llList2String (split_data, 2) + ":" +
168 llList2String (split_data, 3) +
169 llList2String (split_data, 4)]);
171 lquery = llGetNotecardLine (CurrentNoteCard, line);
174 llParcelMediaCommandList ([PARCEL_MEDIA_COMMAND_URL,
175 llList2String (split_data, 1) + ":" +
176 llList2String (split_data, 2)]);
178 lquery = llGetNotecardLine (CurrentNoteCard, line);
180 //llSay(-840,llList2String(dat,1));
181 //llSay(-848,llList2String(dat,1));
183 if (cmd == "mediatexture") {
184 llParcelMediaCommandList ([PARCEL_MEDIA_COMMAND_TEXTURE,
185 (key) llList2String (split_data, 1)]);
186 //llSay(-849,llList2String(dat,1));
188 lquery = llGetNotecardLine (CurrentNoteCard, line);
190 if (cmd == "sleep") {
191 llSleep (llList2Float (split_data, 1));
193 lquery = llGetNotecardLine (CurrentNoteCard, line);
195 if (cmd == "audiourl") {
196 llSay(0, "got to audio url");
197 if (llList2String (split_data, 3) != "") {
198 llSetParcelMusicURL (llList2String (split_data, 1) + ":" +
199 llList2String (split_data, 2) + ":" +
200 llList2String (split_data, 3) + llList2String (split_data, 4));
202 lquery = llGetNotecardLine (CurrentNoteCard, line);
206 llSetParcelMusicURL (llList2String (split_data, 1) + ":" +
207 llList2String (split_data, 2));
209 lquery = llGetNotecardLine (CurrentNoteCard, line);
211 //llSay(-840,llList2String(dat,1));
214 if (cmd == "weburl") {
215 llLoadURL (user, llList2String (split_data, 1),
216 llList2String (split_data, 2) + llList2String (split_data,
218 llList2String (split_data, 4));
221 lquery = llGetNotecardLine (CurrentNoteCard, line);
225 if (cmd == "dialog") {
226 DIALOG = llList2String (split_data, 1);
228 lquery = llGetNotecardLine (CurrentNoteCard, line);
230 if (cmd == "choice1") {
231 CHOICE1TEXT = llList2String (split_data, 1);
232 CHOICE1 = llList2String (split_data, 2);
233 dialog = dialog +[llList2String (split_data, 1)];
236 lquery = llGetNotecardLine (CurrentNoteCard, line);
239 if (cmd == "choice2") {
240 CHOICE2TEXT = llList2String (split_data, 1);
241 CHOICE2 = llList2String (split_data, 2);
242 dialog = dialog +[llList2String (split_data, 1)];
244 lquery = llGetNotecardLine (CurrentNoteCard, line);
246 if (cmd == "choice3") {
247 CHOICE3TEXT = llList2String (split_data, 1);
248 CHOICE3 = llList2String (split_data, 2);
249 dialog = dialog +[llList2String (split_data, 1)];
251 lquery = llGetNotecardLine (CurrentNoteCard, line);
253 if (cmd == "choice4") {
254 CHOICE4TEXT = llList2String (split_data, 1);
255 CHOICE4 = llList2String (split_data, 2);
257 dialog = dialog +[llList2String (split_data, 1)];
259 lquery = llGetNotecardLine (CurrentNoteCard, line);
261 if (cmd == "choice5") {
262 CHOICE5TEXT = llList2String (split_data, 1);
263 CHOICE5 = llList2String (split_data, 2);
264 dialog = dialog +[llList2String (split_data, 1)];
267 lquery = llGetNotecardLine (CurrentNoteCard, line);
270 if (cmd == "choice6") {
271 CHOICE6TEXT = llList2String (split_data, 1);
272 CHOICE6 = llList2String (split_data, 2);
273 dialog = dialog +[llList2String (split_data, 1)];
276 lquery = llGetNotecardLine (CurrentNoteCard, line);
280 if (cmd == "choice7") {
281 CHOICE7TEXT = llList2String (split_data, 1);
282 CHOICE7 = llList2String (split_data, 2);
283 dialog = dialog +[llList2String (split_data, 1)];
286 lquery = llGetNotecardLine (CurrentNoteCard, line);
290 if (cmd == "choice8") {
291 CHOICE8TEXT = llList2String (split_data, 1);
292 CHOICE8 = llList2String (split_data, 2);
293 dialog = dialog +[llList2String (split_data, 1)];
296 lquery = llGetNotecardLine (CurrentNoteCard, line);
300 if (cmd == "choice1points") {
301 CHOICE1POINTS = (integer) llList2String (split_data, 1);
303 lquery = llGetNotecardLine (CurrentNoteCard, line);
307 if (cmd == "choice2points") {
308 CHOICE2POINTS = (integer) llList2String (split_data, 1);
310 lquery = llGetNotecardLine (CurrentNoteCard, line);
312 if (cmd == "choice3points") {
313 CHOICE3POINTS = (integer) llList2String (split_data, 1);
315 lquery = llGetNotecardLine (CurrentNoteCard, line);
317 if (cmd == "choice4points") {
318 CHOICE4POINTS = (integer) llList2String (split_data, 1);
320 lquery = llGetNotecardLine (CurrentNoteCard, line);
322 if (cmd == "choice5points") {
323 CHOICE5POINTS = (integer) llList2String (split_data, 1);
325 lquery = llGetNotecardLine (CurrentNoteCard, line);
327 if (cmd == "choice6points") {
328 CHOICE6POINTS = (integer) llList2String (split_data, 1);
330 lquery = llGetNotecardLine (CurrentNoteCard, line);
332 if (cmd == "choice7points") {
333 CHOICE7POINTS = (integer) llList2String (split_data, 1);
335 lquery = llGetNotecardLine (CurrentNoteCard, line);
337 if (cmd == "choice8points") {
338 CHOICE8POINTS = (integer) llList2String (split_data, 1);
340 lquery = llGetNotecardLine (CurrentNoteCard, line);
342 if (cmd == "email") {
343 llEmail (llList2String (split_data, 1),
344 llKey2Name (user) + " Scored " + (string) TotalScore +
345 " On " + llGetObjectDesc (),
346 llKey2Name (user) + " Scored " + (string) TotalScore +
347 " On " + llGetObjectDesc () + "Score As Of " +
351 lquery = llGetNotecardLine (CurrentNoteCard, line);
353 if (cmd == "imuser") {
354 llInstantMessage (user, llList2String (split_data, 1));
358 llInstantMessage (llList2String (split_data, 1), llList2String (split_data, 2));
360 if (cmd == "deadusertime") {
361 RADARTIME = (integer) llList2String (split_data, 1);
364 if (cmd == "deadrange") {
365 RANGE = (integer) llList2String (split_data, 1);
366 start_sensor_sweeps();
369 if (cmd == "finalscore") {
371 "You Scored " + (string) TotalScore + "/" +
372 llList2String (split_data, 1));
374 if (cmd == "playsounduuid") {
375 llPreloadSound (llList2String (split_data, 1));
376 llPlaySound (llList2String (split_data, 1),
377 (integer) llList2String (split_data, 2));
380 if (cmd == "debug") {
382 "System Debug Info follows " + "/n " +
383 (string) "key user = " + (string) user +
384 (string) " key lquery = " + (string) lquery +
385 (string) " integer DEADTIME = " + (string) RADARTIME +
386 "string CHOICE1 = " + CHOICE1 + "string CHOICE2 = " +
387 CHOICE2 + "string CHOICE3 = " + CHOICE3 +
388 "string CHOICE4 = " + CHOICE4 + "string CHOICE1TEXT = " +
389 CHOICE1TEXT + "string CHOICE2TEXT = " + CHOICE2TEXT +
390 "string CHOICE3TEXT= " + CHOICE3TEXT +
391 "string CHOICE4TEXT= " + CHOICE4TEXT +
392 "integer CHOICE1POINTS" + (string) CHOICE1POINTS +
393 "integer CHOICE2POINTS" + (string) CHOICE2POINTS +
394 "integer CHOICE3POINTS" + (string) CHOICE3POINTS +
395 "integer CHOICE4POINTS" + (string) CHOICE4POINTS +
396 "integer Choicetimer = " + (string) Choicetimer +
397 "integer TotalScore =" + (string) TotalScore +
398 "string DIOALOGE = " + DIALOG +
399 "string CurrentNoteCard = " + CurrentNoteCard +
400 "string resettext = " + resettext +
401 "list RESET = [Restart,CANCEL]" + "list CHOICE = " +
402 (string) CHOICE + "integer line = " + (string) line);
407 if (eof != 2 | eof == 1) {
409 llSetTimerEvent ((float) Choicetimer);
413 lquery = llGetNotecardLine (CurrentNoteCard, line);
417 // process what the device hears spoken nearby.
418 hear_voices(integer channel, string name, key id, string message)
420 //hmmm: bunkum. do this as a list.
421 if (message == CHOICE1TEXT) {
422 CurrentNoteCard = CHOICE1;
426 TotalScore = TotalScore + CHOICE1POINTS;
427 lquery = llGetNotecardLine (CurrentNoteCard, line);
429 if (message == CHOICE2TEXT) {
430 CurrentNoteCard = CHOICE2;
434 TotalScore = TotalScore + CHOICE2POINTS;
435 lquery = llGetNotecardLine (CurrentNoteCard, line);
437 if (message == CHOICE3TEXT) {
438 CurrentNoteCard = CHOICE3;
442 TotalScore = TotalScore + CHOICE3POINTS;
443 lquery = llGetNotecardLine (CurrentNoteCard, line);
445 if (message == CHOICE4TEXT) {
446 CurrentNoteCard = CHOICE4;
450 TotalScore = TotalScore + CHOICE4POINTS;
451 lquery = llGetNotecardLine (CurrentNoteCard, line);
453 if (message == CHOICE5TEXT) {
454 CurrentNoteCard = CHOICE5;
458 TotalScore = TotalScore + CHOICE5POINTS;
459 lquery = llGetNotecardLine (CurrentNoteCard, line);
461 if (message == CHOICE6TEXT) {
462 CurrentNoteCard = CHOICE6;
466 TotalScore = TotalScore + CHOICE6POINTS;
467 lquery = llGetNotecardLine (CurrentNoteCard, line);
469 if (message == CHOICE7TEXT) {
470 CurrentNoteCard = CHOICE7;
474 TotalScore = TotalScore + CHOICE7POINTS;
475 lquery = llGetNotecardLine (CurrentNoteCard, line);
477 if (message == CHOICE8TEXT) {
478 CurrentNoteCard = CHOICE8;
482 TotalScore = TotalScore + CHOICE8POINTS;
483 lquery = llGetNotecardLine (CurrentNoteCard, line);
485 if (message == "Restart") {
488 lquery = llGetNotecardLine (CurrentNoteCard, line);
494 // ensure stops running if kept in updater object.
497 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
498 on_rez(integer parm) { state rerun; }
500 state rerun { state_entry() { state default; } }
502 // main state engine.
510 reboot("object just rezzed.");
515 //llSay(0, "sensor missed avatar.");
516 if (current_awols > MAX_AVATAR_AWOLS) {
517 reboot("avatar was missed by sensor sweep too many times.");
521 sensor (integer numDetected) {
523 //llSay(0, "sensor saw avatar.");
524 handle_sensor(numDetected);
527 link_message (integer sender_num, integer num, string str, key id) {
528 handle_link_message(str, id);
531 touch_start (integer total_number) {
533 for (i = 0; i < total_number; i++) {
534 if (llDetectedKey(i) == user) {
535 llDialog (user, resettext, RESET, CHANNEL);
541 listen (integer channel, string name, key id, string message) {
542 hear_voices(channel, name, id, message);
545 dataserver (key query_id, string data) {
546 process_incoming_data(query_id, data);
549 collision_start(integer total_number)
551 if (user == NULL_KEY) {
552 //llSay(0, "sending startup link message.");
553 handle_link_message("user", llDetectedKey(0));
558 llDialog (user, DIALOG, dialog, CHANNEL);