Bugs_Larnia

LSL: Multilink Texture and Color Changer Example

Jan 13th, 2021 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Multilink Texture and Color Changer Example
  2. Created: 2016-11-11, by Bugs Larnia
  3. Please keep annotations
  4. */
  5.  
  6. //USER SETUP START
  7. integer giOwnerOnly = FALSE; //Set to TRUE for owner only; FALSE for everyone
  8. list glColorChangeLinks = ["1", "2", "3"]; //Link numbers eligible for color changes; encase entries in " "
  9. list glTextureChangeLinks = ["2", "4"]; //Link numbers eligible for texture changes; encase entries in " "
  10.  
  11. //List of color vectors <red, green, blue>
  12. list glColors = [
  13.     <1.0, 1.0, 1.0>,
  14.     <1.0, 0.0, 0.0>,
  15.     <0.0, 1.0, 0.0>,
  16.     <0.0, 0.0, 1.0>
  17.     ];
  18.  
  19. //This is the list of color names - order has to match the glColors list
  20. list glColorNames = [  
  21.     "White",
  22.     "Red",
  23.     "Green",
  24.     "Blue"
  25.     ];
  26.  
  27. //List of texture keys
  28. list glTextures = [
  29.     "ec3d5e4a-21c4-e8b5-02ea-b4f03aa54bd9",
  30.     "586e7250-0d32-d7a6-f833-f0988f4da20a",
  31.     "d568a8ad-2637-33ac-90a6-f41e8b509a6e"
  32.     ];
  33.  
  34. //List of texture names - order has to match the glTextures list    
  35. list glTextureNames = [
  36.     "Fox",
  37.     "Raccooon",
  38.     "Goldbug"
  39.     ];
  40. //USER SETUP END
  41. //==========================================================================
  42.  
  43. list glLinks = ["[Cancel]", "All"];
  44. integer giEars;
  45. integer giLinkToChange;
  46. string gsChangeType;
  47.  
  48. ShowMenu(key pkId, string psMsg, list plButtons)
  49. {
  50.     integer iChannel = (integer)llFrand(-99999.0) - 100000;
  51.     giEars = llListen(iChannel, "", pkId, "");
  52.     llDialog(pkId, psMsg, plButtons, iChannel);
  53.     llSetTimerEvent(45.0);
  54. }
  55.  
  56. StopListening()
  57. {
  58.     llSetTimerEvent(0.0);
  59.     llListenRemove(giEars);
  60. }
  61.  
  62. default
  63. {
  64.     state_entry() { }
  65.  
  66.     touch_start(integer total_number)
  67.     {
  68.         key kId = llDetectedKey(0);
  69.         if (giOwnerOnly && (kId != llGetOwner()))
  70.         {
  71.             return;
  72.         }
  73.        
  74.         ShowMenu(kId, "Please select what to change:", ["[Cancel]", "Textures", "Colors"]);
  75.     }
  76.    
  77.     listen(integer piChannel, string psName, key pkId, string psMsg)
  78.     {
  79.         StopListening();
  80.         if (psMsg == "[Cancel]")
  81.         {
  82.             return;
  83.         }
  84.        
  85.         if (psMsg == "Textures")
  86.         {
  87.             gsChangeType = psMsg;
  88.             ShowMenu(pkId, "Please select the link to change:", glTextureChangeLinks);
  89.         }
  90.         else if (psMsg == "Colors")
  91.         {
  92.             gsChangeType = psMsg;
  93.             ShowMenu(pkId, "Please select the link to change:", glColorChangeLinks);
  94.         }
  95.        
  96.         //Change color and texture
  97.         else if ((gsChangeType == "Colors") && (~llListFindList(glColorNames, [psMsg])))
  98.         {
  99.             integer i = llListFindList(glColorNames, [psMsg]);
  100.             llSetLinkColor(giLinkToChange, llList2Vector(glColors, i), ALL_SIDES);
  101.         }
  102.         else if ((gsChangeType == "Textures") && (~llListFindList(glTextureNames, [psMsg])))
  103.         {
  104.             integer i = llListFindList(glTextureNames, [psMsg]);
  105.             llSetLinkTexture(giLinkToChange, llList2String(glTextures, i), ALL_SIDES);
  106.         }
  107.        
  108.         //Get link number
  109.         else if (psMsg != "OK")
  110.         {
  111.             giLinkToChange = (integer)psMsg;
  112.             if (gsChangeType == "Colors")
  113.             {
  114.                 ShowMenu(pkId, "Please select the color:", glColorNames);
  115.             }
  116.             else if (gsChangeType == "Textures")
  117.             {
  118.                 ShowMenu(pkId, "Please select the texture:", glTextureNames);
  119.             }
  120.         }
  121.     }
  122.    
  123.     //Housekeeping
  124.     on_rez(integer piParam)
  125.     {
  126.         llResetScript();
  127.     }
  128. }
  129.  
Add Comment
Please, Sign In to add comment