button_display.lslp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. debug("*******************************************************hiding");
  77. if (myType=="orb"){
  78. llSetPrimitiveParams([9,3,0,<0.730000, 0.750000, 0.0>,0.0,<0.0, 0.0, 0.0>,<0.0, 1.0, 0.0>]);
  79. }else
  80. if (myType=="rod_hor"){
  81. 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]);
  82. }else
  83. if (myType=="rod_ver"){
  84. 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]);
  85. }
  86. llSetText("", <0,0,0>, 1);
  87. }
  88. show(integer orb){
  89. my_state="show";
  90. debug("*******************************************************showing");
  91. if (myType=="orb"){
  92. llSetPrimitiveParams([9,3,0,<0.0, 1.0, 0.0>,0.0,<0.0, 0.0, 0.0>,<0.0, 1.0, 0.0>]);
  93. }else
  94. if (myType=="rod_hor"){
  95. 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]);
  96. }else
  97. if (myType=="rod_ver"){
  98. 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]);
  99. }
  100. }
  101. /*
  102. Search through all linked prims, and returns the prims link number which matches the name
  103. */
  104. integer get_prim(string name){
  105. integer num_links=llGetNumberOfPrims();
  106. integer i;
  107. integer prim=-1;
  108. for (i=0;i<=num_links;i++){
  109. if (llGetLinkName(i)==name){
  110. prim=i;
  111. }else{
  112. }
  113. }
  114. return prim;
  115. }
  116. list myFamily;
  117. string myType;
  118. init(){
  119. //determine the edge length
  120. integer pie_slice6 = get_prim("pie_slice6");
  121. list pie_slice_data = llGetLinkPrimitiveParams(pie_slice6, [PRIM_SIZE] );
  122. vector pie_slice_size=llList2Vector(pie_slice_data, 0);
  123. 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
  124. 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
  125. sensor_range=tip_to_edge;
  126. myType = llGetSubString(llGetObjectName(), 0, -2);
  127. string name = llGetObjectName();
  128. integer len = llGetNumberOfPrims();
  129. integer k=0;
  130. for (k=0;k<len;k++){
  131. myFamily+=llGetLinkKey(k);
  132. }
  133. my_num = (integer)llGetSubString(name, -1, -1);
  134. }
  135. default{
  136. on_rez(integer r){llResetScript();}
  137. state_entry() {
  138. init();
  139. llListen(SLOODLE_OBSTRUCTION, "", "", "CHECK OBSTRUCTED");
  140. hide(my_num);
  141. }
  142. touch_start(integer num_detected) {
  143. integer j;
  144. for (j=0;j<num_detected;j++){
  145. vector touch_pos= llDetectedTouchPos(j);
  146. vector my_pos = llGetPos();
  147. if (my_state=="show"){
  148. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_USER_TOUCH, myType+"|"+(string)my_num+"|"+(string)touch_pos+"|"+(string)my_pos, llDetectedKey(j));
  149. //debug("sending touch event");
  150. }else{
  151. sloodle_translation_request (SLOODLE_TRANSLATE_DIALOG, [1 , "Ok"], "not_allowed_to_click" , ["Ok"], llDetectedKey(j) , "hex_quizzer");
  152. }
  153. }
  154. }
  155. listen(integer channel, string name, key id, string message) {
  156. list prim_data = llGetLinkPrimitiveParams( LINK_ROOT, [PRIM_NAME]);
  157. string root_name=llList2String(prim_data,0);
  158. root_key = llGetLinkKey( LINK_ROOT );
  159. if (llGetSubString(name, 0, -2)!=myType){
  160. debug("heard that "+name+" was rezzed but it is not a "+myType+", returning");
  161. return;
  162. }
  163. 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");
  164. llSensor(root_name, "", SCRIPTED, sensor_range, TWO_PI);
  165. }
  166. link_message(integer s, integer n, string m, key id){
  167. integer stat=llGetStatus(1);
  168. if (n!=SLOODLE_CHANNEL_ANIM) return;
  169. debug("------------------------------------"+m);
  170. list data = llParseString2List(m, ["|"], []);
  171. string command = llList2String(data, 0);
  172. // debug("command:"+command);
  173. if (command!="show user buttons"&&command!="hide user buttons") return;
  174. list objects_to_show = llParseString2List(llList2String(data, 1), [","], []);
  175. integer ismynum = llListFindList(objects_to_show, [(string)my_num]);
  176. if (ismynum==-1) {
  177. return;
  178. }
  179. if (command=="show user buttons"){
  180. debug("-----------received show user buttons ");
  181. llWhisper(SLOODLE_OBSTRUCTION, "CHECK OBSTRUCTED");
  182. //do a sensor to first see if another hex is within the vincinity, in which case, dont rez orb otherwise it will overlap
  183. //search for a scripted object the same name as me
  184. list prim_data = llGetLinkPrimitiveParams( LINK_ROOT, [PRIM_NAME]);
  185. string root_name=llList2String(prim_data,0);
  186. root_key = llGetLinkKey( LINK_ROOT );
  187. llSensor(root_name, "", SCRIPTED, sensor_range, TWO_PI);
  188. }
  189. if (command=="hide user buttons"){
  190. hide(my_num);
  191. }
  192. }
  193. sensor(integer num_detected) {
  194. integer k;
  195. for (k=0;k<num_detected;k++){
  196. //if detected keys are orbs in the same linkset, ignore
  197. if (llListFindList(myFamily,[llDetectedKey(k)])!=-1){
  198. //its in the list so my family
  199. show(my_num);
  200. OBSTRUCTED=TRUE;
  201. 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");
  202. }else{
  203. //only detected my root
  204. 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!");
  205. hide(my_num);
  206. }
  207. }
  208. }
  209. no_sensor() {
  210. // debug("no hex found!");
  211. show(my_num);
  212. }
  213. }