magicplant.lslp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * magicplant.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. * Contributors:
  9. * Edmund Edgar
  10. * Paul Preibisch
  11. *
  12. * This script will accept touches. When tocuhed it will tell the mod_touchable-1.0.lsl script to send a touch event to the server
  13. * That touch action will check to see if the user has X water in their inventory, and if so, subtract water
  14. * Once watered 5 times, this script will rezz a flower object, and shout out the person the flower object should float towards
  15. * Once the flower object reaches its target it will tell this plant object to give the user a flower in their inventory
  16. */
  17. integer counter=0;
  18. list plantPhase=["p2","p1","p0","p10","p11","p12","p13"];
  19. integer SLOODLE_NOT_ENOUGH_CURRENCY = -1001;
  20. integer SLOODLE_OBJECT_INTERACTION_FLOWER= -1639271134; //channel interaction object will shout commands to its consituent parts
  21. integer SLOODLE_OBJECT_REGISTER_INTERACTION= -1639271133; //channel objects send interactions to the mod_interaction-1.0 script on to be forwarded to server
  22. vector mySize;
  23. grow(){
  24. integer len =llGetListLength(plantPhase);
  25. integer phase = counter++;
  26. if (counter>len-1){
  27. counter=0;
  28. }
  29. llMessageLinked(LINK_SET, -99, llList2String(plantPhase,counter), NULL_KEY);
  30. }
  31. shrink(){
  32. integer len =llGetListLength(plantPhase);
  33. integer phase = counter--;
  34. if (counter<0){
  35. counter=0;
  36. }
  37. llMessageLinked(LINK_SET, -99, llList2String(plantPhase,counter), NULL_KEY);
  38. }
  39. giveFlower(){
  40. llSay(0,"A flower has bloomed!");
  41. vector pos = llGetPos();
  42. llRezObject("flower",<pos.x,pos.y,pos.z+2> , <0,0,2>, ZERO_ROTATION, 1);
  43. }
  44. key userKey;
  45. integer SLOODLE_OBJECT_FLOWER_POWER= -1639271136; //linked message channel to tell a flower to give points
  46. default {
  47. state_entry() {
  48. llMessageLinked(LINK_SET, -99, "p2", NULL_KEY);
  49. llListen(SLOODLE_OBJECT_FLOWER_POWER, "", "", "");
  50. llSetTimerEvent(120);
  51. }
  52. touch_start(integer num_detected) {
  53. //when touched, tell mod_interaction script that a water action has occured
  54. llMessageLinked(LINK_SET, SLOODLE_OBJECT_REGISTER_INTERACTION, "water", llDetectedKey(0));
  55. llSay(0,"Attempting to water plant");
  56. }
  57. listen(integer channel, string name, key id, string message) {
  58. //this plant will listen for messages from the flowers it rezzed
  59. //llRegionSay(SLOODLE_OBJECT_FLOWER_POWER, "GOT FLOWER|"+(string)uuidPlant+"|"+(string)llDetectedKey(0));
  60. list data = llParseString2List(message, ["|"], []);
  61. string command = llList2String(data,0);
  62. key plantUuid= llList2Key(data,1);
  63. userKey= llList2Key(data,2);
  64. if (command == "GOT FLOWER"){
  65. if (plantUuid!=llGetKey()){
  66. return;
  67. }
  68. llMessageLinked(LINK_SET, SLOODLE_OBJECT_REGISTER_INTERACTION, "flower", userKey);
  69. }
  70. //if the message that came in is intended for this
  71. }
  72. link_message(integer sender_num, integer num, string str, key id) {
  73. // Split the data up into lines
  74. list lines = llParseStringKeepNulls(str, ["\n"], []);
  75. integer numlines = llGetListLength(lines);
  76. // Extract all the status fields
  77. list statusfields = llParseStringKeepNulls( llList2String(lines,0), ["|"], [] );
  78. // Get the statuscode
  79. integer statuscode = llList2Integer(statusfields,0);
  80. key user = llList2Key(statusfields,6);
  81. // Was it an error code?
  82. if (statuscode <= 0) {
  83. //error will come if u dont have enough water.
  84. if (statuscode==SLOODLE_NOT_ENOUGH_CURRENCY){
  85. llTriggerSound("NEEDWATER", 1);
  86. }
  87. string msg;
  88. if (numlines > 1) {
  89. msg = llList2String(lines, 1);
  90. }
  91. return;
  92. }else{
  93. string task = llList2String(lines, 1);
  94. if (task=="complete"){
  95. grow();
  96. userKey= user;
  97. giveFlower();
  98. }else
  99. if (task=="water"){
  100. llTriggerSound("water drip", 1);
  101. llTriggerSound("water drip", 1);
  102. llTriggerSound("water drip", 1);
  103. grow();
  104. //check to see if we've watered it x times
  105. llMessageLinked(LINK_SET, SLOODLE_OBJECT_REGISTER_INTERACTION, "complete", user);
  106. }
  107. else
  108. if (task=="flower"){
  109. grow();
  110. llSay(0,"Added a flower to "+llKey2Name(user)+"'s backpack!");
  111. }
  112. }
  113. }
  114. object_rez(key id) {
  115. //flowerUuid|uuidPlant|userKey
  116. llSleep(2);
  117. llRegionSay(SLOODLE_OBJECT_INTERACTION_FLOWER, (string)id+"|"+(string)llGetKey()+"|"+(string)userKey);
  118. }
  119. timer() {
  120. shrink();
  121. }
  122. }
  123. // Please leave the following line intact to show where the script lives in Git:
  124. // SLOODLE LSL Script Git Location: mod/interaction-1.0/objects/magicplant/assets/magicplant.lslp