timer.lslp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /*
  4. * Part of the Sloodle project (www.sloodle.org)
  5. *
  6. * Copyright (c) 2011-06 contributors (see below)
  7. * Released under the GNU GPL v3
  8. * -------------------------------------------
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * All scripts must maintain this copyrite information, including the contributer information listed
  24. *
  25. * Contributors:
  26. * Paul Preibisch
  27. * Edmund Edgar
  28. *
  29. * DESCRIPTION
  30. * llMessageLinked(LINK_SET,SLOODLE_TIMER_RESTART, (string)TIME_LIMIT+"|"+"SND_BUZZER|QUESTION TIME LIMIT REACHED", "");
  31. */
  32. integer TIME_LIMIT=10;//default, but can be set in config
  33. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343; // an arbitrary channel the sloodle scripts will use to talk to each other. Doesn't atter what it is, as long as the same thing is set in the sloodle_slave script.
  34. string sloodleserverroot = "";
  35. integer sloodlecontrollerid = 0;
  36. string sloodlepwd = "";
  37. string END_SOUND;
  38. integer sloodlemoduleid = 0;
  39. string TIMES_UP_MESSAGE;
  40. integer sloodleobjectaccessleveluse = 0; // Who can use this object?
  41. integer sloodleobjectaccesslevelctrl = 0; // Who can control this object?
  42. integer sloodleserveraccesslevel = 0; // Who can use the server resource? (Value passed straight back to Moodle)
  43. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  44. string SLOODLE_EOF = "sloodleeof";
  45. integer eof = FALSE; // Have we reached the end of the configuration data?
  46. integer SLOODLE_CHANNEL_QUIZ_MASTER_REQUEST= -1639277006;
  47. integer SLOODLE_CHANNEL_USER_TOUCH = -1639277002;//user touched object
  48. integer SLOODLE_CHANNEL_QUIZ_MASTER_RESPONSE= -1639277008;
  49. integer SLOODLE_CHANNEL_QUIZ_LOADING_QUIZ = -1639271109;
  50. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  51. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651;
  52. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  53. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  54. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  55. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  56. string SLOODLE_TRANSLATE_DIALOG = "dialog"; // Recipient avatar should be identified in link message keyval. At least 2 output parameters: first the channel number for the dialog, and then 1 to 12 button label strings.
  57. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  58. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  59. string SLOODLE_TRANSLATE_HOVER_TEXT_LINKED_PRIM= "hovertext_linked_prim"; // 3 output parameters: colour <r,g,b>, alpha value, link number
  60. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  61. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  62. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  63. vector RED =<1.00000, 0.00000, 0.00000>;
  64. vector ORANGE=<1.00000, 0.43763, 0.02414>;
  65. vector YELLOW=<1.00000, 1.00000, 0.00000>;
  66. vector GREEN=<0.00000, 1.00000, 0.00000>;
  67. vector BLUE=<0.00000, 0.00000, 1.00000>;
  68. vector BABYBLUE=<0.00000, 1.00000, 1.00000>;
  69. vector PINK=<1.00000, 0.00000, 1.00000>;
  70. vector PURPLE=<0.57338, 0.25486, 1.00000>;
  71. vector BLACK= <0.00000, 0.00000, 0.00000>;
  72. vector WHITE= <1.00000, 1.00000, 1.00000>;
  73. vector AVCLASSBLUE= <0.06274,0.247058,0.35294>;
  74. vector AVCLASSLIGHTBLUG=<0.8549,0.9372,0.9686>;//#daeff7
  75. integer SLOODLE_TIMER_START= -1639277011; //shoudl be used to starts the timer from its current position
  76. integer SLOODLE_TIMER_RESTART= -1639277012;//should be used to set the counter to 0 and begin counting down again
  77. integer SLOODLE_TIMER_STOP= -1639277013;//should stop the timer at its current position
  78. integer SLOODLE_TIMER_STOP_AND_RESET= -1639277014;//should stop the timer at its current position and reset count to 0
  79. integer SLOODLE_TIMER_RESET= -1639277015;//shoudl reset the count back to zero but not restart the timer
  80. integer SLOODLE_TIMER_TIMES_UP= -1639277016;//used to transmit the timer reached its time limit
  81. integer COUNT=0;
  82. sloodle_error_code(string method, key avuuid,integer statuscode, string msg){
  83. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|"+(string)statuscode+"|"+(string)msg, NULL_KEY);
  84. }
  85. sloodle_debug(string msg){
  86. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  87. }
  88. // Send a translation request link message
  89. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch){
  90. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  91. }
  92. integer get_prim(string name){
  93. integer num_links=llGetNumberOfPrims();
  94. integer i;
  95. integer prim=-1;
  96. for (i=0;i<=num_links;i++){
  97. if (llGetLinkName(i)==name){
  98. prim=i;
  99. }else{
  100. }
  101. }
  102. return prim;
  103. }
  104. debug (string message ){
  105. list params = llGetPrimitiveParams ([PRIM_MATERIAL ]);
  106. if (llList2Integer (params ,0)==PRIM_MATERIAL_FLESH){
  107. llOwnerSay("memory: "+(string)llGetFreeMemory()+" Script name: "+llGetScriptName ()+": " +message );
  108. }
  109. }
  110. default {
  111. on_rez(integer start_param) {
  112. llResetScript();
  113. }
  114. state_entry() {
  115. COUNT=0;
  116. }
  117. link_message(integer sender_num, integer chan, string str, key id) {
  118. list data=llParseString2List(str, ["|"], []);
  119. if (chan==SLOODLE_TIMER_START){//starts the timer from its current position
  120. llSetTimerEvent(1);
  121. TIME_LIMIT=(integer)llList2Integer(data,0);
  122. END_SOUND=llList2String(data,1);
  123. TIMES_UP_MESSAGE=llList2String(data,2);
  124. }else
  125. if (chan==SLOODLE_TIMER_RESTART){//used to set the counter to 0 and begin counting down again
  126. sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT_LINKED_PRIM, [RED, 1.0,get_prim("timer_prim")], "option", [" "], "", "hex_quizzer");
  127. COUNT=0;
  128. TIME_LIMIT=(integer)llList2Integer(data,0);
  129. END_SOUND=llList2String(data,1);
  130. TIMES_UP_MESSAGE=llList2String(data,2);
  131. llSetTimerEvent(1);
  132. }else
  133. if (chan==SLOODLE_TIMER_STOP){//stop the timer at its current position
  134. sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT_LINKED_PRIM, [RED, 1.0,get_prim("timer_prim")], "timer_stopped", [" "], "", "hex_quizzer");
  135. llSetTimerEvent(0);
  136. }else
  137. if (chan==SLOODLE_TIMER_STOP_AND_RESET){// stop the timer at its current position and reset count to 0
  138. llSetTimerEvent(0);
  139. COUNT=0;
  140. }else
  141. if (chan==SLOODLE_TIMER_RESET){// reset the count back to zero but not restart the timer
  142. COUNT=0;
  143. llSetTimerEvent(0);
  144. }
  145. }
  146. timer() {
  147. COUNT++;
  148. vector color;
  149. if ((TIME_LIMIT - COUNT)<=0){
  150. llSetTimerEvent(0.0);
  151. if (END_SOUND!=""){
  152. llTriggerSound(END_SOUND,1);
  153. END_SOUND="";
  154. }
  155. llMessageLinked(LINK_SET, SLOODLE_TIMER_TIMES_UP, TIMES_UP_MESSAGE, NULL_KEY);
  156. return;
  157. }
  158. string timer_text="(" + (string)(TIME_LIMIT - COUNT) + ")";
  159. if ((TIME_LIMIT - COUNT)>10){
  160. color=GREEN;
  161. llTriggerSound("SND_TICK",0.2);
  162. }
  163. else if ((TIME_LIMIT - COUNT)<=10&&(TIME_LIMIT - COUNT)>5){
  164. color=YELLOW;
  165. llTriggerSound("SND_TICK",0.2);
  166. }
  167. else {
  168. color=RED;
  169. llTriggerSound("SND_BEEPBEEP",0.2);
  170. };
  171. sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT_LINKED_PRIM, [color, 1.0,get_prim("timer_prim")], "option", [timer_text], "", "hex_quizzer");
  172. }
  173. }