orb.lslp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* button_display.lslp
  2. *
  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. * As mentioned, this script has been licensed under GPL 3.0
  25. * Basically, that means, you are free to use the script, commercially etc, but if you include
  26. * it in your objects, you must make the source viewable to the person you are distributuing it to -
  27. * ie: it can not be closed source - GPL 3.0 means - you must make it open!
  28. * This is so that others can modify it and contribute back to the community.
  29. * The SLOODLE github can be found here: https://github.com/sloodle
  30. *
  31. * Enjoy!
  32. *
  33. * Contributors:
  34. * Paul Preibisch
  35. *
  36. * DESCRIPTION
  37. * The main purpose of this script is to power a button prim that sits on the edge of a hexagon quizzer's pie slice. A user can request that a
  38. * new hexagon be joined to this edge by clicking on the horizontal rod, or vertical rod
  39. * When the horizontal rod or vertical rod is touched, this script will send a linked message to the hexagon rezzer script telling
  40. * it who touched
  41. * it. It will also set the prims properties so that the orb reshapes itself small enough to be hidden (close) when needed.
  42. *
  43. */
  44. integer SLOODLE_CHANNEL_ANIM= -1639277007;
  45. integer DELAY;
  46. integer my_num;
  47. key root_key;
  48. string my_state;
  49. float edge_length;
  50. float tip_to_edge;
  51. float sensor_range;
  52. integer SLOODLE_OBSTRUCTION=1639277021;
  53. integer OBSTRUCTED=FALSE;
  54. integer SLOODLE_CHANNEL_USER_TOUCH = -1639277002;//user touched object
  55. string SLOODLE_TRANSLATE_HOVER_TEXT_LINKED_PRIM= "hovertext_linked_prim"; // 3 output parameters: colour <r,g,b>, alpha value, link number
  56. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  57. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  58. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  59. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  60. 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.
  61. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  62. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  63. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  64. debug (string message ){
  65. list params = llGetPrimitiveParams ([PRIM_MATERIAL ]);
  66. if (llList2Integer (params ,0)==PRIM_MATERIAL_FLESH){
  67. llOwnerSay("memory: "+(string)llGetFreeMemory()+" Script name: "+llGetScriptName ()+": " +message );
  68. }
  69. }
  70. // Send a translation request link message
  71. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch){
  72. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  73. }
  74. hide(integer orb){
  75. my_state="hide";
  76. if (myType=="orb"){
  77. llSetPrimitiveParams([9,3,0,<0.730000, 0.750000, 0.0>,0.0,<0.0, 0.0, 0.0>,<0.0, 1.0, 0.0>]);
  78. }else
  79. if (myType=="rod_hor"){
  80. llSetPrimitiveParams([9,4,0,<0.505000, 0.525000, 0.0>,0.0,<0.0, 0.0, 0.0>,<1.0, 0.500000, 0.0>,<0.0, 0.0, 0.0>,<0.0, 1.0, 0.0>,<0.0, 0.0, 0.0>,1.0,0.0,0.0]);
  81. }else
  82. if (myType=="rod_ver"){
  83. llSetPrimitiveParams([9,4,0,<0.505000, 0.525000, 0.0>,0.0,<0.0, 0.0, 0.0>,<1.0, 0.500000, 0.0>,<0.0, 0.0, 0.0>,<0.0, 1.0, 0.0>,<0.0, 0.0, 0.0>,1.0,0.0,0.0]);
  84. }
  85. llSetText("", <0,0,0>, 1);
  86. }
  87. show(integer orb){
  88. my_state="show";
  89. if (myType=="orb"){
  90. llSetPrimitiveParams([9,3,0,<0.0, 1.0, 0.0>,0.0,<0.0, 0.0, 0.0>,<0.0, 1.0, 0.0>]);
  91. }else
  92. if (myType=="rod_hor"){
  93. llSetPrimitiveParams([9,4,0,<0.505000, 0.525000, 0.0>,0.0,<0.0, 0.0, 0.0>,<1.0, 0.500000, 0.0>,<0.0, 0.0, 0.0>,<0.0, 1.0, 0.0>,<0.0, 0.0, 0.0>,1.0,0.0,0.0]);
  94. }else
  95. if (myType=="rod_ver"){
  96. llSetPrimitiveParams([9,4,0,<0.0, 1.0, 0.0>,0.0,<0.0, 0.0, 0.0>,<1.0, 0.500000, 0.0>,<0.0, 0.0, 0.0>,<0.0, 1.0, 0.0>,<0.0, 0.0, 0.0>,1.0,0.0,0.0]);
  97. }
  98. }
  99. /*
  100. Search through all linked prims, and returns the prims link number which matches the name
  101. */
  102. integer get_prim(string name){
  103. integer num_links=llGetNumberOfPrims();
  104. integer i;
  105. integer prim=-1;
  106. for (i=0;i<=num_links;i++){
  107. if (llGetLinkName(i)==name){
  108. prim=i;
  109. }else{
  110. }
  111. }
  112. return prim;
  113. }
  114. list myFamily;
  115. string myType;
  116. init(){
  117. //determine the edge length
  118. integer pie_slice6 = get_prim("pie_slice6");
  119. list pie_slice_data = llGetLinkPrimitiveParams(pie_slice6, [PRIM_SIZE] );
  120. vector pie_slice_size=llList2Vector(pie_slice_data, 0);
  121. tip_to_edge = pie_slice_size.z+2;//since we are looking for the length starting from the tip of the pie_slice to the middle of the edge, we need to choose the z dimension for this particular pie slice
  122. edge_length= pie_slice_size.y;//since we are looking for the length of an edge we need to choose the y dimension for this particular pie slice
  123. sensor_range=tip_to_edge;
  124. myType = llGetSubString(llGetObjectName(), 0, -2);
  125. string name = llGetObjectName();
  126. integer len = llGetNumberOfPrims();
  127. integer k=0;
  128. for (k=0;k<len;k++){
  129. myFamily+=llGetLinkKey(k);
  130. }
  131. my_num = (integer)llGetSubString(name, -1, -1);
  132. }
  133. default{
  134. on_rez(integer r){llResetScript();}
  135. state_entry() {
  136. init();
  137. llListen(SLOODLE_OBSTRUCTION, "", "", "CHECK OBSTRUCTED");
  138. hide(my_num);
  139. }
  140. touch_start(integer num_detected) {
  141. integer j;
  142. for (j=0;j<num_detected;j++){
  143. if (my_state=="show"){
  144. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_USER_TOUCH, myType+"|"+(string)my_num, llDetectedKey(j));
  145. //debug("sending touch event");
  146. }else{
  147. sloodle_translation_request (SLOODLE_TRANSLATE_DIALOG, [1 , "Ok"], "not_allowed_to_click" , ["Ok"], llDetectedKey(j) , "hex_quizzer");
  148. }
  149. }
  150. }
  151. listen(integer channel, string name, key id, string message) {
  152. list prim_data = llGetLinkPrimitiveParams( LINK_ROOT, [PRIM_NAME]);
  153. string root_name=llList2String(prim_data,0);
  154. root_key = llGetLinkKey( LINK_ROOT );
  155. if (llGetSubString(name, 0, -2)!=myType){
  156. debug("heard that "+name+" was rezzed but it is not a "+myType+", returning");
  157. return;
  158. }
  159. debug("heard a whisper that "+name+" is near me, going to fire off a sensor event to detect if it is one of my family");
  160. llSensor(root_name, "", SCRIPTED, sensor_range, TWO_PI);
  161. }
  162. link_message(integer s, integer n, string m, key id){
  163. integer stat=llGetStatus(1);
  164. if (n!=SLOODLE_CHANNEL_ANIM) return;
  165. debug("------------------------------------"+m);
  166. list data = llParseString2List(m, ["|"], []);
  167. string command = llList2String(data, 0);
  168. // debug("command:"+command);
  169. if (command!="show user buttons"&&command!="hide user buttons") return;
  170. list objects_to_show = llParseString2List(llList2String(data, 1), [","], []);
  171. integer ismynum = llListFindList(objects_to_show, [(string)my_num]);
  172. if (ismynum==-1) {
  173. return;
  174. }
  175. if (command=="show user buttons"){
  176. debug("-----------received show user buttons ");
  177. llWhisper(SLOODLE_OBSTRUCTION, "CHECK OBSTRUCTED");
  178. //do a sensor to first see if another hex is within the vincinity, in which case, dont rez orb otherwise it will overlap
  179. //search for a scripted object the same name as me
  180. list prim_data = llGetLinkPrimitiveParams( LINK_ROOT, [PRIM_NAME]);
  181. string root_name=llList2String(prim_data,0);
  182. root_key = llGetLinkKey( LINK_ROOT );
  183. llSensor(root_name, "", SCRIPTED, sensor_range, TWO_PI);
  184. }
  185. if (command=="hide user buttons"){
  186. hide(my_num);
  187. }
  188. }
  189. sensor(integer num_detected) {
  190. integer k;
  191. for (k=0;k<num_detected;k++){
  192. //if detected keys are orbs in the same linkset, ignore
  193. if (llListFindList(myFamily,[llDetectedKey(k)])!=-1){
  194. hide(my_num);
  195. OBSTRUCTED=TRUE;
  196. debug("im a sensor, and heard that "+llDetectedName(k)+" has been rezzed around me, and it is of my family, I am going to show");
  197. }else{
  198. //only detected my root
  199. debug("im a sensor, and heard that "+llDetectedName(k)+" has been rezzed around me, and it is NOT a family member so hiding so dont overlap!");
  200. show(my_num);
  201. }
  202. }
  203. }
  204. no_sensor() {
  205. // debug("no hex found!");
  206. show(my_num);
  207. }
  208. }