Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LScript 15.07 KB | None | 0 0
  1.  
  2. integer DefaultPRIMCHAN = -192567;     // Default channel to use
  3. integer PRIMCHAN = DefaultPRIMCHAN;    // Channel used by Base Prim to talk to Component Prims;
  4.                                        // ***THIS MUST MATCH IN BOTH SCRIPTS!***
  5.  
  6. //The UUID of the creator of the object
  7. //Leave this as "" unless SL displays wrong name in object properties
  8. key creatorUUID = "";
  9.  
  10. // Set to TRUE to allow group members to use the dialog menu
  11. // Set to FALSE to disallow group members from using the dialog menu
  12. integer ingroup = TRUE;
  13.  
  14. // Set to TRUE to delete piece from inventory when rezzed
  15. // (WARNING) If set to FALSE, user will be able to rez multiple copies
  16. integer deleteOnRez = FALSE;
  17.  
  18. // Allow non-creator to use CLEAN command?
  19. // (WARNING) If set to TRUE, it is recommended to set
  20. // deleteOnRez to FALSE, or user could lose entire building
  21. integer allowClean = TRUE;
  22.  
  23. //When user selects CLEAN, delete the base prim too?
  24. integer dieOnClean = FALSE;
  25.  
  26. // Set to TRUE to record piece's location based on sim
  27. // coordinates instead of relationship to base prim
  28. integer recordSimLocation = FALSE;
  29.  
  30. // Set to TRUE to rez all building pieces before positioning,
  31. // or FALSE to do (slower?) one at a time
  32. integer bulkBuild = TRUE;
  33.  
  34. //Set to FALSE if you dont want the script to say anything while 'working'
  35. integer chatty = TRUE;
  36.  
  37. //How long to listen for a menu response before shutting down the listener
  38. float fListenTime = 30.0;
  39.  
  40. //How often (in seconds) to perform any timed checks
  41. float fTimerRate = 0.25;
  42.  
  43. //How long to sit still before exiting active mode
  44. float fStoppedTime = 30.0;
  45.  
  46. //SL sometimes blocks rezzing to prevent "gray goo" attacks
  47. //How long we wait (seconds) before we assume SL blocked our rez attempt
  48. integer iRezWait = 10;
  49.  
  50. //Specify which Menu Options will be displayed
  51. //FALSE will restrict full options to creator
  52. //TRUE will offer full options to anyone
  53. integer fullOptions = FALSE;
  54.  
  55. //Set to TRUE if you want ShapeGen channel support
  56. // (Last 4 digits of channel affected)
  57. integer SGCompatible = FALSE;
  58.  
  59.  
  60. ///////////////////////////////////////////////////////////////////////////////
  61. //Part of KEYPAD CODE BY Andromeda Quonset....More added below in seevral places
  62. list Menu2 = [ "-", "0","enter","7","8","9","4","5","6","1","2","3"];
  63. string Input = "";
  64. string Sign = "+";
  65. string SignInput = " ";
  66. string Caption = "Enter a number, include any leading 0's: ";
  67.  
  68. ///////////////////////////////////////////////////////////////////////////////
  69. // DO NOT EDIT BELOW THIS LINE.... NO.. NOT EVEN THEN
  70. ///////////////////////////////////////////////////////////////////////////////
  71.  
  72. //Name each option-these names will be your button names.
  73. string optRecord = "Record";
  74. string optReset = "Reset";
  75. string optBuild = "Build";
  76. string optPos = "Position";
  77. string optClean = "Clean";
  78. string optDone = "Done";
  79. string optChannel = "Channel";
  80.  
  81. //Menu option descriptions
  82. string descRecord = ": Record the position of all parts\n";
  83. string descReset = ": Forgets the position of all parts\n";
  84. string descBuild = ": Rez inv. items and position them\n";
  85. string descPos = ": Reposition the parts to a new location\n";
  86. string descClean = ": De-Rez all pieces\n";
  87. string descDone = ": Remove all BB scripts and freeze parts in place.\n";
  88. string descChannel = ": Change Channel used on base and parts.\n";
  89.  
  90. integer MENU_CHANNEL;
  91. integer MENU2_CHANNEL;
  92. integer MENU_HANDLE;
  93. integer MENU2_HANDLE;
  94. key agent;
  95. key objectowner;
  96. integer group;
  97. string title = "";
  98. list optionlist = [];
  99. integer bMoving;
  100. vector vLastPos;
  101. rotation rLastRot;
  102. integer bRezzing;
  103. integer iListenTimeout = 0;
  104. integer iLastRez = 0;
  105. integer iRezIndex;
  106.  
  107.  
  108. InvertSign()
  109. {
  110.     if(Sign == "+")
  111.         Sign = "-";
  112.     else
  113.         Sign = "+";
  114. }
  115.  
  116. //To avoid flooding the sim with a high rate of movements
  117. //(and the resulting mass updates it will bring), we used
  118. // a short throttle to limit ourselves
  119. announce_moved()
  120. {
  121.     llRegionSay(PRIMCHAN, "MOVE " + llDumpList2String([ llGetPos(), llGetRot() ], "|"));
  122.     llResetTime();        //Reset our throttle
  123.     vLastPos = llGetPos();
  124.     rLastRot = llGetRot();
  125.     return;
  126. }
  127.  
  128.  
  129. rez_object()
  130. {
  131.     //Rez the object indicated by iRezIndex
  132.     llRezObject(llGetInventoryName(INVENTORY_OBJECT, iRezIndex), llGetPos(), ZERO_VECTOR, llGetRot(), PRIMCHAN);
  133.     iLastRez = llGetUnixTime();
  134.  
  135.     if(!bRezzing) {
  136.         bRezzing = TRUE;
  137.         //timer_on();
  138.     }
  139. }
  140.  
  141. post_rez_object()
  142. {
  143.     if ( creatorUUID != llGetOwner() ) {
  144.         if(deleteOnRez) llRemoveInventory(llGetInventoryName(INVENTORY_OBJECT, iRezIndex));
  145.     }
  146. }
  147.  
  148. heard(integer channel, string name, key id, string message)
  149. {
  150.     if( channel == PRIMCHAN ) {
  151.         if( message == "READYTOPOS" ) {
  152.             //New prim ready to be positioned
  153.             vector vThisPos = llGetPos();
  154.             rotation rThisRot = llGetRot();
  155.             llRegionSay(PRIMCHAN, "MOVESINGLE " + llDumpList2String([ vThisPos, rThisRot ], "|"));
  156.  
  157.         } else if( message == "ATDEST" ) {
  158.             //Rez the next in the sequence (if any)
  159.             iRezIndex--;
  160.             if(iRezIndex >= 0) {
  161.                 //Attempt to rez it
  162.                 rez_object();
  163.             } else {
  164.                 //We are done building, reset our listeners
  165.                 iLastRez = 0;
  166.                 bRezzing = FALSE;
  167.                 state reset_listeners;
  168.             }
  169.         }
  170.         return;
  171.  
  172.     } else if( channel == MENU_CHANNEL ) {   //Process input from original menu
  173.         if ( message == optRecord ) {
  174.             PRIMCHAN = DefaultPRIMCHAN;
  175.             llOwnerSay("Recording positions...");
  176.             if(recordSimLocation) {
  177.                 //Location in sim
  178.                 llRegionSay(PRIMCHAN, "RECORDABS " + llDumpList2String([ llGetPos(), llGetRot() ], "|"));
  179.             } else {
  180.                 //Location relative to base
  181.                 llRegionSay(PRIMCHAN, "RECORD " + llDumpList2String([ llGetPos(), llGetRot() ], "|"));
  182.             }
  183.             return;
  184.         }
  185.         if( message == optReset ) {
  186.             llOwnerSay("Forgetting positions...");
  187.             llShout(PRIMCHAN, "RESET");
  188.             return;
  189.         }
  190.         if ( message == optBuild ) {
  191.             if(chatty) llOwnerSay("Rezzing build pieces...");
  192.  
  193.             //If rezzing/positioning one at a time, we need
  194.             // to listen for when they've reached their dest
  195.             if(!bulkBuild) {
  196.                 llListen(PRIMCHAN, "", NULL_KEY, "READYTOPOS");
  197.                 llListen(PRIMCHAN, "", NULL_KEY, "ATDEST");
  198.             }
  199.  
  200.             //Start rezzing, last piece first
  201.             iRezIndex = llGetInventoryNumber(INVENTORY_OBJECT) - 1;
  202.             rez_object();
  203.             return;
  204.         }
  205.         if ( message == optPos ) {
  206.             if(chatty) llOwnerSay("Positioning");
  207.             vector vThisPos = llGetPos();
  208.             rotation rThisRot = llGetRot();
  209.             llRegionSay(PRIMCHAN, "MOVE " + llDumpList2String([ vThisPos, rThisRot ], "|"));
  210.             return;
  211.         }
  212.         if ( message == optClean ) {
  213.             llRegionSay(PRIMCHAN, "CLEAN");
  214.             if(dieOnClean) llDie();
  215.             return;
  216.         }
  217.         if ( message == optDone ) {
  218.             llRegionSay(PRIMCHAN, "DONE");
  219.             if(chatty) llOwnerSay("Removing Builder's Buddy scripts.");
  220.             return;
  221.         }
  222.         if ( message == optChannel ) {
  223.             Sign = "+"; //default is a positive number
  224.             Input = "";
  225.             llDialog( agent, Caption, Menu2, MENU2_CHANNEL );
  226.         }
  227.  
  228.     } else if ( channel == MENU2_CHANNEL ) {    //process input from MENU2
  229.         // if a valid choice was made, implement that choice if possible.
  230.         // (llListFindList returns -1 if Choice is not in the menu list.)
  231.         if ( llListFindList( Menu2, [ message ]) != -1 ) {
  232.             if( llListFindList(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], [message]) != -1) {
  233.                 Input += message;
  234.                 SignInput = Sign + Input;
  235.                 llDialog( agent, Caption + SignInput, Menu2, MENU2_CHANNEL );
  236.  
  237.             } else if( message == "-" ) {
  238.                 InvertSign();
  239.                 SignInput = Sign + Input;
  240.                 llDialog( agent, Caption + SignInput, Menu2, MENU2_CHANNEL );
  241.  
  242.             } else if( message == "enter" ) {     //terminate input from menu2
  243.                 string CalcChan = Input;
  244.  
  245.                 //Apply ShapeGen compatibility?
  246.                 if(SGCompatible) {
  247.                     //new assign channel number, forcing last 4 digits to 0000
  248.                     integer ChanSize = llStringLength(Input); //determine number of digits (chars)
  249.                     if(ChanSize > 5) {
  250.                         CalcChan = llGetSubString(Input, 0, 4);    //Shorten to 5 digits
  251.                     }
  252.                     CalcChan += "0000"; //append 0000
  253.                     if(Sign == "-")
  254.                         CalcChan = Sign + CalcChan;
  255.                 }
  256.                 PRIMCHAN = (integer)CalcChan; //assign channel number
  257.                 llOwnerSay("Channel set to " + (string)PRIMCHAN + ".");
  258.             }
  259.  
  260.         } else {
  261.             llDialog( agent, Caption, Menu2, MENU2_CHANNEL );
  262.         }
  263.     }
  264. }
  265.  
  266.  
  267. ///////////////////////////////////////////////////////////////////////////////
  268. ///////////////////////////////////////////////////////////////////////////////
  269. ///////////////////////////////////////////////////////////////////////////////
  270. default {
  271.     ///////////////////////////////////////////////////////////////////////////////
  272.     changed(integer change) {
  273.         if(change & CHANGED_OWNER)
  274.         llResetScript();
  275.     }
  276.  
  277.     ///////////////////////////////////////////////////////////////////////////////
  278.     state_entry () {
  279.         //Determine the creator UUID
  280.         if(creatorUUID == "") creatorUUID = llGetCreator();
  281.  
  282.         //Use which menu?
  283.         if (creatorUUID == llGetOwner() || fullOptions) {
  284.             //Display all options
  285.             optionlist = [optPos, optClean, optDone, optRecord, optReset, optBuild, optChannel];
  286.             title = optRecord + descRecord;
  287.             title += optReset + descReset;
  288.             title += optBuild + descBuild;
  289.             title += optPos + descPos;
  290.             title += optClean + descClean;
  291.             title += optDone + descDone;
  292.             title += optChannel + descChannel;
  293.  
  294.         } else {
  295.             //Display limited options
  296.             if(allowClean) {
  297.                 optionlist = [optBuild, optPos, optClean, optDone];
  298.                 title = optBuild + descBuild;
  299.                 title += optPos + descPos;
  300.                 title += optClean + descClean;
  301.                 title += optDone + descDone;
  302.             } else {
  303.                 optionlist = [optBuild, optPos, optDone];
  304.                 title = optBuild + descBuild;
  305.                 title += optPos + descPos;
  306.                 title += optDone + descDone;
  307.             }
  308.         }
  309.  
  310.         //Record our position
  311.         vLastPos = llGetPos();
  312.         rLastRot = llGetRot();
  313.  
  314.         llSetTimerEvent(fTimerRate);
  315.     }
  316.  
  317.     ///////////////////////////////////////////////////////////////////////////////
  318.     touch_start (integer total_number) {
  319.         group = llDetectedGroup(0); // Is the Agent in the objowners group?
  320.         agent = llDetectedKey(0); // Agent's key
  321.         objectowner = llGetOwner(); // objowners key
  322.         // is the Agent = the owner OR is the agent in the owners group
  323.         if ( (objectowner == agent) || ( group && ingroup )  )  {
  324.             iListenTimeout = llGetUnixTime() + llFloor(fListenTime);
  325.             MENU_CHANNEL = llFloor(llFrand(-99999.0 - -100));
  326.             MENU2_CHANNEL = MENU_CHANNEL + 1;
  327.             MENU_HANDLE = llListen(MENU_CHANNEL,"","","");
  328.             MENU2_HANDLE = llListen(MENU2_CHANNEL,"","","");
  329.             if ( creatorUUID == llGetOwner() || fullOptions) {
  330.                 llDialog(agent,title + "Now on Channel " + (string)PRIMCHAN, optionlist, MENU_CHANNEL); //display channel number if authorized
  331.             } else {
  332.                 llDialog(agent, title, optionlist, MENU_CHANNEL);
  333.             }
  334.             //timer_on();
  335.         }
  336.     }
  337.  
  338.     ///////////////////////////////////////////////////////////////////////////////
  339.     listen(integer channel, string name, key id, string message) {
  340.         heard(channel, name, id, message);
  341.         return;
  342.     }
  343.  
  344.     ///////////////////////////////////////////////////////////////////////////////
  345.     moving_start()
  346.     {
  347.         if( !bMoving )
  348.         {
  349.             bMoving = TRUE;
  350.             //timer_on();
  351.             announce_moved();
  352.         }
  353.     }
  354.  
  355.     ///////////////////////////////////////////////////////////////////////////////
  356.     object_rez(key id) {
  357.         //The object rezzed, perform any post-rez processing
  358.         post_rez_object();
  359.  
  360.         //Rezzing it all before moving?
  361.         if(bulkBuild) {
  362.             //Move on to the next object
  363.             //Loop through backwards (safety precaution in case of inventory change)
  364.             iRezIndex--;
  365.             if(iRezIndex >= 0) {
  366.                 //Attempt to rez it
  367.                 rez_object();
  368.  
  369.             } else {
  370.                 //Rezzing complete, now positioning
  371.                 iLastRez = 0;
  372.                 bRezzing = FALSE;
  373.                 if(chatty) llOwnerSay("Positioning");
  374.                 llRegionSay(PRIMCHAN, "MOVE " + llDumpList2String([ llGetPos(), llGetRot() ], "|"));
  375.             }
  376.         }
  377.     }
  378.  
  379.     ///////////////////////////////////////////////////////////////////////////////
  380.     timer() {
  381.         //Did we change position/rotation?
  382.         if( (llGetRot() != rLastRot) || (llGetPos() != vLastPos) )
  383.         {
  384.             if( llGetTime() > fTimerRate ) {
  385.                 announce_moved();
  386.             }
  387.         }
  388.  
  389.         //Are we rezzing?
  390.         if(bRezzing) {
  391.             //Did the last one take too long?
  392.             if((llGetUnixTime() - iLastRez) >= iRezWait) {
  393.                 //Yes, retry it
  394.                 if(chatty) llOwnerSay("Reattempting rez of most recent piece");
  395.                 rez_object();
  396.             }
  397.         }
  398.  
  399.         //Open listener?
  400.         if( iListenTimeout != 0 )
  401.         {
  402.             //Past our close timeout?
  403.             if( iListenTimeout <= llGetUnixTime() )
  404.             {
  405.                 iListenTimeout = 0;
  406.                 llListenRemove(MENU_HANDLE);
  407.             }
  408.         }
  409.     }
  410.  
  411.     ///////////////////////////////////////////////////////////////////////////////
  412.     on_rez(integer iStart)
  413.     {
  414.         //Reset ourselves
  415.         llResetScript();
  416.     }
  417. }
  418.  
  419.  
  420. //////////////////////////////////////////////////////////////////////////////////////////
  421. //////////////////////////////////////////////////////////////////////////////////////////
  422. //////////////////////////////////////////////////////////////////////////////////////////
  423. state reset_listeners
  424. {
  425.     //////////////////////////////////////////////////////////////////////////////////////////
  426.     state_entry()
  427.     {
  428.         state default;
  429.     }
  430. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement