ext_config_control.lsl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // :SHOW:1
  2. // :CATEGORY:Light
  3. // :NAME:Rene Free Lighting System
  4. // :AUTHOR:Rene10957 Resident
  5. // :KEYWORDS: light,lamp,lighting light
  6. // :CREATED:2015-06-11 14:38:41
  7. // :EDITED:2016-03-30 20:29:28
  8. // :ID:1079
  9. // :NUM:1770
  10. // :REV:1.0.1
  11. // :WORLD:Opensim
  12. // :DESCRIPTION:
  13. // Extended Configuration Control
  14. // :CODE:
  15. // :LICENSE: CC0 (Public Domain)
  16. // Rene's Free Lighting System - Extended Configuration Control
  17. //
  18. // Author: Rene10957 Resident
  19. // Date: 24-08-2014
  20. //
  21. // Drop this in a separate prim (not root) together with the switch
  22. // Remove after use
  23. // License: CC0 (Public Domain).
  24. // To the extent possible under law, Rene10957 has waived all copyright and related or neighboring rights.
  25. // For more information, see http://creativecommons.org/publicdomain/zero/1.0/.
  26. //////////////////////////////////////////
  27. // Please read user manual before using //
  28. //////////////////////////////////////////
  29. string title = "Extended Configuration Control"; // title
  30. string version = "1.0.1"; // version
  31. // Constants
  32. integer pluginChannel = 10957; // plugin channel
  33. integer switchChannel = -10957; // switch channel
  34. // Variables
  35. list onList;
  36. list offList;
  37. vector color;
  38. vector primColor;
  39. vector particleColor;
  40. string intensity;
  41. string radius;
  42. string falloff;
  43. string alpha;
  44. string glow;
  45. string fullbright;
  46. string particleSize;
  47. string particleTexture;
  48. string red;
  49. string green;
  50. string blue;
  51. string primRed;
  52. string primGreen;
  53. string primBlue;
  54. string partRed;
  55. string partGreen;
  56. string partBlue;
  57. // Functions
  58. string roundDecimals(float number, float decimals)
  59. {
  60. integer intNumber = llRound(number * llPow(10, decimals)); // move decimal point to the right and round
  61. float fltNumber = (float)intNumber / llPow(10, decimals); // move it back to the left
  62. string strNumber = (string)fltNumber; // cast to string
  63. string end = llGetSubString(strNumber, -1, -1);
  64. while (end == "0") { // remove trailing zeroes
  65. strNumber = llDeleteSubString(strNumber, -1, -1);
  66. end = llGetSubString(strNumber, -1, -1);
  67. }
  68. if (end == ".") {
  69. return llGetSubString(strNumber, 0, -2);
  70. }
  71. else {
  72. if (llGetSubString(strNumber, 0, 0) == "0") return llGetSubString(strNumber, 1, -1);
  73. else return strNumber;
  74. }
  75. }
  76. storeData(string msg)
  77. {
  78. list msgList = llCSV2List(msg);
  79. integer on = (integer)llList2String(msgList, 1);
  80. color = (vector)llList2String(msgList, 2);
  81. intensity = roundDecimals((float)llList2String(msgList, 3), 2);
  82. radius = roundDecimals((float)llList2String(msgList, 4), 2);
  83. falloff = roundDecimals((float)llList2String(msgList, 5), 2);
  84. alpha = roundDecimals((float)llList2String(msgList, 6), 2);
  85. glow = roundDecimals((float)llList2String(msgList, 7), 2);
  86. fullbright = llList2String(msgList, 8);
  87. primColor = (vector)llList2String(msgList, 9);
  88. particleColor = (vector)llList2String(msgList, 10);
  89. particleSize = llList2String(msgList, 11);
  90. particleTexture = llList2String(msgList, 13);
  91. red = roundDecimals(color.x, 2);
  92. green = roundDecimals(color.y, 2);
  93. blue = roundDecimals(color.z, 2);
  94. primRed = roundDecimals(primColor.x, 2);
  95. primGreen = roundDecimals(primColor.y, 2);
  96. primBlue = roundDecimals(primColor.z, 2);
  97. partRed = roundDecimals(particleColor.x, 2);
  98. partGreen = roundDecimals(particleColor.y, 2);
  99. partBlue = roundDecimals(particleColor.z, 2);
  100. // Since the description differs from other prims, switch-to-light communication will fail.
  101. // Solution: fake the switch message and pretend this is the default group.
  102. list sendList = ["Default", on, color, intensity, radius, falloff, alpha, glow, fullbright,
  103. primColor, particleColor, particleSize, 999, particleTexture, on];
  104. string sendMsg = llList2CSV(sendList);
  105. llMessageLinked(LINK_ALL_OTHERS, switchChannel, sendMsg, "");
  106. if (on) onList = [red, green, blue, intensity, radius, falloff, alpha, glow, fullbright,
  107. primRed, primGreen, primBlue, partRed, partGreen, partBlue, particleSize, particleTexture];
  108. else offList = [red, green, blue, alpha];
  109. if (llGetListLength(onList) > 0 && llGetListLength(offList) > 0) {
  110. string desc = llDumpList2String(["#LS#"] + onList + offList, ";");
  111. llSetObjectDesc(desc);
  112. }
  113. }
  114. default
  115. {
  116. state_entry()
  117. {
  118. integer i;
  119. integer number = llGetNumberOfPrims();
  120. list descList;
  121. string desc;
  122. for (i = number; i >= 0; --i) {
  123. descList = llGetLinkPrimitiveParams(i, [PRIM_DESC]);
  124. desc = llList2String(descList, 0);
  125. if (llGetSubString(desc, 0, 3) == "#LS#") llSetLinkPrimitiveParamsFast(i, [PRIM_DESC,"(No Description)"]);
  126. }
  127. llMessageLinked(LINK_THIS, pluginChannel, "off", llGetOwner()); // request information from switch
  128. llWhisper(0, title + " " + version + " ready");
  129. llOwnerSay("Please remove the script after use");
  130. }
  131. on_rez(integer start_param)
  132. {
  133. llResetScript();
  134. }
  135. link_message(integer sender_number, integer number, string msg, key id)
  136. {
  137. if (number == switchChannel) storeData(msg);
  138. }
  139. }