Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. //
  2. // We'll use face #1 (south facing) for our picture. That will mean changes in Y for swapping.
  3. // 0.001 seems to be plenty to keep faces from glitching.
  4. //
  5. float gfTimerLength = 15.0;
  6. integer giPreviousChoice = -1;
  7. integer giShowingPrim = 1; // This is either 1 or 2, for the two prims. 1 is root.
  8. //
  9.  
  10. Initialize()
  11. {
  12. giShowingPrim = 1;
  13. // Make sure the child is behind and the same size.
  14. vector vRootSize = llList2Vector(llGetLinkPrimitiveParams(1, [PRIM_SIZE]), 0);
  15. llSetLinkPrimitiveParamsFast(2, [PRIM_POS_LOCAL, <0, 0.001, 0>, PRIM_SIZE, vRootSize]);
  16. llSetTimerEvent(gfTimerLength); // Can't hurt.
  17. //
  18. // All sides except 1 to transparent.
  19. llSetLinkTexture(1, TEXTURE_TRANSPARENT, 0); llSetLinkTexture(1, TEXTURE_TRANSPARENT, 2); llSetLinkTexture(1, TEXTURE_TRANSPARENT, 3); llSetLinkTexture(1, TEXTURE_TRANSPARENT, 4); llSetLinkTexture(1, TEXTURE_TRANSPARENT, 5);
  20. llSetLinkTexture(2, TEXTURE_TRANSPARENT, 0); llSetLinkTexture(2, TEXTURE_TRANSPARENT, 2); llSetLinkTexture(2, TEXTURE_TRANSPARENT, 3); llSetLinkTexture(2, TEXTURE_TRANSPARENT, 4); llSetLinkTexture(2, TEXTURE_TRANSPARENT, 5);
  21. //
  22. // Set side 1 color to white.
  23. llSetLinkColor(1, <1,1,1>, 1);
  24. llSetLinkColor(2, <1,1,1>, 1);
  25. }
  26.  
  27.  
  28. string GetRandomTexture()
  29. {
  30. integer iCount;
  31. integer iChoice;
  32. //
  33. iCount = llGetInventoryNumber(INVENTORY_TEXTURE);
  34. if (iCount == 0) return "";
  35. if (iCount == 1) return llGetInventoryName(INVENTORY_TEXTURE, 0);
  36. // We've got more than one, so make sure we don't return the same one twice.
  37. do iChoice = llFloor(llFrand(iCount));
  38. while (iChoice == giPreviousChoice);
  39. giPreviousChoice = iChoice;
  40. return llGetInventoryName(INVENTORY_TEXTURE, iChoice);
  41. }
  42.  
  43. FadePictures(integer iLinkHide, integer iLinkShow)
  44. {
  45. float fAlphaHide = llList2Float(llGetLinkPrimitiveParams(iLinkHide, [PRIM_COLOR, 1]), 1);
  46. float fAlphaShow = llList2Float(llGetLinkPrimitiveParams(iLinkShow, [PRIM_COLOR, 1]), 1);
  47. do
  48. {
  49. fAlphaHide -= 0.05;
  50. if (fAlphaHide < 0.0) fAlphaHide = 0.0;
  51. llSetLinkAlpha(iLinkHide, fAlphaHide, 1);
  52. //
  53. fAlphaShow += 0.05;
  54. if (fAlphaShow > 1.0) fAlphaShow = 1.0;
  55. llSetLinkAlpha(iLinkShow, fAlphaShow, 1);
  56. //
  57. llSleep(0.02);
  58. }
  59. while (fAlphaHide != 0.0 || fAlphaShow != 1.0);
  60. }
  61.  
  62. ShowPicture(string sPicture)
  63. {
  64. if (sPicture == "") return;
  65. //
  66. if (giShowingPrim == 1)
  67. {
  68. giShowingPrim = 2;
  69. llSetLinkAlpha(2, 0, 1); // Link, Alpha, Face. So it doesn't show when the front one goes transparent.
  70. FadePictures(1, 2);
  71. llSetLinkPrimitiveParamsFast(2, [PRIM_POS_LOCAL, <0, -0.001, 0>]); // Show prim 2 (moves prim 2 in front).
  72. llSetLinkTexture(1, sPicture, 1);
  73. llSetLinkAlpha(1, 1, 1); // Link, Alpha, Face. Make opaque to make sure it loads.
  74. }
  75. else
  76. {
  77. giShowingPrim = 1;
  78. llSetLinkAlpha(1, 0, 1); // Link, Alpha, Face. So it doesn't show when the front one goes transparent.
  79. FadePictures(2, 1);
  80. llSetLinkPrimitiveParamsFast(2, [PRIM_POS_LOCAL, <0, 0.001, 0>]); // Show prim 1 (moves prim 2 behind).
  81. llSetLinkTexture(2, sPicture, 1);
  82. llSetLinkAlpha(2, 1, 1); // Link, Alpha, Face. Make opaque to make sure it loads.
  83. }
  84. }
  85.  
  86. default
  87. {
  88. on_rez(integer iStartParam)
  89. {
  90. Initialize();
  91. }
  92. state_entry()
  93. {
  94. Initialize();
  95. }
  96. changed(integer iChangeBitFlags)
  97. {
  98. if (iChangeBitFlags & CHANGED_INVENTORY)
  99. {
  100. llSetTimerEvent(0);
  101. ShowPicture(GetRandomTexture());
  102. ShowPicture(GetRandomTexture()); // We do it twice because the first one is just loading into the background.
  103. llSetTimerEvent(gfTimerLength);
  104. }
  105. }
  106. touch_start(integer iNumDetected)
  107. {
  108. llSetTimerEvent(0);
  109. ShowPicture(GetRandomTexture());
  110. llSetTimerEvent(gfTimerLength);
  111. }
  112. timer()
  113. {
  114. ShowPicture(GetRandomTexture());
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement