ZenMondo's Modeling Stand

From ZenMondo Wormser, 1 Year ago, written in Linden Scripting, viewed 433 times.
URL http://flynnos.org/flynnbin/view/0a477c5c Embed
Download Paste or View Raw
  1. /////////////////////////////////////////////////////////////
  2. //
  3. // ZenMondo's Modeling Stand by ZenMondo Wormser
  4. //
  5. // Place this script in an object along with
  6. // an assortment of animations.
  7. //
  8. // Sitting on the object will pose an avatar 1 meter
  9. // above the object.
  10. //
  11. // Click the object to get a menu to select an animation
  12. //
  13. /////////////////////////////////////////////////////////////
  14.  
  15. ///////////////////////////
  16. // This work is licensed under the Creative Commons Attribution-Noncommercial-Share
  17. // Alike 3.0 License. To view a copy of this license, visit
  18. // http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
  19. // Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
  20. //
  21. // Attribution:
  22. //  If unmodified you must keep the filename intact
  23. //  If a derivative work you must say "Based on the CodePoetry of ZenMondo Wormser"
  24. //////////////////////////
  25.  
  26.  
  27. integer object_counter=0;
  28. list inventory_list = [];
  29. list menu_list = [];
  30.  
  31. integer menu_page;
  32. integer last_menu;
  33.  
  34. integer handle;
  35. integer UserChan = -11811;
  36.  
  37. key current_user = NULL_KEY;
  38.  
  39. integer using;
  40. integer animating;
  41. string current_anim;
  42.  
  43. //Functions
  44.  
  45. //Compact function to put buttons in "correct" human-readable order ~ Redux
  46. //Taken from http://lslwiki.net/lslwiki/wakka.php?wakka=llDialog
  47. list order_buttons(list buttons)
  48. {
  49.     return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
  50. }
  51.  
  52.  
  53. //Function to Build the two lists we will use
  54. // Could have put it all in state_entry but may be a handy function
  55. // to use in another similar script so I put it here.
  56. BuildLists()
  57. {
  58.     integer counter=0;
  59.     integer inventory_num = llGetInventoryNumber(INVENTORY_ANIMATION);
  60.        
  61.     while(counter < inventory_num)
  62.     {
  63.         string object_name = llGetInventoryName(INVENTORY_ANIMATION, counter);
  64.        
  65.         inventory_list = (inventory_list=[]) + inventory_list + object_name;
  66.         menu_list = (menu_list=[]) + menu_list + [(string) (++counter) + ")" + object_name];   //Incrimenting the the counter in this line.  Probably bad practice
  67.                 //But it solves two problems, incrimenting the counter in the loop
  68.                 // and making a human readale list startign at "1" instead of "0"
  69.  
  70.     }
  71.      
  72.     if(counter % 9 == 0) //Multiples of 9 won't round down right.
  73.     {
  74.         --counter;
  75.     }
  76.    
  77.     last_menu = llFloor(counter / 9.0); //I say 9.0 so it treats it like a float
  78.                                         // and will round down correctly.
  79.    
  80.    
  81.    
  82. }
  83.  
  84.  
  85. //Function to Display the pages of the Menu
  86. // Instead of defining my menus ahead of time
  87. // (and in so doing putting a limit on the number of items)
  88. // I build the pages of the menu dynamicaly
  89. DisplayMenu(key id)
  90. {
  91.     //These are the buttons, they will be numbers
  92.     // Based on what page of the menu we are on.
  93.    
  94.     string b1 = (string) (menu_page *9 +1);
  95.     string b2 = (string) (menu_page *9 +2);
  96.     string b3 = (string) (menu_page *9 +3);
  97.     string b4 = (string) (menu_page *9 +4);
  98.     string b5 = (string) (menu_page *9 +5);
  99.     string b6 = (string) (menu_page *9 +6);
  100.     string b7 = (string) (menu_page *9 +7);
  101.     string b8 = (string) (menu_page *9 +8);
  102.     string b9 = (string) (menu_page *9 +9);
  103.  
  104.    
  105.        list menu = [b1, b2, b3, b4, b5, b6, b7, b8, b9, "<<PREV", "Home", "NEXT>>"]; //will use the order_buttons function to put these in a good order for llDialog
  106.    
  107.     list menu_text = llList2List(menu_list, menu_page * 9, menu_page * 9  + 8); //This is the part of the list for menu text for this page.
  108.    
  109.     integer menu_length = llGetListLength(menu_text);
  110.    
  111.     if(menu_length < 9) //Don't Need all the buttons
  112.     {
  113.         menu = llDeleteSubList(menu, menu_length, 8); //Trim the menu buttons
  114.     }
  115.    
  116.     llDialog(id, llDumpList2String(menu_text, "\n"), order_buttons(menu), UserChan); //Display the Menu
  117.      
  118. }
  119. {
  120.      state_entry()
  121.     {
  122.         menu_page = 0;
  123.        
  124.         UserChan = -((integer)llFrand(2147483646.0) + 1); //Choose a random  negative channel to use to avoid crossttalk with other books
  125.  
  126.         BuildLists();
  127.  
  128.         llSitTarget(<0.0, 0.0, 1.0>, ZERO_ROTATION);  //Position where Avatar will Sit
  129.    
  130.         llSetSitText("Pose");
  131.        
  132.     }
  133.  
  134.     touch_start(integer total_number)
  135.     {if(using) //Object in use
  136.        {
  137.             if(current_user != llDetectedKey(0))
  138.             {
  139.                 //Communicate using llDialog we are in a library after all
  140.                 // and its even quieter than a whisper.
  141.                 llDialog(llDetectedKey(0), "I'm sorry another user is using me at this time, please wait a moment and try again.", ["OK"], 1181111811);
  142.             }
  143.            
  144.             else // Our user
  145.             {
  146.                 DisplayMenu(current_user); //Give the menu again but not more time
  147.                                         // This is in case they accidently hit "ignore"
  148.             }
  149.         }
  150.        
  151.         else //Giver is available and ready for use
  152.         {
  153.             current_user = llDetectedKey(0);
  154.             using = TRUE;
  155.             handle = llListen(UserChan, "", current_user, "");
  156.             llSetTimerEvent(90); //90 Second limit to make a choice or reset if walk away
  157.             DisplayMenu(current_user);
  158.            
  159.         }
  160.        
  161.          
  162.     }
  163.  
  164.     listen(integer channel, string name, key id, string message)
  165.     {
  166.         if(message == "Home")
  167.         {
  168.             llSetTimerEvent(90);
  169.             menu_page = 0;
  170.             DisplayMenu(current_user);
  171.            
  172.         }
  173.        
  174.         else if(message == "<<PREV")
  175.         {
  176.             menu_page--;
  177.             if(menu_page == -1)
  178.             {
  179.                 menu_page = last_menu;
  180.             }
  181.            
  182.             DisplayMenu(current_user);
  183.         }
  184.        
  185.         else if(message == "NEXT>>")
  186.         {
  187.             menu_page++;
  188.             if(menu_page > last_menu)
  189.             {
  190.                 menu_page = 0;
  191.             }
  192.            
  193.             DisplayMenu(current_user);
  194.         }
  195.        
  196.         else //Patron Chose a Number
  197.         {
  198.             llSetTimerEvent(0);
  199.             llListenRemove(handle);
  200.            
  201.             integer get_item = (integer) message;
  202.             get_item--; //Humans like to count from 1, but computers like 0 better.    
  203.            
  204.             //llGiveInventory(current_user, llList2String(inventory_list, get_item));
  205.            
  206.             if(animating == TRUE)
  207.             {
  208.                llStopAnimation(current_anim);
  209.                animating = FALSE;
  210.             }
  211.            
  212.             llStopAnimation("sit");
  213.             llStartAnimation(llList2String(inventory_list, get_item));
  214.             current_anim = llList2String(inventory_list, get_item);
  215.             animating = TRUE;
  216.            
  217.             using = FALSE;
  218.             current_user = NULL_KEY;
  219.             menu_page = 0;
  220.            
  221.         }
  222.     }
  223.            
  224.                
  225.     timer()
  226.     {
  227.         llSetTimerEvent(0);
  228.         llListenRemove(handle);
  229.         llDialog(current_user, "I'm sorry time has expired to make a menu choice." , ["OK"], 1181111811);
  230.         using= FALSE;
  231.         current_user = NULL_KEY;
  232.         menu_page = 0;
  233.     }
  234.    
  235.     changed(integer change)
  236.     {
  237.              if(change & CHANGED_LINK) // will be triggered if sat upon
  238.         {
  239.          
  240.             key avatar = llAvatarOnSitTarget();
  241.                
  242.            
  243.             if(avatar != NULL_KEY) //We have an avatar sitting
  244.             {
  245.                        
  246.                 llRequestPermissions(avatar,PERMISSION_TRIGGER_ANIMATION);
  247.                                
  248.                 llStopAnimation("Sit");
  249.                 current_anim = llGetInventoryName(INVENTORY_ANIMATION, 0);
  250.                 llStartAnimation(current_anim);
  251.                 animating = TRUE;
  252.                
  253.                
  254.             }
  255.            
  256.             else //probably just stood up
  257.             {
  258.                
  259.                 if(animating == TRUE)
  260.                 {
  261.                     llStopAnimation(current_anim);
  262.                     animating = FALSE;
  263.                     llSetTimerEvent(0);
  264.                 }
  265.                
  266.                 llSetAlpha(1.0, ALL_SIDES);
  267.             }
  268.                  
  269.         }    
  270.            
  271.         if(change & CHANGED_INVENTORY)
  272.         {
  273.             llResetScript();
  274.         }  
  275.        
  276.        
  277.     }
  278. }
  279.  

Reply to "ZenMondo's Modeling Stand"

Here you can reply to the paste above

captcha