dancer-864.lsl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // :CATEGORY:Dance
  2. // :NAME:Dancer
  3. // :AUTHOR:Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:38:51
  6. // :ID:214
  7. // :NUM:289
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // Dance Server
  12. // :CODE:
  13. // Open source do with as you want license by Ferd Frederix
  14. // plays a random bunch of animations that are located in the prim inventory when it is attached or rezzed.
  15. integer INTERVAL = 30; // how many seconds to play each dance, randomly
  16. // just some constants, nothing here. Move on.
  17. list dances;
  18. integer WHICH; // which dance
  19. integer TOTAL; // how many dances
  20. integer PERMS; // current permissions
  21. integer STATE; // off if flase, 1 = next dance, 2 = random
  22. integer listener; // the current listener, so we can remove it.
  23. integer counter; // counter for timer to auto stop listeners;
  24. // pop up a dialog boz
  25. dialog()
  26. {
  27. llListenRemove(listener);
  28. integer channel = llCeil(llFrand(1000)+100 * -1);
  29. listener = llListen(channel,"","","");
  30. llDialog(llGetOwner(),"Choose",["Next Dance","Stop Dance","Random"], channel);
  31. }
  32. default
  33. {
  34. state_entry()
  35. {
  36. // load up the current animation inventory into a list
  37. integer i;
  38. integer j = llGetInventoryNumber(INVENTORY_ANIMATION);
  39. for (i = 0; i < j; i++)
  40. {
  41. dances += llGetInventoryName(INVENTORY_ANIMATION,i); // add to a list
  42. TOTAL++;
  43. }
  44. STATE = 1; // dance sequentially
  45. llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
  46. dialog();
  47. }
  48. // was rezzed or attached, start over
  49. on_rez(integer param)
  50. {
  51. llResetScript();
  52. }
  53. // someone added or deleted an animation. Start over and ake a new list and
  54. changed(integer what)
  55. {
  56. if (what & CHANGED_INVENTORY)
  57. llResetScript();
  58. }
  59. timer()
  60. {
  61. // since they may hit ignore on the dialog, we count two passes at rthe timer, then kill off any listener.
  62. if (listener)
  63. counter++;
  64. if (counter)
  65. llListenRemove(listener); // remove the listener after two passes to help with lag
  66. // now lets see what to do
  67. PERMS = llGetPermissions();
  68. if (PERMS & PERMISSION_TRIGGER_ANIMATION)
  69. {
  70. if (STATE == 1) // sequential play
  71. {
  72. llStopAnimation(llList2String(dances, WHICH)); // quit the current
  73. WHICH++;
  74. if (WHICH >= TOTAL)
  75. {
  76. WHICH = 0;
  77. }
  78. llStartAnimation(llList2String(dances, WHICH)); // start next one.
  79. llOwnerSay("Dance:" + llList2String(dances, WHICH));
  80. }
  81. else if (STATE == 2) // random play
  82. {
  83. llStopAnimation(llList2String(dances, WHICH));
  84. WHICH = llCeil(llFrand(TOTAL))-1;
  85. llStartAnimation(llList2String(dances, WHICH));
  86. llOwnerSay("Dance:" + llList2String(dances, WHICH));
  87. }
  88. llSetTimerEvent(INTERVAL);
  89. }
  90. else
  91. {
  92. // dang, no permissions, oh well, ask for them
  93. llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
  94. }
  95. }
  96. listen(integer channel, string name, key id, string message)
  97. {
  98. llListenRemove(listener); // save lag
  99. PERMS = llGetPermissions();
  100. if (message == "Stop Dance")
  101. {
  102. STATE = FALSE;
  103. if (PERMS & PERMISSION_TRIGGER_ANIMATION)
  104. {
  105. llStopAnimation(llList2String(dances, WHICH));
  106. }
  107. llSetTimerEvent(0); // shit it all down
  108. }
  109. else if (message == "Next Dance")
  110. {
  111. if (!(PERMS & PERMISSION_TRIGGER_ANIMATION))
  112. {
  113. llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
  114. }
  115. STATE = 1; // flag ithis as sequential
  116. }
  117. else if ( message == "Random")
  118. {
  119. if (!(PERMS & PERMISSION_TRIGGER_ANIMATION))
  120. {
  121. llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
  122. }
  123. STATE = 2; // flag this as random
  124. }
  125. }
  126. touch_start(integer who)
  127. {
  128. if (llDetectedKey(0) == llGetOwner()) // only the owner can do this as we can control only one avatar at a time
  129. {
  130. dialog();
  131. }
  132. }
  133. run_time_permissions(integer perm)
  134. {
  135. PERMS = perm;
  136. llSetTimerEvent(1.0); // trigger the logic in one second
  137. }
  138. }
  139. // END //