sloodle_quiz_ui.lslp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle quiz chair UI
  4. // Controls the movement of the quiz chair, based on linked messages from the main script.
  5. // It should be possible to radically alter the object, eg. change it into an aeroplane etc - by altering this script.
  6. // Part of the Sloodle project (www.sloodle.org)
  7. //
  8. // Copyright (c) 2006-9 Sloodle (various contributors)
  9. // Released under the GNU GPL
  10. //
  11. // Contributors:
  12. // Edmund Edgar
  13. // Paul Preibisch
  14. // Peter R. Bloomfield
  15. //
  16. integer SLOODLE_CHANNEL_OBJECT_DIALOG= -3857343;
  17. integer SLOODLE_CHANNEL_QUIZ_START_FOR_AVATAR = -1639271102; //Tells us to start a quiz for the avatar, if possible.; Ordinary quiz chair will have a second script that detects and avatar sitting on it and sends it. Awards-integrated version waits for a game ID to be set before doing this.
  18. integer SLOODLE_CHANNEL_QUIZ_STARTED_FOR_AVATAR = -1639271103; //Sent by main quiz script to tell UI scripts that quiz has started for avatar with key
  19. integer SLOODLE_CHANNEL_1QUIZ_COMPLETED_FOR_AVATAR = -1639271104; //Sent by main quiz script to tell UI scripts that quiz has finished for avatar with key, with x/y correct in string
  20. integer SLOODLE_CHANNEL_QUESTION_ASKED_AVATAR = -1639271105; //Sent by main quiz script to tell UI scripts that question has been asked to avatar with key. String contains question ID + "|" + question text
  21. integer SLOODLE_CHANNEL_QUESTION_ANSWERED_AVATAR = -1639271106; //Sent by main quiz script to tell UI scripts that question has been answered by avatar with key. String contains selected option ID + "|" + option text + "|"
  22. integer SLOODLE_CHANNEL_QUIZ_LOADING_QUESTION = -1639271107;
  23. integer SLOODLE_CHANNEL_QUIZ_LOADED_QUESTION = -1639271108;
  24. integer SLOODLE_CHANNEL_QUIZ_LOADING_QUIZ = -1639271109;
  25. integer SLOODLE_CHANNEL_QUIZ_LOADED_QUIZ = -1639271110;
  26. integer SLOODLE_CHANNEL_QUIZ_GO_TO_STARTING_POSITION = -1639271111;
  27. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION = -1639271112; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key.
  28. integer SLOODLE_CHANNEL_ANSWER_SCORE_FOR_AVATAR = -1639271113; // Tells anyone who might be interested that we scored the answer. Score in string, avatar in key.
  29. integer SLOODLE_CHANNEL_QUIZ_STATE_ENTRY_DEFAULT = -1639271114; //mod quiz script is in state DEFAULT
  30. integer SLOODLE_CHANNEL_QUIZ_STATE_ENTRY_QUIZZING = -1639271117; //mod quiz script is in state quizzing
  31. integer SLOODLE_CHANNEL_QUIZ_STOP_FOR_AVATAR = -1639271119; //Tells us to STOP a quiz for the avatar
  32. integer SLOODLE_CHANNEL_QUIZ_NO_PERMISSION_USE= -1639271118; //user has tried to use the chair but doesnt have permission to do so.
  33. integer SLOODLE_CHANNEL_QUIZ_SUCCESS_NOTHING_MORE_TO_DO_WITH_AVATAR= -1639271122;
  34. integer SLOODLE_CHANNEL_QUIZ_FAILURE_NOTHING_MORE_TO_DO_WITH_AVATAR= -1639271123;
  35. vector startingposition=<0,0,0>;
  36. integer doPlaySound = 0;
  37. integer doRepeat = 0; // whether we should run through the questions again when we're done
  38. key sitter;
  39. move_to_start( vector startingposition )
  40. {
  41. vector position = llGetPos();
  42. if (startingposition==<0,0,0>){
  43. startingposition=position;
  44. }
  45. position.z = startingposition.z;
  46. llSetPos(position);
  47. }
  48. // Configure by receiving a linked message from another script in the object
  49. // Returns TRUE if the object has all the data it needs
  50. integer sloodle_handle_command(string str)
  51. {
  52. list bits = llParseString2List(str,["|"],[]);
  53. integer numbits = llGetListLength(bits);
  54. string name = llList2String(bits,0);
  55. if (name == "set:sloodleplaysound") doPlaySound = (integer)llList2String(bits,1);
  56. return 1;
  57. }
  58. // Move the chair up or down as visual feedback
  59. move_vertical(float multiplier)
  60. {
  61. vector position = llGetPos();
  62. position.z += 0.5 * multiplier;
  63. llSetPos(position);
  64. }
  65. // Play a sound as audio feedback
  66. play_sound(float multiplier)
  67. {
  68. // Do nothing if sound is disabled
  69. if (doPlaySound == 0) {
  70. return;
  71. }
  72. string sound_file;
  73. float volume;
  74. // Determine what our sound file and volume should be
  75. if (multiplier > 0) {
  76. sound_file = "Correct";
  77. } else {
  78. sound_file = "Incorrect";
  79. multiplier = multiplier * -1;
  80. }
  81. // Cap our volume
  82. if (multiplier > 1) {
  83. volume = 1.0;
  84. } else {
  85. volume = (float)multiplier;
  86. }
  87. // Make sure the sound file exists, and then play it
  88. if (llGetInventoryType(sound_file) == INVENTORY_SOUND) {
  89. llTriggerSound(sound_file,multiplier);
  90. }
  91. }
  92. default
  93. {
  94. on_rez(integer start_param) {
  95. llResetScript();
  96. }
  97. state_entry() {
  98. }
  99. link_message(integer sender_num, integer num, string str, key id)
  100. {
  101. if (num==SLOODLE_CHANNEL_QUIZ_SUCCESS_NOTHING_MORE_TO_DO_WITH_AVATAR){
  102. llUnSit(id);
  103. move_to_start( startingposition );
  104. }else
  105. if (num==SLOODLE_CHANNEL_QUIZ_FAILURE_NOTHING_MORE_TO_DO_WITH_AVATAR){
  106. llUnSit(id);
  107. move_to_start( startingposition );
  108. }else
  109. if (num == SLOODLE_CHANNEL_QUIZ_GO_TO_STARTING_POSITION) {
  110. move_to_start( startingposition );
  111. } else if (num == SLOODLE_CHANNEL_ANSWER_SCORE_FOR_AVATAR) {
  112. move_vertical( (float)str );
  113. play_sound( (float)str );
  114. }else if (num == SLOODLE_CHANNEL_QUIZ_STATE_ENTRY_QUIZZING){
  115. move_to_start( startingposition );
  116. }else if (num==SLOODLE_CHANNEL_QUIZ_NO_PERMISSION_USE){
  117. if (id!=NULL_KEY){
  118. llUnSit(id);
  119. }
  120. }
  121. else if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  122. // Split the message into lines
  123. list lines = llParseString2List(str, ["\n"], []);
  124. integer numlines = llGetListLength(lines);
  125. integer i = 0;
  126. for (i=0; i < numlines; i++) {
  127. sloodle_handle_command(llList2String(lines, i));
  128. }
  129. }
  130. }
  131. changed(integer change) {
  132. if(change & (CHANGED_LINK)){
  133. sitter = llAvatarOnSitTarget();
  134. if (sitter!=NULL_KEY){
  135. startingposition = llGetPos();
  136. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_QUIZ_START_FOR_AVATAR, "", sitter);
  137. }else {
  138. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_QUIZ_STOP_FOR_AVATAR, "", sitter);
  139. move_to_start( startingposition );
  140. }
  141. }
  142. }
  143. }
  144. // Please leave the following line intact to show where the script lives in Git:
  145. // SLOODLE LSL Script Git Location: mod/quiz-1.0/objects/default/assets/sloodle_quiz_ui.lslp