config_control.lsl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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:37:37
  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. // Configuration Control: Menu-controlled lighting system with many features
  14. // :CODE:
  15. // :LICENSE: CC0 (Public Domain)
  16. // Rene's Free Lighting System - Configuration Control
  17. //
  18. // Author: Rene10957 Resident
  19. // Date: 24-08-2014
  20. //
  21. // Drop this in every light bulb, instead of the light script
  22. // Make sure the switch is in a separate prim (not root)
  23. // Remove after use
  24. // License: CC0 (Public Domain).
  25. // To the extent possible under law, Rene10957 has waived all copyright and related or neighboring rights.
  26. // For more information, see http://creativecommons.org/publicdomain/zero/1.0/.
  27. //////////////////////////////////////////
  28. // Please read user manual before using //
  29. //////////////////////////////////////////
  30. string title = "Configuration Control"; // title
  31. string version = "1.0.1."; // version
  32. // Constants
  33. integer pluginChannel = 10957; // plugin channel
  34. integer switchChannel = -10957; // switch channel
  35. // Variables
  36. list onList;
  37. list offList;
  38. vector color;
  39. vector primColor;
  40. string intensity;
  41. string radius;
  42. string falloff;
  43. string alpha;
  44. string glow;
  45. string fullbright;
  46. string red;
  47. string green;
  48. string blue;
  49. string primRed;
  50. string primGreen;
  51. string primBlue;
  52. // Functions
  53. string roundDecimals(float number, float decimals)
  54. {
  55. integer intNumber = llRound(number * llPow(10, decimals)); // move decimal point to the right and round
  56. float fltNumber = (float)intNumber / llPow(10, decimals); // move it back to the left
  57. string strNumber = (string)fltNumber; // cast to string
  58. string end = llGetSubString(strNumber, -1, -1);
  59. while (end == "0") { // remove trailing zeroes
  60. strNumber = llDeleteSubString(strNumber, -1, -1);
  61. end = llGetSubString(strNumber, -1, -1);
  62. }
  63. if (end == ".") {
  64. return llGetSubString(strNumber, 0, -2);
  65. }
  66. else {
  67. if (llGetSubString(strNumber, 0, 0) == "0") return llGetSubString(strNumber, 1, -1);
  68. else return strNumber;
  69. }
  70. }
  71. storeData(string msg)
  72. {
  73. list msgList = llCSV2List(msg);
  74. integer on = (integer)llList2String(msgList, 1);
  75. color = (vector)llList2String(msgList, 2);
  76. intensity = roundDecimals((float)llList2String(msgList, 3), 2);
  77. radius = roundDecimals((float)llList2String(msgList, 4), 2);
  78. falloff = roundDecimals((float)llList2String(msgList, 5), 2);
  79. alpha = roundDecimals((float)llList2String(msgList, 6), 2);
  80. glow = roundDecimals((float)llList2String(msgList, 7), 2);
  81. fullbright = llList2String(msgList, 8);
  82. primColor = (vector)llList2String(msgList, 9);
  83. red = roundDecimals(color.x, 2);
  84. green = roundDecimals(color.y, 2);
  85. blue = roundDecimals(color.z, 2);
  86. primRed = roundDecimals(primColor.x, 2);
  87. primGreen = roundDecimals(primColor.y, 2);
  88. primBlue = roundDecimals(primColor.z, 2);
  89. llSetPrimitiveParams([
  90. PRIM_POINT_LIGHT, on, color, (float)intensity, (float)radius, (float)falloff,
  91. PRIM_COLOR, ALL_SIDES, primColor, (float)alpha,
  92. PRIM_GLOW, ALL_SIDES, (float)glow,
  93. PRIM_FULLBRIGHT, ALL_SIDES, (integer)fullbright]);
  94. if (on) onList = [red, green, blue, intensity, radius, falloff, alpha, glow, fullbright,
  95. primRed, primGreen, primBlue];
  96. else offList = [red, green, blue, alpha];
  97. if (llGetListLength(onList) > 0 && llGetListLength(offList) > 0) {
  98. string desc = llDumpList2String(["#LS#"] + onList + offList, ";");
  99. llSetObjectDesc(desc);
  100. }
  101. }
  102. default
  103. {
  104. state_entry()
  105. {
  106. if (llGetSubString(llGetObjectDesc(), 0, 3) == "#LS#") llSetObjectDesc("(No Description)");
  107. llMessageLinked(LINK_ALL_OTHERS, pluginChannel, "off", llGetOwner()); // request information from switch
  108. llWhisper(0, title + " " + version + " ready");
  109. llOwnerSay("Please remove the script after use");
  110. }
  111. on_rez(integer start_param)
  112. {
  113. llResetScript();
  114. }
  115. link_message(integer sender_number, integer number, string msg, key id)
  116. {
  117. if (number == switchChannel) storeData(msg);
  118. }
  119. }