Advertisement
boukanjime22

SIT ANIMATION SCRIPT

Jan 11th, 2020
1,394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1. IF YOU NEED SHOW MORE GO TO :https://gurl.pw/i2mq
  2.  
  3.  
  4. /* Edited to bejeezus from an existing free script, "Bailey Simple Poseball Script" by Alkarris Thirty.*/
  5.  
  6. /* EDIT THESE, USER SCUM! */
  7. integer hideAndShowPrim = TRUE; //When set to TRUE, this hides the prim while being sat on, and unhides elsewise
  8. vector aniOffset = <0,0,-0.1>; //This is the physical offset. You will probably only want to edit the third number for up and down offset.
  9. vector aniRotation = <0,0,180>; //This is the rotation set to your body in relation to the prim.
  10.  
  11.  
  12. /* DON'T TOUCH STUFF PAST HERE UNLESS YOU HAVE A CERTIFICATION IN WIZARD SHIT */
  13. list aniList=[];
  14. string currentAnimation;
  15. integer currentPage=0;
  16.  
  17. //populate our list with all of our animations, for a menu system
  18. CatalogAnimations()
  19. {
  20. aniList=[];//reset the list to empty
  21. integer i = 0;
  22. integer aniCount = llGetInventoryNumber(INVENTORY_ANIMATION);
  23. for(i=0;i<aniCount;i++)
  24. {
  25. string foundAni=llGetInventoryName(INVENTORY_ANIMATION, i);
  26. //if the string is more than 24 characters we have to cut it down for the buttons of the menu
  27. if(llStringLength(foundAni)>24) aniList+=llGetSubString(foundAni,0,10)+"…"+llGetSubString(foundAni,-10,-1);
  28. else aniList += foundAni;
  29. }//for loop
  30. llOwnerSay("Found " + (string)aniCount + " animations.");
  31. }//catalog()
  32.  
  33. /* Create a list, with the page argument deciding how to display it:
  34. 1,2,3,etc. - If there are more than 11 poses total, position 0 will always show [PREV PAGE] and [NEXT PAGE] will be position 2 (lower left and lower right, respectively).
  35. Negative (-1, -2, etc.) - Pop an error. Shouldn't happen, but good to debug */
  36. ShowList(integer page)
  37. {
  38. if(page < 0) llDialog(llAvatarOnSitTarget(),"ERROR: Requested negative page. Contact Alkarris Thirty to report a bug in his stupid script, please.",["OK"],-1);//get our negative error catcher out of the way...
  39. else llDialog(llAvatarOnSitTarget(),
  40. "Pick an animation from the list. \nPage: "+(string)currentPage +" \nPlaying: "+ currentAnimation,
  41. DialogSortList(llList2List(aniList,0+(10*(page-1)),9+(10*(page-1)))),-11);
  42. }
  43.  
  44. //This function just rearranges a given list to be Left-to-Right, Top-to-Bottom alpha sorted, taking the Next and Prev buttons in the corners into consideration.
  45. list DialogSortList(list iList){
  46. list oList;
  47. integer buttons=llGetListLength(aniList)>12;
  48. if(llGetListLength(iList)>12&&!buttons||llGetListLength(iList)>10&&buttons) return ["LIST2LONG"];
  49. else {
  50. if(buttons){
  51. oList+=Last3(llList2List(iList,0,-2));
  52. oList=["PREV PAGE"]+llList2List(iList,-1,-1)+["NEXT PAGE"]+oList;
  53. }
  54. else oList = Last3(iList);
  55. }
  56. return oList;
  57. }
  58. list Last3(list iList){ //this is a supplement to the DialogSortList function. I been chuggin brain hurt juice.
  59. if(llGetListLength(iList)<=3) return iList;
  60. else return llList2List(iList, -3, -1) + Last3(llList2List(iList,0,-4));
  61. }
  62.  
  63. string ParseEllipsis(string msg){// match the ellipsis-ized button text to the inventory animation it came from.
  64. list chunks=llParseString2List(msg,["…"],[]);
  65. if(llGetListLength(chunks)>1){
  66. integer i;
  67. for(i=0;i<llGetInventoryNumber(INVENTORY_ANIMATION);++i){
  68. string iName=llGetInventoryName(INVENTORY_ANIMATION,i);
  69. if(llSubStringIndex(iName,llList2String(chunks,0))!=-1&&llSubStringIndex(iName,llList2String(chunks,1))!=-1) return iName;//match found
  70. }
  71. return msg;//no match found
  72. }
  73. else return msg;
  74. }
  75.  
  76. default
  77. {
  78. //Initialize
  79. state_entry()
  80. {
  81. if(aniOffset==<0,0,0>) aniOffset=<0,0,0.1>; //Safeguard to make sure offset isn't 0,0,0 because that will cause llAvatarOnSitTarget to fail.
  82. if(aniRotation==<0,0,0>) aniRotation=<0,0,0.1>;//Rotation safeguard.
  83. llSitTarget(aniOffset, llEuler2Rot(aniRotation*DEG_TO_RAD)); // Set's the sit target position and rotation.
  84. if(hideAndShowPrim==TRUE)llSetAlpha(1.0, ALL_SIDES); // Initialize the object's alpha to visible
  85. CatalogAnimations();
  86. currentPage=1;
  87. llListen(-11,"",llAvatarOnSitTarget(),"");//only listen to the menu choices of whoever's sitting
  88. }
  89.  
  90. listen(integer channel, string name, key id, string msg)
  91. {
  92. if(msg=="NEXT PAGE")
  93. {
  94. //The user pressed NEXT PAGE, so we increment our page count, then check to make sure there'll be animations on the next page, otherwise, we reset the counter back to page 1.
  95. if ((currentPage*10+1) > llGetListLength(aniList)) currentPage=1;
  96. else currentPage++;
  97. ShowList(currentPage);
  98. }
  99. else if(msg=="PREV PAGE")
  100. {
  101. //similar logic, but in decrements
  102. if(currentPage==1) currentPage=llCeil((float)llGetListLength(aniList)/10);
  103. else currentPage--;
  104. ShowList(currentPage);
  105. }
  106. else if(llGetInventoryType(ParseEllipsis(msg))==INVENTORY_ANIMATION)
  107. {
  108. llStopAnimation(currentAnimation);
  109. currentAnimation=ParseEllipsis(msg);
  110. llStartAnimation(currentAnimation);
  111. ShowList(currentPage);
  112. }
  113. else
  114. {
  115. //Okay, the button may have been truncated, now lets waste time and see if it matches up with any inventory item.
  116. integer i=0;
  117. integer aniCount = llGetInventoryNumber(INVENTORY_ANIMATION);
  118. for(i=0;i<aniCount;i++)
  119. {
  120. string foundAni=llGetInventoryName(INVENTORY_ANIMATION, i);
  121. if(llStringLength(foundAni)>24)
  122. {
  123. string inventorySubstring=llGetSubString(foundAni,0,23);
  124. if(msg==inventorySubstring)
  125. {
  126. llStopAnimation(currentAnimation);
  127. currentAnimation=llGetInventoryName(INVENTORY_ANIMATION, i);
  128. llStartAnimation(currentAnimation);
  129. ShowList(currentPage);
  130. }//if inventory substring matches button message
  131. }//if big inventory name
  132. }//for loop
  133. }//else
  134. }
  135.  
  136. touch_start(integer num_detected)
  137. {
  138. //if the sitter clicks the object, reset the page count and display page 1 (or zero)
  139. if(llDetectedKey(0)==llAvatarOnSitTarget())
  140. {
  141. currentPage=1;
  142. ShowList(currentPage);
  143. }
  144. }
  145.  
  146. // Called when an agent sits or unsits
  147. changed(integer change)
  148. {
  149. if(change & CHANGED_LINK)
  150. {
  151. currentPage=1;//reset our page bookmark on sit change
  152. if(llAvatarOnSitTarget() != NULL_KEY) // Makes sure there is a key from the avatar
  153. {
  154. llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION); // If so, request perms to play anim.
  155. }
  156. else //If not (Key is null) then agent unsat. Stop animation, make object visible, make float text visible
  157. {
  158. integer perm=llGetPermissions();
  159. if(llGetInventoryNumber(INVENTORY_ANIMATION)>0) llStopAnimation(currentAnimation);
  160. if(hideAndShowPrim==TRUE)llSetAlpha(1.0, ALL_SIDES);
  161. }
  162. }//if changed_link
  163. if(change & CHANGED_INVENTORY)
  164. {
  165. llOwnerSay("Inventory changed, re-cataloguing animations");
  166. CatalogAnimations();
  167. }//if changed_inventory
  168. if(change & CHANGED_OWNER) llResetScript();
  169. }//changed()
  170.  
  171. // Called when permission to play anim are requested
  172. run_time_permissions(integer perm)
  173. {
  174. if (perm & PERMISSION_TRIGGER_ANIMATION)
  175. {
  176. if(llGetInventoryNumber(INVENTORY_ANIMATION)>0)
  177. {
  178. llStopAnimation("sit"); // Stop the default sit animation
  179. currentAnimation=llGetInventoryName(INVENTORY_ANIMATION,0); // Get the name of an animation in the object inventory
  180. llStartAnimation(currentAnimation); // Start the found animation
  181. currentPage=1;
  182. ShowList(currentPage);
  183. }
  184. else
  185. {
  186. llDialog(llAvatarOnSitTarget(),"No animations loaded into prim. Nothing to animate.",["OK"],-1);
  187. }
  188. if(hideAndShowPrim==TRUE)llSetAlpha(0.0, ALL_SIDES); // Make oject tranparent
  189. }
  190. }//r_t_p()
  191.  
  192. }
  193. /* If you paid for this script, you were ripped off. Sincerely, Alkarris Thirty */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement