Advertisement
Edie_Shoreland

BotZHAO/Revised llSetAO ZHAO

Aug 31st, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // :CATEGORY:AO
  2. // :NAME:ZHAO-II AO for Second life
  3. // :AUTHOR:Chloe1982 Constantine and others
  4. // :CREATED:2014-01-30 19:59:33
  5. // :EDITED:2014-01-30 19:59:33
  6. // :ID:1016
  7. // :NUM:1572
  8. // :REV:1.0
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // ZHAO=II compatible AO using the new LSL Animation functions, timer is now used only to detect swimming
  12. // :CODE:
  13. // As an exercise, I took a version of ZHAO II core and rewrote it to be compatible with a linked message interface, but used the new functions;
  14. // It still needs to poll for swimming but I figured that could be done at a much slower rate than normally used in an AO.
  15. // I had to forgo the ability to replace the typing anim since that would require a faster timer.
  16. //  The new animation override functions don't allow for stacking anims in the way you used to with the , separator so that was given up.
  17. // Finally, in the interests of cramming the core into a single 16k LSL compiled script I didn't implement the timing option for the different anims;
  18. // it could certainly be done, I just chose not to do so!
  19.  
  20.  
  21. // ZHAO-II-core - Ziggy Puff, 07/07
  22. /////////////////////////////////////////////////////////////////////////////////////////////////////
  23. // Evie Moriguchi/Edie Shoreland, 10/05/15 - Allow (but ignore) any [ Typing ] animations
  24. //                   included in notecards without the script sending an error message.
  25. //                   [No need to edit the "Default" notecard, Making it easier to dump ZHAO
  26. //                   contents from an older ZHAO into a bot friendly single prim style AO.
  27. //                   Put all animations (including the typing ones), this script, and the
  28. //                   unedited "Default" notecard into a prim and reset the script.]
  29. //                   Fixed so sitOverride == FALSE actually turns off the sitting override
  30. //                   [Sit Override OFF is just the better option for bots and NPCs, no more
  31. //                   weird glitchy sits while two priority 3 animations fight it out.]
  32. //
  33. // Chloe1982 Constantine, 05/08/13 - Modified/Updated to use the new LSL Animation functions, timer is
  34. //                   now used only to detect swimming (timerEventLength)
  35. //
  36. // Ziggy, 07/16/07 - Warning instead of error on 'no animation in inventory', that way SL's built-in
  37. //                   anims can be used
  38. //
  39. // Ziggy, 07/14/07 - 2 bug fixes. Listens aren't being reset on owner change, and a typo in the
  40. //                   ground sit animation code
  41. //
  42. // Ziggy, 06/07:
  43. //          Reduce script count, since idle scripts take up scheduler time
  44. //          Tokenize notecard reader, to simplify notecard setup
  45. //          Remove scripted texture changes, to simplify customization by animation sellers
  46.  
  47. // Fennec Wind, January 18th, 2007:
  48. //          Changed Walk/Sit/Ground Sit dialogs to show animation name (or partial name if too long)
  49. //          and only show buttons for non-blank entries.
  50. //          Fixed minor bug in the state_entry, ground sits were not being initialized.
  51. //
  52. //
  53. // Dzonatas Sol, 09/06: Fixed forward walk override (same as previous backward walk fix).
  54. //
  55. // Based on Francis Chung's Franimation Overrider v1.8
  56. //
  57. // This program is free software; you can redistribute it and/or modify
  58. // it under the terms of the GNU General Public License as published by
  59. // the Free Software Foundation; either version 2 of the License, or
  60. // (at your option) any later version.
  61. //
  62. // This program is distributed in the hope that it will be useful,
  63. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  64. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  65. // GNU General Public License for more details.
  66. //
  67. // You should have received a copy of the GNU General Public License
  68. // along with this program; if not, write to the Free Software
  69. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
  70.  
  71. /////////////////////////////////////////////////////////////////////////////////////////////////////
  72. // Main engine script - receives link messages from any interface script. Handles the core AO work
  73. //
  74. // Interface definition: The following link_message commands are handled by this script. All of
  75. // these are sent in the string field. All other fields are ignored
  76. //
  77. // ZHAO_RESET                          Reset script
  78. // ZHAO_LOAD|<notecardName>            Load specified notecard
  79. // ZHAO_NEXTSTAND                      Switch to next stand
  80. // ZHAO_STANDTIME|<time>               Time between stands. Specified in seconds, expects an integer.
  81. //                                     0 turns it off
  82. // ZHAO_AOON                           AO On
  83. // ZHAO_AOOFF                          AO Off
  84. // ZHAO_SITON                          Sit On
  85. // ZHAO_SITOFF                         Sit Off
  86. // ZHAO_RANDOMSTANDS                   Stands cycle randomly
  87. // ZHAO_SEQUENTIALSTANDS               Stands cycle sequentially
  88. // ZHAO_SETTINGS                       Prints status
  89. // ZHAO_SITS                           Select a sit
  90. // ZHAO_GROUNDSITS                     Select a ground sit
  91. // ZHAO_WALKS                          Select a walk
  92. //
  93. // So, to send a command to the ZHAO-II engine, send a linked message:
  94. //
  95. //   llMessageLinked(LINK_SET, 0, "ZHAO_AOON", NULL_KEY);
  96. //
  97. // This script uses a listener on channel -91234. If other scripts are added to the ZHAO, make sure
  98. // they don't use the same channel
  99. /////////////////////////////////////////////////////////////////////////////////////////////////////
  100.  
  101. /////////////////////////////////////////////////////////////////////////////////////////////////////
  102. // New notecard format
  103. //
  104. /////////////////////////////////////////////////////////////////////////////////////////////////////
  105. // Lines starting with a / are treated as comments and ignored. Blank lines are ignored. Valid lines
  106. // look like this:
  107. //
  108. // [ Walking ]SexyWalk1|SexyWalk2|SexyWalk3
  109. //
  110. // The token (in this case, [ Walking ]) identifies the animation to be overridden. The rest is a
  111. // list of animations, separated by the '|' (pipe) character. You can specify multiple animations
  112. // for Stands, Walks, Sits, and GroundSits. Multiple animations on any other line will be ignored.
  113. // You can have up to 12 animations each for Walks, Sits and GroundSits. There is no hard limit
  114. // on the number of stands, but adding too many stands will make the script run out of memory and
  115. // crash, so be careful. You can repeat tokens, so you can split the Stands up across multiple lines.
  116. // Use the [ Standing ] token in each line, and the script will add the animation lists together.
  117. //
  118. // Advanced: Each 'animation name' can be a comma-separated list of animations, which will be played
  119. // together. For example:
  120. //
  121. // [ Walking ]SexyWalk1UpperBody,SexyWalk1LowerBody|SexyWalk2|SexyWalk3
  122. //
  123. // Note the ',' between SexyWalk1UpperBody and SexyWalk1LowerBody - this tells ZHAO-II to treat these
  124. // as a single 'animation' and play them together. The '|' between this 'animation' and SexyWalk2 tells
  125. // ZHAO-II to treat SexyWalk2 and SexyWalk3 as separate walk animations. You can use this to layer
  126. // animations on top of each other.
  127. //
  128. // Do not add any spaces around animation names!!!
  129. //
  130. // The token can be one of the following:
  131. //
  132. // [ Standing ]
  133. // [ Walking ]
  134. // [ Sitting ]
  135. // [ Sitting On Ground ]
  136. // [ Crouching ]
  137. // [ Crouch Walking ]
  138. // [ Landing ]
  139. // [ Standing Up ]
  140. // [ Falling ]
  141. // [ Flying Down ]
  142. // [ Flying Up ]
  143. // [ Flying ]
  144. // [ Flying Slow ]
  145. // [ Hovering ]
  146. // [ Jumping ]
  147. // [ Pre Jumping ]
  148. // [ Running ]
  149. // [ Turning Right ]
  150. // [ Turning Left ]
  151. // [ Floating ]
  152. // [ Swimming Forward ]
  153. // [ Swimming Up ]
  154. // [ Swimming Down ]
  155. //
  156.  
  157.  
  158. // CONSTANTS
  159. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  160. // Default notecard we read on script_entry
  161. string defaultNoteCard = "Default";
  162.  
  163. // List of all the animation states
  164. list animState = [ "Sitting on Ground", "Sitting", "Striding", "Crouching", "CrouchWalking",
  165.                    "Soft Landing", "Standing Up", "Falling Down", "Hovering Down", "Hovering Up",
  166.                    "FlyingSlow", "Flying", "Hovering", "Jumping", "PreJumping", "Running",
  167.                    "Turning Right", "Turning Left", "Walking", "Landing", "Standing", "Taking Off" ];
  168.  
  169. // Logic change - we now have a list of tokens. The 'overrides' list is the same length as this,
  170. // i.e. it has one entry per token, *not* one entry per animation. Multiple options for a token
  171. // are stored as | separated strings in a single list entry. This was done to save memory, and
  172. // allow a larger number of stands etc. All the xxxIndex variables now refer to the token index,
  173. // since that's how long 'overrides' is.
  174.  
  175. // List of internal tokens. This *must* be in the same sequence as the animState list. Note that
  176. // we combine some tokens after the notecard is read (striding/walking, landing/soft landing), etc.
  177. // The publicized tokens list only contains one entry for each pair, but we'll accept both, and
  178. // combine them later
  179. list tokens = [ "Sitting On Ground", "Sitting",     "Striding", "Crouching", "Crouch Walking",        // 0-4
  180.                 "Soft Landing", "Standing Up", "Falling", "Flying Down", "Flying Up",            // 5-9
  181.                 "Flying Slow", "Flying", "Hovering", "Jumping", "Pre Jumping",                    // 10-14
  182.                 "Running", "Turning Right", "Turning Left", "Walking", "Landing",                // 15-19
  183.                 "Standing", "Taking Off", "Swimming Down", "Swimming Up", "Swimming Forward",    // 20-24
  184.                 "Floating" ];                                                                    // 25
  185.  
  186. // The tokens for which we allow multiple animations
  187. string multiAnimTokenIndexes = ",0,1,18,20,";    // Groundsit, Sitting, Walking, Standing
  188.  
  189. // Index of interesting animations
  190. integer noAnimIndex     = -1;
  191. integer sitgroundIndex  = 0;
  192. integer sittingIndex    = 1;
  193. /*
  194. integer hoverdownIndex  = 8;
  195. integer hoverupIndex    = 9;
  196. integer flyingslowIndex = 10;
  197. integer flyingIndex     = 11;
  198. integer hoverIndex      = 12;
  199. */
  200. integer walkingIndex    = 18;
  201. integer standingIndex   = 20;
  202. /*
  203. integer swimdownIndex   = 22;
  204. integer swimupIndex     = 23;
  205. integer swimmingIndex   = 24;
  206. integer waterTreadIndex = 25;
  207. */
  208.  
  209. // magic string that replaces the following commented out lists
  210. string magicPos = "12111009082524242322";
  211. // number of swimming replacement anims
  212. integer magicSwim = 5;
  213.  
  214. // list of animations that have a different value when underwater
  215. //list underwaterAnim = [ hoverIndex, flyingIndex, flyingslowIndex, hoverupIndex, hoverdownIndex ];
  216.  
  217. // corresponding list of animations that we override the overrider with when underwater
  218. //list underwaterOverride = [ waterTreadIndex, swimmingIndex, swimmingIndex, swimupIndex, swimdownIndex];
  219.  
  220. // How long before flipping stand animations
  221. integer standTimeDefault = 30;
  222.  
  223. // How fast should we poll for whether or not we're under water?
  224. // NOTE, you can change this to whatever value you like, it will just change the delay on how long it takes
  225. // you to start/stop swimming
  226.  
  227. float timerEventLength = 3.0;
  228.  
  229. // Number of timer events that will have to pass to change an anim
  230. integer maxTicks;
  231. // Number of ticks that have passed
  232. integer numTicks = 0;
  233. // Are we underwater?
  234. integer    isUnder = FALSE;
  235.  
  236. // Listen channel for pop-up menu
  237. integer listenChannel = -91234;
  238.  
  239. // GLOBALS
  240. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  241.  
  242. integer numStands;                          // Number of stands - needed for auto cycle
  243. integer randomStands = FALSE;               // Whether stands cycle randomly
  244. integer curStandIndex;                      // Current stand - needed for cycling
  245. string curStandAnim = "";                   // Current Stand animation
  246. string curSitAnim = "";                     // Current sit animation
  247. string curWalkAnim = "";                    // Current walk animation
  248. string curGsitAnim = "";                    // Current ground sit animation
  249.  
  250. list overrides = [];                        // List of animations we override
  251. key notecardLineKey;                        // notecard reading keys
  252. integer notecardIndex;                      // current line being read from notecard
  253. integer numOverrides;                       // # of overrides
  254.  
  255. integer standTime = standTimeDefault;       // How long before flipping stand animations
  256.  
  257. integer animOverrideOn = TRUE;              // Is the animation override on?
  258. integer gotPermission  = FALSE;             // Do we have animation permissions?
  259.  
  260. integer listenHandle;                       // Listen handlers - only used for pop-up menu, then turned off
  261.  
  262. integer haveWalkingAnim = FALSE;            // Hack to get it so we face the right way when we walk backwards
  263.  
  264. integer sitOverride = FALSE;                 // Whether we're overriding sit or not
  265.  
  266. integer listenState = 0;                    // What pop-up menu we're handling now
  267.  
  268. integer loadInProgress = FALSE;             // Are we currently loading a notecard
  269. string notecardName = "";                   // The notecard we're currently reading
  270.  
  271. key Owner = NULL_KEY;
  272.  
  273. // String constants to save a few bytes
  274. string EMPTY = "";
  275. string SEPARATOR = "|";
  276. string TRYAGAIN = "\nPlease correct the notecard and try again.";
  277.  
  278. // CODE
  279. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  280.  
  281. // Enable or disable the AO
  282.  
  283. AO_Enable()
  284. {
  285.     llSetTimerEvent(timerEventLength);
  286.     numTicks = 0;
  287.     if (gotPermission)
  288.         sendOverrides();
  289. }
  290.  
  291. AO_Disable()
  292. {
  293.     llSetTimerEvent(0.0);
  294.     if (gotPermission)
  295.         llResetAnimationOverride("ALL");            // Clear them all out
  296. }
  297.  
  298. // Send new overrides to the server
  299. sendOverrides()
  300. {
  301.     integer n = llGetListLength(animState);
  302.     string anim = EMPTY;
  303.     string st;
  304.     while (n--)
  305.     {
  306.         st = llList2String(animState, n);
  307.         if ((anim = llList2String(overrides, n)) == EMPTY)
  308.             llResetAnimationOverride(st);
  309.         else if (llSubStringIndex(multiAnimTokenIndexes, "," + (string)n + ",") == -1)
  310.             doAnimSet(st, anim);
  311.         else
  312.         {
  313.             if (n == 0)
  314.                 anim = curGsitAnim;
  315.             else if (n == 1)
  316.                 anim = curSitAnim;
  317.             else if (n == 18)
  318.                 anim = curWalkAnim;
  319.             else
  320.                 anim = curStandAnim;
  321.             doAnimSet(st, anim);
  322.         }
  323.     }
  324. }
  325.  
  326. // Switch to the next stand anim
  327. doNextStand(integer fromUI)
  328. {
  329.     if (numStands > 0)
  330.     {
  331.         if (randomStands)
  332.             curStandIndex = llFloor(llFrand(numStands));
  333.         else
  334.             curStandIndex = (curStandIndex + 1) % numStands;
  335.  
  336.         doAnimSet("Standing", curStandAnim = findMultiAnim(20, curStandIndex));  //, 20
  337.  
  338.         if (fromUI)
  339.             llOwnerSay("Switching to stand '" + curStandAnim + "'.");
  340.     }
  341.     else if (fromUI)
  342.         llOwnerSay("No stand animations configured.");
  343. }
  344.  
  345. // Actually set the animation (if we need to)
  346. // Fixed so sitOverride can actually be turned off
  347. doAnimSet(string st, string anim)
  348. {
  349.     if (anim == EMPTY)
  350.         return;
  351.     if (animOverrideOn)
  352.     {
  353.         if (sitOverride == TRUE) llSetAnimationOverride(st, anim);
  354.         else if (st != "Sitting") llSetAnimationOverride(st, anim);
  355.     }
  356. }
  357.  
  358. // Displays menu of animation choices
  359. doMultiAnimMenu( integer _animIndex, string _animType, string _currentAnim )
  360. {
  361.     // Dialog enhancement - Fennec Wind
  362.     // Fix - a no-mod anim with a long name will break this
  363.  
  364.     list anims = llParseString2List( llList2String(overrides, _animIndex), [SEPARATOR], [] );
  365.     integer numAnims = llGetListLength( anims );
  366.     if ( numAnims > 12 ) {
  367.         llOwnerSay( "Too many animations, cannot generate menu. " + TRYAGAIN );
  368.         return;
  369.     }
  370.  
  371.     list buttons = [];
  372.     integer i;
  373.     string animNames = EMPTY;
  374.     for ( i=0; i<numAnims; i++ ) {
  375.         animNames += "\n" + (string)(i+1) + ". " + llList2String( anims, i );
  376.         buttons += [(string)(i+1)];
  377.     }
  378.     // If no animations were configured, say so and just display an "OK" button
  379.     if ( animNames == EMPTY ) {
  380.         animNames = "\n\nNo overrides have been configured.";
  381.     }
  382.     llListenControl(listenHandle, TRUE);
  383.     llDialog( Owner, "Select the " + _animType + " animation to use:\n\nCurrently: " + _currentAnim + animNames,
  384.               buttons, listenChannel );
  385. }
  386.  
  387. // Returns an animation from the multiAnims
  388. string findMultiAnim( integer _animIndex, integer _multiAnimIndex )
  389. {
  390.     list animsList = llParseString2List( llList2String(overrides, _animIndex), [SEPARATOR], [] );
  391.     return llList2String( animsList, _multiAnimIndex );
  392. }
  393.  
  394. // Checks for too many animations - can't do menus with > 12 animations
  395. checkMultiAnim( integer _animIndex, string _animName )
  396. {
  397.     list animsList = llParseString2List( llList2String(overrides, _animIndex), [SEPARATOR], [] );
  398.     if ( llGetListLength(animsList) > 12 )
  399.         llOwnerSay( "You have more than 12 " + _animName + " animations. Please correct this." );
  400. }
  401.  
  402. checkAnimInInventory( string _csvAnims )
  403. {
  404.     list anims = llCSV2List( _csvAnims );
  405.     integer i;
  406.     for( i=0; i<llGetListLength(anims); i++ ) {
  407.         string animName = llList2String( anims, i );
  408.         if ( llGetInventoryType( animName ) != INVENTORY_ANIMATION ) {
  409.             // Only a warning, so built-in anims can be used
  410.             llOwnerSay( "Warning: Couldn't find animation '" + animName + "' in inventory." );
  411.         }
  412.     }
  413. }
  414.  
  415. // Print free memory. Separate function to save a few bytes
  416. printFreeMemory()
  417. {
  418.     float memory = (float)llGetFreeMemory() * 100.0 / 16384.0;
  419.     llOwnerSay( (string)((integer)memory) + "% memory free" );
  420. }
  421.  
  422. doWater(integer drowning)
  423. {
  424.     if (isUnder == drowning)
  425.         return;
  426.     integer n = magicSwim;
  427.     integer off = 0;
  428.     if (isUnder = drowning)
  429.         off = 2 * n;
  430.  
  431.     integer p;
  432.     integer po;
  433.     string anim;
  434.     string st;
  435.     while (n--)
  436.     {
  437.         po = p = (integer)llGetSubString(magicPos, n * 2, n * 2 + 1);
  438.         if (isUnder)
  439.             po = (integer)llGetSubString(magicPos, n * 2 + off, n * 2 + 1 + off);
  440.         st = llList2String(animState, p);
  441.         if ((anim = llList2String(overrides, po)) == EMPTY)
  442.             llResetAnimationOverride(st);
  443.         else
  444.             doAnimSet(st, anim);
  445.     }
  446. }
  447.  
  448. // Load all the animation names from a notecard
  449. loadNoteCard() {
  450.  
  451.     if ( llGetInventoryKey(notecardName) == NULL_KEY ) {
  452.         llOwnerSay( "Notecard '" + notecardName + "' does not exist, or does not have full permissions." );
  453.         loadInProgress = FALSE;
  454.         notecardName = EMPTY;
  455.         return;
  456.     }
  457.  
  458.     llOwnerSay( "Loading notecard '" + notecardName + "'..." );
  459.  
  460.     // Faster events while processing our notecard
  461.     llMinEventDelay( 0 );
  462.  
  463.     // Clear out saved override information, since we now allow sparse notecards
  464.     overrides = [];
  465.     integer i;
  466.     for ( i=0; i<numOverrides; i++ )
  467.         overrides += [EMPTY];
  468.  
  469.     // Clear out multi-anim info as well, since we may end up with fewer options
  470.     // that the last time
  471.     curStandIndex = 0;
  472.     curStandAnim = EMPTY;
  473.     curSitAnim = EMPTY;
  474.     curWalkAnim = EMPTY;
  475.     curGsitAnim = EMPTY;
  476.  
  477.     // Start reading the data
  478.     notecardIndex = 0;
  479.     notecardLineKey = llGetNotecardLine( notecardName, notecardIndex );
  480. }
  481.  
  482. // Stop loading notecard
  483. endNotecardLoad()
  484. {
  485.     loadInProgress = FALSE;
  486.     notecardName = EMPTY;
  487. }
  488.  
  489. // Initialize listeners, and reset some status variables
  490. initialize() {
  491.     Owner = llGetOwner();
  492.  
  493.     float tevent = 0.0;
  494.     if (animOverrideOn)
  495.         tevent = standTime;
  496.     llSetTimerEvent(tevent);
  497.     numTicks = 0;
  498.     maxTicks = llRound(standTime / timerEventLength);
  499.  
  500.     gotPermission = FALSE;
  501.  
  502.     // Create new listener, and turn it off
  503.     if ( listenHandle )
  504.         llListenRemove( listenHandle );
  505.  
  506.     listenHandle = llListen( listenChannel, EMPTY, Owner, EMPTY );
  507.     llListenControl( listenHandle, FALSE );
  508.  
  509.     printFreeMemory();
  510. }
  511.  
  512. // STATE
  513. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  514.  
  515. default {
  516.     state_entry() {
  517.         integer i;
  518.  
  519.         Owner = llGetOwner();
  520.  
  521.         // Just a precaution, this shouldn't be on after a reset
  522.         if ( listenHandle )
  523.             llListenRemove( listenHandle );
  524.  
  525.         listenHandle = llListen( listenChannel, EMPTY, Owner, EMPTY );
  526.  
  527.         if (llGetAttached())
  528.             llRequestPermissions(Owner, PERMISSION_OVERRIDE_ANIMATIONS);
  529.  
  530.         numOverrides = llGetListLength(tokens);
  531.  
  532.         // populate override list with blanks
  533.         overrides = [];
  534.         for ( i=0; i<numOverrides; i++ ) {
  535.             overrides += [ EMPTY ];
  536.         }
  537.         randomStands = FALSE;
  538.         initialize();
  539.         notecardName = defaultNoteCard;
  540.         loadInProgress = TRUE;
  541.         loadNoteCard();
  542.     }
  543.  
  544.     on_rez( integer _code ) {
  545.         initialize();
  546.     }
  547.  
  548.     attach( key _k ) {
  549.         if (_k != NULL_KEY)
  550.             llRequestPermissions(Owner, PERMISSION_OVERRIDE_ANIMATIONS);
  551.         else if (gotPermission)
  552.             llResetAnimationOverride("ALL");
  553.         gotPermission = FALSE;
  554.     }
  555.  
  556.     run_time_permissions( integer _perm ) {
  557.         if (_perm & PERMISSION_OVERRIDE_ANIMATIONS)
  558.         {
  559.             if (animOverrideOn)
  560.                 sendOverrides();
  561.             gotPermission = TRUE;
  562.         }
  563.     }
  564.  
  565.     link_message( integer _sender, integer _num, string _message, key _id) {
  566.  
  567.         // Coming from an interface script
  568.         if ( _message == "ZHAO_RESET" ) {
  569.             llOwnerSay( "Resetting..." );
  570.             llResetScript();
  571.  
  572.         } else if ( _message == "ZHAO_AOON" ) {
  573.             animOverrideOn = TRUE;
  574.             llOwnerSay("AO Enabled.");
  575.             AO_Enable();
  576.  
  577.         } else if ( _message == "ZHAO_AOOFF" ) {
  578.             animOverrideOn = FALSE;
  579.             llOwnerSay("AO Disabled.");
  580.             AO_Disable();
  581.  
  582.         } else if ( _message == "ZHAO_SITON" ) {
  583.             // Turning on sit override
  584.             sitOverride = TRUE;
  585.             llOwnerSay("Sit override: On");
  586.             doAnimSet("Sitting", curSitAnim);
  587.  
  588.         } else if ( _message == "ZHAO_SITOFF" ) {
  589.             // Turning off sit override
  590.             sitOverride = FALSE;
  591.             llOwnerSay("Sit override: Off");
  592.             llResetAnimationOverride("Sitting");
  593.  
  594.         } else if ( _message == "ZHAO_RANDOMSTANDS" ) {
  595.             // Cycling to next stand - sequential or random
  596.             randomStands = TRUE;
  597.             llOwnerSay( "Stand cycling: Random" );
  598.  
  599.         } else if ( _message == "ZHAO_SEQUENTIALSTANDS" ) {
  600.             // Cycling to next stand - sequential or random
  601.             randomStands = FALSE;
  602.             llOwnerSay( "Stand cycling: Sequential" );
  603.  
  604.         } else if ( _message == "ZHAO_SETTINGS" ) {
  605.             // Print settings
  606.             if ( sitOverride == TRUE ) {
  607.                 llOwnerSay( "Sit override: On" );
  608.             } else {
  609.                 llOwnerSay( "Sit override: Off" );
  610.             }
  611.             if ( randomStands == TRUE ) {
  612.                 llOwnerSay( "Stand cycling: Random" );
  613.             } else {
  614.                 llOwnerSay( "Stand cycling: Sequential" );
  615.             }
  616.             llOwnerSay( "Stand cycle time: " + (string)standTime + " seconds" );
  617.  
  618.         } else if ( _message == "ZHAO_NEXTSTAND" ) {
  619.             // Cycling to next stand - sequential or random. This is from UI, so we
  620.             // want feedback
  621.             doNextStand( TRUE );
  622.  
  623.         } else if ( llGetSubString(_message, 0, 14) == "ZHAO_STANDTIME|" ) {
  624.             // Stand time change
  625.             maxTicks = llRound((standTime = (integer)llGetSubString(_message, 15, -1)) / timerEventLength);
  626.             llOwnerSay( "Stand cycle time: " + (string)standTime + " seconds" );
  627.  
  628.         } else if ( llGetSubString(_message, 0, 9) == "ZHAO_LOAD|" ) {
  629.             // Can't load while we're in the middle of a load
  630.             if ( loadInProgress == TRUE ) {
  631.                 llOwnerSay( "Cannot load new notecard, still reading notecard '" + notecardName + "'" );
  632.                 return;
  633.             }
  634.  
  635.             // Notecard menu
  636.             loadInProgress = TRUE;
  637.             notecardName = llGetSubString(_message, 10, -1);
  638.             loadNoteCard();
  639.  
  640.         } else if ( _message == "ZHAO_SITS" ) {
  641.             // Selecting new sit anim
  642.  
  643.             // Move these to a common function
  644.             doMultiAnimMenu( sittingIndex, "Sitting", curSitAnim );
  645.  
  646.             listenState = 1;
  647.  
  648.         } else if ( _message == "ZHAO_WALKS" ) {
  649.             // Same thing for the walk
  650.  
  651.             // Move these to a common function
  652.             doMultiAnimMenu( walkingIndex, "Walking", curWalkAnim );
  653.  
  654.             listenState = 2;
  655.         } else if ( _message == "ZHAO_GROUNDSITS" ) {
  656.             // And the ground sit
  657.  
  658.             // Move these to a common function
  659.             doMultiAnimMenu( sitgroundIndex, "Sitting On Ground", curGsitAnim );
  660.  
  661.             listenState = 3;
  662.         }
  663.     }
  664.  
  665.     listen( integer _channel, string _name, key _id, string _message) {
  666.         // Turn listen off. We turn it on again if we need to present
  667.         // another menu
  668.         llListenControl(listenHandle, FALSE);
  669.  
  670.         if ( listenState == 1 ) {
  671.             doAnimSet("Sitting", curSitAnim = findMultiAnim(1, (integer)_message - 1));
  672.             llOwnerSay("New sitting animation: " + curSitAnim);
  673.  
  674.         } else if ( listenState == 2 ) {
  675.             doAnimSet("Walking", curWalkAnim = findMultiAnim(18, (integer)_message - 1));
  676.             llOwnerSay("New walking animation: " + curWalkAnim);
  677.  
  678.         } else if ( listenState == 3 ) {
  679.             doAnimSet("Sitting on Ground", curGsitAnim = findMultiAnim(0, (integer)_message - 1));
  680.             llOwnerSay("New groundsit animation: " + curGsitAnim);
  681.         }
  682.     }
  683.  
  684.     dataserver( key _query_id, string _data )
  685.     {
  686.         if ( _query_id != notecardLineKey )
  687.             return;
  688.  
  689.         if ( _data == EOF )
  690.         {
  691.             // Now the read ends when we hit EOF
  692.  
  693.             // End-of-notecard handling...
  694.  
  695.             // See how many walks/sits/ground-sits we have
  696.             checkMultiAnim(18, "walking");
  697.             checkMultiAnim(1, "sitting");
  698.  
  699.             // Reset stand, walk, sit and ground-sit anims to first entry
  700.             curStandIndex = 0;
  701.             numStands = llGetListLength(llParseString2List(llList2String(overrides, 20), (list)SEPARATOR, [])); //FIX
  702.  
  703.             curStandAnim = findMultiAnim(20, 0);
  704.             curWalkAnim = findMultiAnim(18, 0);
  705.             curSitAnim = findMultiAnim(1, 0);
  706.  
  707.             endNotecardLoad();
  708.             llOwnerSay("LSL Functions/AO loaded. Mem:" + (string)llGetFreeMemory());
  709.  
  710.             return;
  711.         }
  712.  
  713.         // We ignore blank lines and lines which start with a #
  714.         // Accept (and ignore) [ Typing ] entries in default notecards  
  715.         if (_data == EMPTY || llGetSubString(_data, 0, 0) == "#" || llGetSubString(_data, 0, 9) == "[ Typing ]")
  716.         {
  717.             notecardLineKey = llGetNotecardLine(notecardName, ++notecardIndex);
  718.             return;
  719.         }
  720.  
  721.         // Let's get a token
  722.         integer p = llSubStringIndex(_data, "[");
  723.         string token = EMPTY;
  724.         string anims = EMPTY;
  725.         if (p != -1)
  726.         {
  727.             if ((p = llSubStringIndex(_data = llDeleteSubString(_data, 0, p), "]")) != -1)
  728.             {
  729.                 token = llStringTrim(llGetSubString(_data, 0, p - 1), STRING_TRIM);
  730.                 anims = llStringTrim(llDeleteSubString(_data, 0, p), STRING_TRIM);
  731.                 if ((p = llListFindList(tokens, [token])) == -1)
  732.                 {
  733.                     llOwnerSay("AO:bad data on line " + (string)(notecardIndex+1) + " of " + notecardName + TRYAGAIN); // start from 1
  734.                     endNotecardLoad();
  735.                     return;
  736.                 }
  737.             }
  738.         }
  739.  
  740.         if (anims != EMPTY)
  741.         {
  742.             // See if this is a token for which we allow multiple animations
  743.             if (llSubStringIndex(multiAnimTokenIndexes, "," + (string)p + ",") != -1)
  744.             {  //FIX
  745.                 list anims2Add = llParseString2List(anims, (list)SEPARATOR, []); //FIX
  746.                 // Make sure the anims exist
  747.                 integer k = llGetListLength(anims2Add);
  748.                 while (k--)
  749.                     checkAnimInInventory(llList2String(anims2Add, k));
  750.  
  751.                 // Join the string and list and put it back into overrides
  752.                 overrides = llListReplaceList(overrides, (list)(llList2String(overrides, p) + SEPARATOR + llDumpList2String(anims2Add, SEPARATOR)), p, p ); //FIX
  753.             }
  754.             else
  755.             {
  756.                 // This is an animation for which we only allow one override
  757.                 if (llSubStringIndex(anims, SEPARATOR) != -1)
  758.                 {
  759.                     llOwnerSay("Multiple anims for " + token + " not allowed. " + TRYAGAIN);
  760.                     endNotecardLoad();
  761.                     return;
  762.                 }
  763.  
  764.                 // Inventory check
  765.                 checkAnimInInventory(anims);
  766.  
  767.                 // We're good
  768.                 overrides = llListReplaceList(overrides, (list)anims, p, p); //FIX
  769.             }
  770.         }
  771.  
  772.         // Wow, after all that, we read one line of the notecard
  773.         notecardLineKey = llGetNotecardLine(notecardName, ++notecardIndex);
  774.     }
  775.  
  776.     timer() {
  777.         vector cur = llGetPos();
  778.         doWater(cur.z < llWater(ZERO_VECTOR));
  779.         if (!(numTicks = (numTicks + 1) % maxTicks))
  780.         {
  781.             if (llGetAnimation(Owner) == "Standing")
  782.                 doNextStand(FALSE);
  783.         }
  784.     }
  785. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement