magicchest.lslp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * magicchest.lsl
  3. * Part of the Sloodle project (www.sloodle.org)
  4. *
  5. * Copyright (c) 2011-06 contributors (see below)
  6. * Released under the GNU GPL v3
  7. * -------------------------------------------
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * All scripts must maintain this copyrite information, including the contributer information listed
  23. *
  24. * DESCRIPTION
  25. * This script was built for an adventure game which involves access to hidden chambers etc.
  26. * A user must collect X currency in order to unlock and open this door through touch
  27. *
  28. *
  29. * A touch action will check to see if the user has X currency in their inventory, and if so
  30. * instruct the chest to open
  31. *
  32. * Contributors:
  33. * Paul Preibisch
  34. * Edmund Edgar
  35. * SND_CHEST_OPEN: http://www.freesound.org/people/dobroide/ under http://creativecommons.org/licenses/by/3.0/
  36. * SND_KEYS: http://www.freesound.org/people/dobroide/ under http://creativecommons.org/licenses/by/3.0/
  37. * SND_CHEST_CLOSE: http://www.freesound.org/people/dobroide/ under http://creativecommons.org/licenses/by/3.0/
  38. */
  39. string SLOODLE_EOF = "sloodleeof";
  40. integer eof = FALSE; // Have we reached the end of the configuration data?
  41. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;//configuration channel
  42. integer isconfigured = 0;
  43. integer MAX=30;
  44. integer counter=0;
  45. //order of animation messages
  46. key userKey;
  47. vector RED =<1.00000, 0.00000, 0.00000>;
  48. integer SLOODLE_NOT_ENOUGH_CURRENCY= -1001;// AWARDS You do not have enough points to use this object. (There may be a customized message in the next line.)
  49. integer SLOODLE_OBJECT_REGISTER_INTERACTION= -1639271133; //channel objects send interactions to the mod_interaction-1.0 script on to be forwarded to server
  50. debug(string str){
  51. // llSay(0,str);
  52. }
  53. string objecttogive;
  54. integer soundCounter=0;
  55. playDoorKnockSound(){
  56. list snds= ["SND_CHEST_KEYS"];
  57. llTriggerSound(llList2String(snds, soundCounter),1);
  58. soundCounter++;
  59. if (soundCounter>llGetListLength(snds)-1){
  60. soundCounter=0;
  61. snds=llListRandomize(snds, 1);
  62. }
  63. }
  64. integer DOOR_STATE;
  65. integer OPEN=-1;
  66. integer CLOSED=1;
  67. doorClose(){
  68. counter=0;
  69. llSetTimerEvent(0);
  70. llTriggerSound("SND_CHEST_CLOSE", 1);
  71. llMessageLinked(LINK_SET, -99, "p0", NULL_KEY);
  72. llSetText("", RED, 1);
  73. DOOR_STATE=CLOSED;
  74. llSetText("", RED, 1);
  75. }
  76. doorOpen(){
  77. counter=0;
  78. DOOR_STATE=OPEN;
  79. //status is > 0 so it is a success, user has enough currency so we can open the door
  80. llTriggerSound("SND_CHEST_OPEN", 1);
  81. llSay(0,"Chest is opened!");
  82. llMessageLinked(LINK_SET, -99, "p1", NULL_KEY);
  83. llSleep(1);
  84. llSetTimerEvent(1);
  85. }
  86. knock(){
  87. //when touched, tell mod_interaction script that a water action has occured
  88. llMessageLinked(LINK_SET, SLOODLE_OBJECT_REGISTER_INTERACTION, "tryopenchest", llDetectedKey(0));
  89. llSay(0,"Attempting to open the chest");
  90. llTriggerSound("SND_KEYS", 1);
  91. }
  92. list give_in_folder;
  93. integer item_no = 0;
  94. default {
  95. state_entry() {
  96. doorClose();
  97. }
  98. touch_start(integer num_detected) {
  99. integer j;
  100. for (j=0;j<num_detected;j++){
  101. if (DOOR_STATE==CLOSED){
  102. knock();
  103. }else{
  104. llTriggerSound("chimes", 1);
  105. item_no = 0;
  106. give_in_folder =[];
  107. for ( item_no= 0 ; item_no < llGetInventoryNumber( INVENTORY_ALL ) ;item_no++ ){
  108. string name = llGetInventoryName( INVENTORY_ALL, item_no );
  109. if ( name != llGetScriptName() ){
  110. give_in_folder += [ name ];
  111. }
  112. }
  113. llGiveInventoryList ( llDetectedKey(0), llGetObjectName(), give_in_folder );
  114. }
  115. }
  116. }
  117. link_message(integer sender_num, integer num, string str, key id) {
  118. // Split the data up into lines
  119. str = llStringTrim(str, STRING_TRIM);
  120. list lines = llParseStringKeepNulls(str, ["\n"], []);
  121. integer numlines = llGetListLength(lines);
  122. // Extract all the status fields
  123. list statusfields = llParseStringKeepNulls( llList2String(lines,0), ["|"], [] );
  124. // Get the statuscode
  125. integer statuscode = llList2Integer(statusfields,0);
  126. key user = llList2Key(statusfields,6);
  127. // Was it an error code?
  128. llSay(0,"*** status code is:"+(string)statuscode);
  129. if (statuscode==1){
  130. string task = llList2String(lines, 1);
  131. if (task=="tryopenchest"){
  132. doorOpen();
  133. }
  134. }else
  135. if (statuscode <= 0) {
  136. //error will come if u dont have enough water.
  137. if (statuscode==SLOODLE_NOT_ENOUGH_CURRENCY){
  138. playDoorKnockSound();
  139. }
  140. }
  141. }
  142. timer() {
  143. counter++;
  144. if (counter>MAX){
  145. doorClose();
  146. }
  147. if ((MAX-counter)>0){
  148. llSetText("Closing chest in: "+(string)(MAX-counter)+" seconds!", RED, 1);
  149. }
  150. }
  151. }
  152. // Please leave the following line intact to show where the script lives in Git:
  153. // SLOODLE LSL Script Git Location: mod/interaction-1.0/objects/magicchest/assets/magicchest.lslp