Guest User

Untitled

a guest
Apr 18th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ~menu
  2.  
  3. //MLP MULTI-LOVE-POSE V1.2 - Copyright (c) 2006, by Miffy Fluffy (BSD License)
  4. integer PINK1 = 1;  //0001 binary
  5. integer BLUE1 = 2;  //0010 binary
  6. integer PINK2 = 4;  //0100 binary
  7. integer BLUE2 = 8;  //1000 binary
  8. integer a;
  9. integer alive;
  10. integer b;
  11. integer b0;
  12. integer ballusers;
  13. integer c;
  14. integer ch;
  15. integer chat = 1;
  16. integer group;
  17. integer hear;
  18. integer i;
  19. integer line;
  20. integer menu;
  21. integer menuusers;
  22. integer redo = 1;
  23. integer rez;
  24. integer swap;
  25. integer visible;
  26. float alpha;
  27. string cmd;
  28. string pose;
  29. string pose0;
  30. key owner;
  31. key user;
  32. key user0;
  33. list buttons;
  34. list buttonindex;
  35. list commands;
  36. list menus;
  37. list balls;
  38. list users;
  39.  
  40. //menu partly based on Menu Engine by Zonax Delorean (BSD License)
  41. //llDialog(user, menuname, buttons(from index to nextindex-1), channel)  
  42. doMenu() {
  43.     b0 = llList2Integer(buttonindex, menu);         //position of first button for this (sub)menu
  44.     b = llList2Integer(buttonindex, menu+1);        //position of first button for next (sub)menu
  45.     llDialog(user, llList2String(menus,menu), llList2List(buttons, b0, b - 1), ch - 1);
  46.     c = llList2Integer(balls,menu);         //ballcolors
  47.     if (c) {                                //if submenu includes ballcolor(s):
  48.         if (!rez) rezBalls();               //if no balls present: create balls
  49.         llSay(ch,(string)(c & 3));          //ball1color: mask with 3 = 0011 binary
  50.         llSay(ch+1,(string)(c >> 2));       //ball2color: shift 2 bits to the right
  51.         if (ballusers) setBalls("GROUP");   //if group access only
  52.     }
  53.     llResetTime();
  54.     //if (user != llGetOwner()) llOwnerSay("("+llKey2Name(user)+" selects "+llList2String(menus,menu)+")");     //owner will receive info
  55. }
  56. say(string str) {
  57.     if (menuusers) llWhisper(0,str);
  58.     else llOwnerSay(str);
  59. }
  60. setBalls(string cmd) {
  61.     llSay(ch,cmd);      //msg to balls
  62.     llSay(ch+1,cmd);
  63. }
  64. rezBalls() {
  65.     setBalls("DIE");
  66.     llRezObject("~ball",llGetPos(),ZERO_VECTOR,ZERO_ROTATION,ch);
  67.     llRezObject("~ball",llGetPos(),ZERO_VECTOR,ZERO_ROTATION,ch+1);
  68.     llMessageLinked(LINK_THIS,0,"REPOS",NULL_KEY);  //msg to pos
  69.     llMessageLinked(LINK_THIS,0,"POSE","0");        //msg to pos/pose
  70.     rez = 1;
  71.     alive = 2;
  72.     pose = pose0;
  73.     llSetTimerEvent(60);
  74.     if (chat) say("Balls ready");
  75. }
  76.  
  77. default {
  78.     state_entry() {
  79.         //llSetScriptState("~run", TRUE);
  80.         llResetOtherScript("~pos");
  81.         llResetOtherScript("~pose");
  82.         llResetOtherScript("~pose1");
  83.         llResetOtherScript("~pose2");
  84.         ch = (integer)("0x"+llGetSubString((string)llGetKey(),-4,-1));  //fixed channel for prim
  85.         setBalls("DIE");
  86.         alpha = llGetAlpha(0);                                          //store object transparancy (alpha)
  87.         if (alpha < 0.1) alpha = 0.5; else visible = 1;                 //if invisible store a visible alpha
  88.         llMessageLinked(LINK_THIS,1,"OK?",NULL_KEY);                    //msg to memory: ask if ready
  89.     }
  90.     link_message(integer from, integer num, string str, key id) {
  91.         if (num == 2) {
  92.             if (str == "OK") state load;                                //memory ready
  93.         }
  94.     }
  95. }          
  96. state load {
  97.     state_entry() {
  98.         llGetNotecardLine(".MENUITEMS",0);                              //read first line of menuitems notecard
  99.     }
  100.     dataserver(key query_id, string data) {                                
  101.         if (data == EOF) state on;
  102.         i = llSubStringIndex(data,"//");                                //remove comments
  103.         if (i != -1) {
  104.             if (i == 0) data = "";
  105.             else data = llGetSubString(data, 0, i - 1);
  106.         }
  107.         while (llGetSubString(data, -1, -1) == " ") data = llDeleteSubString(data, -1, -1); //remove spaces from end
  108.         if (data != "") {
  109.             i = llSubStringIndex(data," ");
  110.             cmd = data;                      
  111.             if (i != -1) {                                              //split command from data
  112.                 cmd = llGetSubString(data, 0, i - 1);
  113.                 data = llGetSubString(data, i+1, -1);
  114.             }
  115.             list ldata = llParseString2List(data,["  |  ","  | "," |  "," | "," |","| ","|"],[]);
  116.             data = llList2String(ldata, 0);
  117.             if (cmd == "MENU") {
  118.                 if (a < 2) {
  119.                     llOwnerSay("warning: first item in .MENUITEMS must be: POSE stand");
  120.                     llOwnerSay("warning: second item in .MENUITEMS must be: POSE default");
  121.                 }
  122.                 llOwnerSay("loading data for '"+data+"'");            
  123.                 if (llList2String(ldata, 1) == "GROUP") menu = 1;       //access to submenus
  124.                 else if (llList2String(ldata, 1) != "OWNER") menu = 2;  //0=owner 1=group 2=all
  125.                 pose = llList2String(ldata, 2);
  126.                 if (pose == "PINK") rez = PINK1;
  127.                 else if (pose == "BLUE") rez = BLUE1;
  128.                 pose = llList2String(ldata, 3);
  129.                 if (pose == "PINK") rez += PINK2;
  130.                 else if (pose == "BLUE") rez += BLUE2;
  131.                 menus += [ data ];
  132.                 balls += [ rez ];
  133.                 buttonindex += [ b ];
  134.                 users += [ menu ];
  135.                 rez = 0;
  136.                 b0 = 0;
  137.                 menu = 0;
  138.             } else if (b0 < 12) {                                       //maximum 12 buttons per menu
  139.                 if (cmd == "POSE") {
  140.                     llMessageLinked(LINK_THIS,1,data,(string)a);        //msg to memory
  141.                     llMessageLinked(LINK_THIS,9+a,llList2String(ldata, 1),llList2String(ldata, 2));  //msg to pose
  142.                     if (!a) pose0 = data;
  143.                     cmd = (string)a;
  144.                     ++a;
  145.                 } else if (cmd == "REDO") {
  146.                     if (llList2String(ldata, 1) != "OFF") redo = 1;
  147.                 } else if (cmd == "CHAT") {
  148.                     if (llList2String(ldata, 1) != "OFF") chat = 1;
  149.                 } else if (cmd == "BALLUSERS") {
  150.                     if (llList2String(ldata, 1) == "GROUP") ballusers = 1;
  151.                 } else if (cmd == "MENUUSERS") {
  152.                     if (llList2String(ldata, 1) == "GROUP") menuusers = 1;
  153.                     else if (llList2String(ldata, 1) != "OWNER") menuusers = 2;
  154.                 }  
  155.                 commands += [ cmd ];
  156.                 buttons += [ data ];
  157.                 ++b;
  158.                 ++b0;
  159.             }
  160.         }
  161.         ++line;
  162.         llGetNotecardLine(".MENUITEMS",line);                           //read next line of menuitems notecard
  163.     }
  164.     state_exit() {
  165.         buttonindex += [ b ];                                           //enter last buttonindex
  166.         commands += [ "" ];                                             //empty command for undefined buttons (-1)
  167.         llOwnerSay("READY");
  168.         llOwnerSay((string)b+" menuitems loaded ("+llGetScriptName()+": "+(string)llGetFreeMemory()+" bytes free)");
  169.         llMessageLinked(LINK_THIS,1,"LOADED",(string)a);                //msg to memory
  170.         llMessageLinked(LINK_THIS,9+a,"LOADED",NULL_KEY);               //msg to pose
  171.     }
  172. }
  173. state on {
  174.     state_entry() {
  175.         owner = llGetOwner();
  176.         llSetTimerEvent(0);
  177.         llListenRemove(hear);
  178.         hear = llListen(ch - 1, "", NULL_KEY, "");                      //listen for pressed buttons
  179.     }
  180.     touch_start(integer i) {
  181.         user0 = llDetectedKey(0);
  182.         if (user0 == owner || (menuusers == 1 && llDetectedGroup(0)) || menuusers == 2) {   //0=owner 1=group 2=all
  183.             if (user0 != user) {
  184.                 if (llGetTime() < 60) {
  185.                     llDialog(user0, "\n"+llKey2Name(user)+" has just selected the menu, do you want to continue?", ["Yes","Cancel"], ch - 1);
  186.                     return;
  187.                 }
  188.                 user = user0;
  189.                 group = llDetectedGroup(0);
  190.             }
  191.             menu = 0; doMenu();                                         //mainmenu
  192.         }                
  193.     }
  194.    
  195.     listen(integer channel, string name, key user0, string button) {
  196.         if (user0 != user) {
  197.             if (button == "Yes") {
  198.                 user = user0;
  199.                 group = llSameGroup(user0);
  200.                 menu = 0; doMenu();
  201.             } else if (button != "Cancel") {
  202.                 llDialog(user0, "\nSelection cancelled because "+llKey2Name(user)+" has just selected the menu, do you want to operate the menu again?", ["Yes","Cancel"], ch - 1);
  203.             }
  204.             return;
  205.         }
  206.         b = llListFindList(buttons,[ button ]);                         //find position of cmd
  207.         string cmd = llList2String(commands,b);                         //get command
  208.         //llSay(0,button+" "+cmd);                                      //debug
  209.         if (cmd == "TOMENU") {                                            
  210.             menu = llListFindList(menus,[ button ]);                    //find submenu
  211.             if (menu == -1) return;
  212.             i = llList2Integer(users, menu);
  213.             if (user == owner || (i == 1 && group) || i == 2) {         //0=owner 1=group 2=all
  214.                 doMenu(); return;
  215.             }
  216.             if (i == 1) llDialog(user0, "\n"+button+" menu deactivated\n(access by group only)", ["OK"], ch - 1);
  217.             else llDialog(user0, "\n"+button+" menu deactivated\n(access by owner only)", ["OK"], ch - 1);
  218.             menu = 0;
  219.             return;
  220.         } else if (cmd == "BACK") {
  221.             menu = 0; doMenu();                                         //mainmenu
  222.             return;
  223.         } else if ((integer)cmd > 0) {                                  //POSE
  224.             llMessageLinked(LINK_THIS,0,"POSE",cmd);                    //msg to pos/pose
  225.             if (chat) say(button);
  226.             pose = button;
  227.         } else if (cmd == "SWAP") {
  228.             llMessageLinked(LINK_THIS,0,"SWAP",NULL_KEY);               //msg to pos/pose
  229.             swap = !swap;
  230.         } else if (cmd == "STAND") {
  231.             llMessageLinked(LINK_THIS,0,"POSE","0");                    //STAND msg to pos/pose
  232.             if (chat) say(button);
  233.             menu = 0;
  234.             pose = pose0;
  235.         } else if (cmd == "STOP") {
  236.             llMessageLinked(LINK_THIS,0,"POSE","0");                    //STAND msg to pos/pose
  237.             if (chat) say(button);
  238.             setBalls("DIE");
  239.             if (chat && rez) say("Balls removed");
  240.             rez = 0;
  241.             llSetTimerEvent(0);
  242.             return;
  243.         } else if (cmd == "ADJUST") {
  244.             setBalls("ADJUST");
  245.         } else if (cmd == "HIDE") {
  246.             setBalls("0");
  247.         } else if (cmd == "SHOW") {
  248.             setBalls("SHOW");
  249.         } else if (cmd == "DUMP") {
  250.             llMessageLinked(LINK_THIS,1,"DUMP",NULL_KEY);
  251.         } else if (cmd == "INVISIBLE") {
  252.             visible = !visible;
  253.             llSetAlpha((float)visible*alpha, ALL_SIDES);
  254.         } else if (cmd == "REDO") {
  255.             redo = !redo;
  256.             if (redo) say(button+" ON"); else say(button+" OFF");
  257.         } else if (cmd == "CHAT") {
  258.             chat = !chat;
  259.             if (chat) say(button+" ON"); else say(button+" OFF");
  260.         } else if (cmd == "BALLUSERS") {
  261.             ballusers = !ballusers;
  262.             if (ballusers) {
  263.                 llOwnerSay(button+" GROUP");
  264.                 setBalls("GROUP");
  265.             } else {    
  266.                 llOwnerSay(button+" ALL");
  267.                 setBalls("ALL");
  268.             }
  269.         } else if (cmd == "MENUUSERS") {
  270.             if (user == owner) {
  271.                 if (!menuusers) {
  272.                     menuusers = 1;
  273.                     llOwnerSay(button+" GROUP");
  274.                 } else if (menuusers == 1) {
  275.                     menuusers = 2;
  276.                     llOwnerSay(button+" ALL");
  277.                 } else if (menuusers == 2) {
  278.                     menuusers = 0;
  279.                     llOwnerSay(button+" OWNER");
  280.                 }
  281.             } else llWhisper(0,button+" (can be switched by owner only)");
  282.         } else if (cmd == "RESET") {
  283.             llMessageLinked(LINK_THIS,0,"POSE","0");                    //STAND msg to pos/pose
  284.             setBalls("DIE");
  285.             //llSleep(0.5);        
  286.             if (chat) say(button);
  287.             llResetScript();
  288.         } else if (cmd == "OFF") {
  289.             llMessageLinked(LINK_THIS,0,"POSE","0");                    //STAND msg to pos/pose
  290.             setBalls("DIE");
  291.             //llSleep(0.5);
  292.             if (user == owner) {
  293.                 llOwnerSay(button);
  294.                 llResetOtherScript("~run");
  295.                 llResetScript();
  296.             }
  297.             llDialog(user0, "\n"+button+" button deactivated\n(access by owner only)", ["OK"], -1);
  298.             return;
  299.         } else if (llGetSubString(cmd, 0, 0) == "Z" || (cmd == "SAVE")) {    //SAVE //Z-adjust
  300.             llMessageLinked(LINK_THIS,0,cmd,pose);                      //msg to pos/pose
  301.             doMenu();
  302.             return;
  303.         }
  304.         if (redo) doMenu();
  305.     }
  306.    
  307.    
  308.     link_message(integer from, integer num, string str, key id) {
  309.       if (str == "PRIMTOUCH") {
  310.         user0 = id ;
  311.         integer detected_group = num;    
  312.         if (user0 == owner || (menuusers == 1 && detected_group) || menuusers == 2) {   //0=owner 1=group 2=all
  313.             if (user0 != user) {
  314.                 if (llGetTime() < 60) {
  315.                     llDialog(user0, "\n"+llKey2Name(user)+" has just selected the menu, do you want to continue?", ["Yes","Cancel"], ch - 1);
  316.                     return;
  317.                 }
  318.                 user = user0;
  319.                 group = llDetectedGroup(0);
  320.             }
  321.             menu = 0; doMenu();                                         //mainmenu
  322.         }                
  323.              return;
  324.       }
  325.      
  326.         if (num != 2) return;
  327.         if (str == "ALIVE") {
  328.             ++alive;
  329.         } else if (str == "DIE") {                                      //suicide msg from ball
  330.             setBalls("DIE");
  331.             menu = 0;
  332.             rez = 0;
  333.             llSetTimerEvent(0);
  334.         }
  335.     }
  336.     on_rez(integer r) {
  337.         if (owner != llGetOwner()) llResetScript();
  338.     }
  339.     timer() {
  340.         if (alive > 1) {    
  341.             alive = 0;
  342.             llSay(ch,"LIVE");           //msg to balls: stay alive
  343.             llSay(ch+1,"LIVE");
  344.         } else {                        //balls not rezzed properly anymore
  345.             rezBalls();
  346.             llSay(ch,(string)(c & 3));          //ball1color: mask with 3 = 0011 binary
  347.             llSay(ch+1,(string)(c >> 2));       //ball2color: shift 2 bits to the right
  348.             if (ballusers) setBalls("GROUP");   //if group access only
  349.         }
  350.     }
  351. }
Add Comment
Please, Sign In to add comment