Punkysnippets

From Second Life Wiki
Jump to navigation Jump to search

Basic Scripts!


Below are some small example scripts and misc useful codes for inserts! Some of them are extremely simple, others may not be so simple, but they are intended to help those who need it. :)


Simple leashing script

This is mearly an example for a leash, you will need to change the on/off to fit your need, the length and etc. <lsl> string texturename = "08d5770f-d3c4-7d4a-5a2b-2a1c126643d9"; string nullstr = ""; key nullkey = NULL_KEY; key posekey = nullkey; float age = 3; float gravity = 1.0; key currenttarget = nullkey; string ourtarget = nullstr; integer line; key loadkey; UpdateParticles(key leashtarget) {

   currenttarget = leashtarget;
   llParticleSystem( [
   PSYS_PART_START_SCALE,(vector) <0.075,0.075,0>,
   PSYS_PART_END_SCALE,(vector) <1,1,0>,
   PSYS_PART_START_COLOR,(vector) <1,1,1>,
   PSYS_PART_END_COLOR,(vector) <1,1,1>,
   PSYS_PART_START_ALPHA,(float) 1.0,
   PSYS_PART_END_ALPHA,(float) 1.0,
   PSYS_SRC_TEXTURE,(string) texturename,
   PSYS_SRC_BURST_PART_COUNT,(integer) 1,
   PSYS_SRC_BURST_RATE,(float) 0.0,
   PSYS_PART_MAX_AGE,(float) age,
   PSYS_SRC_MAX_AGE,(float) 0.0,
   PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP,
   PSYS_SRC_BURST_RADIUS,(float) 0.5,
   PSYS_SRC_INNERANGLE,(float) 0.0,
   PSYS_SRC_OUTERANGLE,(float) 0.0,
   PSYS_SRC_OMEGA,(vector) <0,0,0>,
   PSYS_SRC_ACCEL,(vector) <0,0,-gravity>,
   PSYS_SRC_BURST_SPEED_MIN,(float) 1000.0,
   PSYS_SRC_BURST_SPEED_MAX,(float) 1000.0,
   PSYS_SRC_TARGET_KEY,(key) leashtarget,
   PSYS_PART_FLAGS,
    PSYS_PART_FOLLOW_VELOCITY_MASK |
    PSYS_PART_FOLLOW_SRC_MASK |
    PSYS_PART_TARGET_POS_MASK | 0
   ] );

} integer isKey(key in) {

   if(in) return 2;
   return (in == nullkey);

} ///// /////Leash Vari ///// vector target; vector subpos; float dist; integer leash_length = 2; key ptarget; key owner; string targetN; default {

   on_rez(integer r)
   {
       owner = llGetOwner();
   }
   state_entry()
   {
       llParticleSystem([]);
       owner = llGetOwner();
       llListen(0, "", owner, "");
   }
   listen(integer chan, string name, key id, string msg)
   {
       list parse = llParseString2List(msg, ["|"], []);
       if(llList2String(parse, 0) == "leash")
       {
           llSensorRepeat("", (key)llList2String(parse, 1), AGENT, 96, PI, 0.2);
       }
   }
   sensor(integer s)
   {
       target = llDetectedPos(0);
       ptarget = llDetectedKey(0);
       subpos = llGetPos();
       dist = llVecDist(subpos, target);
       UpdateParticles(ptarget);
       if(dist >= (leash_length + 1))
       {
           llMoveToTarget(target, 0.75);
       }
       if(dist <= leash_length)
       {
           llStopMoveToTarget();
       }
   }
   no_sensor()
   {
       llParticleSystem([]);
       llStopMoveToTarget();
   }

} </lsl>


Simple one-way touch door

This is just a simple, one-way door that you can use to only allow entry from a particular side, and I'm sure there are less complicated ways or more complicated, but this is just something I threw together in a minute or so as an example <lsl> //Written by MissPony Pelous // Rotation detection not added, so use x for the x axis, and y for the y axis // change the >= to either <= or >= based on the side you want :) vector pos; vector dPos; rotation rot; default {

   state_entry()
   {
       pos = llGetPos();
   }
   touch_start(integer total_number)
   {
       dPos = llDetectedPos(0);
       rot = llGetRot();
       if ( dPos.x <= pos.x )
       {
           llSay(0, "You may enter.");
           llSetStatus(STATUS_PHANTOM, TRUE);
           llSetAlpha(0.3, -1);
           llSetColor(<0,1,0>, -1);
           llSetTimerEvent(3);
       }
       else if ( dPos.x >= pos.x )
       {
           llSay(0, "You may not exit from the inside.");
           llSetStatus(STATUS_PHANTOM, FALSE);
       }
   }
   timer()
   {
       llSetStatus(STATUS_PHANTOM, FALSE);
       llSetAlpha(1.0, -1);
       llSetColor(<0,0,0>, -1);
       llSay(0, "Door closed.");
       llSetTimerEvent(0);
   }

} </lsl>


Key generator (not UUID)

This is just a simple example of generating a key to use for things such as a password- door or a unique key (object) :) Use your imagination! <lsl> // Yet another code from the mass inventory of MissPony (Punky :P) // //Globals, no need to modify integer useable; string objKey; list temp; integer list_size = 8; list letters = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; //End Globals //=========== list listgen() {

   temp = [];
   integer i;
   for (i=0; i<8; i++)
   {
       integer index = (integer)llFrand(llGetListLength(letters));
       temp += llList2List(letters, index, index);
   }
   return temp;

} integer key_1() {

   return (integer)llFrand(99999999);

} string key_2() {

   return llToUpper(llDumpList2String(listgen(), ""));

} string key_3() {

   return llToUpper(llDumpList2String(listgen(), ""));

} integer key_4() {

   return (integer)llFrand(99999999);

} string keygen() {

   return objKey = (string)key_1() + "-" + (string)key_2() + "-" + (string)key_3() + "-" + (string)key_4();

} default {

   touch_start(integer t)
   {
       llOwnerSay(keygen());
   }

} </lsl>

Locking door for access list or group access

Here is a simple door script and note card to allow access to any area that you wish. :) <lsl> // Open source owner only, group access, or open mode door by // MissPony Pelous for use by anyone as long as this tag is at // the top and credit is given where credit is due // ---------------- key OWNER; key NOTECARD; string NOTE_NAME; integer NOTE_LINE = 0; integer LOCKED = FALSE; integer GROUP_ONLY = FALSE; list ACCESS = ["MissPony Pelous"]; default {

   on_rez(integer r)
   {
       OWNER = llGetOwner();
       ACCESS = [llKey2Name(llGetOwner())]; // Add the owner to the list by default
       if ( llGetInventoryNumber(INVENTORY_NOTECARD) != 0 ) // Make sure there is a notecard present, if not, do nothing
       {
           NOTE_NAME = llGetInventoryName(INVENTORY_NOTECARD, 0); // Get the first notecard in the inventory
           NOTECARD = llGetNotecardLine(NOTE_NAME, NOTE_LINE);
       }
   }
   state_entry()
   {
       OWNER = llGetOwner();
       ACCESS = [llKey2Name(llGetOwner())]; // Add the owner to the list by default
       llListen(0, "", OWNER, "");
   }
   listen(integer chan, string name, key id, string msg)
   {
       
       if ( llToLower(msg) == "lock" )
       {
           LOCKED = TRUE;
           GROUP_ONLY = FALSE;
           llOwnerSay("Locked to access list only.");
       }
       if ( llToLower(msg) == "unlock" )
       {
           LOCKED = FALSE;
           GROUP_ONLY = FALSE;
           llOwnerSay("Unlocked");
       }
       if ( llToLower(msg) == "grouplock" )
       {
           LOCKED = TRUE;
           GROUP_ONLY = TRUE;
           llOwnerSay("Group access only.");
       }
   }
   changed(integer change)
   {
       if ( change & CHANGED_INVENTORY )
       {
           if ( llGetInventoryNumber(INVENTORY_NOTECARD) != 0 ) // Make sure there is a notecard present when the inventory is changed
           {   
               NOTE_NAME = llGetInventoryName(INVENTORY_NOTECARD, 0); // Get the first notecard in the inventory
               NOTECARD = llGetNotecardLine(NOTE_NAME, NOTE_LINE);
           }
       }
   }
   touch_start(integer total_number)
   {
       if ( LOCKED == TRUE && GROUP_ONLY == TRUE )
       {
           if ( llSameGroup(llDetectedKey(0)) == TRUE )
           {
               llSetLinkAlpha(LINK_THIS, 0.0, ALL_SIDES);
               llSetStatus(STATUS_PHANTOM, TRUE);
               llSleep(4);
               llSetLinkAlpha(LINK_THIS, 1.0, ALL_SIDES);
               llSetStatus(STATUS_PHANTOM, FALSE);
           }
           else
           {
               llWhisper(0, "Sorry but you are not allowed to open this door.");
           }
       }
       else if ( LOCKED == TRUE && GROUP_ONLY == FALSE )
       {
           if ( llListFindList(ACCESS, [llDetectedName(0)]) != -1 )
           {
               llSetLinkAlpha(LINK_THIS, 0.0, ALL_SIDES);
               llSetStatus(STATUS_PHANTOM, TRUE);
               llSleep(4);
               llSetLinkAlpha(LINK_THIS, 1.0, ALL_SIDES);
               llSetStatus(STATUS_PHANTOM, FALSE);
           }
           else
           {
               llWhisper(0, "Sorry but you are not allowed to open this door.");
           }
       }
       else
       {
           llSetLinkAlpha(LINK_THIS, 0.0, ALL_SIDES);
           llSetStatus(STATUS_PHANTOM, TRUE);
           llSleep(4);
           llSetLinkAlpha(LINK_THIS, 1.0, ALL_SIDES);
           llSetStatus(STATUS_PHANTOM, FALSE);
       }
   }
   dataserver(key Qid, string data)
   {
       if ( Qid == NOTECARD )
       {
           if ( data != EOF ) // While not the end of notecard, read
           {
               if ( llGetSubString(data, 0, 0) != "#" )// Make sure it's not a comment
               {
                   ACCESS += [data]; // Add the owners
                   NOTE_LINE += 1; // Go to next line
                   NOTECARD = llGetNotecardLine(NOTE_NAME, NOTE_LINE);
               }
               else
               {
                   NOTE_LINE += 1; // Go to next line if it's a comment
               }
           }
           else
           {
               if ( ACCESS != [] ) // No point in telling the owner who is on the access list, if there is no one there
               {
                   llOwnerSay("Loaded the follow AVs to the access list: "+llList2CSV(ACCESS));
               }
               NOTE_LINE = 0; // Reset the notecard line for later
           }
       }
   }

} </lsl>

The note card access list example

#Anything with '#' is a comment and will be ignored
MissPony Pelous
MissPony Pelous
FirstName3 LastName4
#etc, etc :)
#Some more stuff to ignore :)

RealRestraint plugin open source examples

The following below are two examples of making a RealRestraint plugin.

This is an example of KEYHOLDER ONLY access

Name of script: "*AllAccess plugin" <lsl> // Created by MissPony Pelous for learning purposes only. Do not sell this code without permission // From MissPony Pelous directly. // ================================================================================================ // This script was created for the purpose of showing how a simple RealRestraint plugin works. // The RealRestraint brand is created by Marine Kelley. // ================================================================================================ // The following code will demonstrate the use of the backdoor (such as used in a realkey) // HOWEVER it is NOT a real key and will not give out information on how the actual real key works // This is merely the internal command. // ================================================================================================ // Also will be the add and removal of struggle chances, i.e.- the amount you can struggle before // having to wait a certain time. // ================================================================================================ // A SIDE NOTE TO THE USERS WHO MIGHT MAKE A PLUGIN OF THEIR OWN // The '*' is for KEYHOLDERS ONLY and anything after that, will be the menu button name. // Where as the '&' is for OWNER ONLY and can be accessed by the owner at any time. // If you DO NOT need a MENU for this plugin, then NO PREFIX IS NEEDED. // =============== // AGAIN: '*Menu' Would be an example for KEYHOLDER ONLY menu. // and '&Menu' Would be an example for OWNER ONLY menu. // =============== // ================================================================================================

key TEMP; //Just a temporary key used to know which person to give the keys to. dia(key user) {

   llDialog(user, "\nWhat option would you like to choose?\n", ["GetKey", "NoStrug", "AlwStrug"], -99999234);

} default {

   link_message(integer sender, integer link_num, string msg, key id)
   {
       if ( msg == llGetScriptName()) // This is used when the menu sends a message asking for the actual menu of this plugin.
       {
           dia(id); // Gives the dialog to who is currently using this plugin, repeated below.
       }
   }
   touch_start(integer t)
   {
       if ( llDetectedKey(0) != llGetOwner() )// Determines who to give the menu to, in this case, not the owner.
       {
           if ( llDetectedKey(0) != TEMP) // Only gives a menu to who has not used this to take the keys: SEE BELOW.
           {
               llMessageLinked(LINK_SET, 11, "*AllAccess", llDetectedKey(0)); // Tells the RR to access this scripts menu.
           }
       }
       
   }
   state_entry()
   {
       llListen(-99999234, "", "", ""); // Our dialog listener.
   }
   listen(integer chan, string name, key id, string msg)
   {
       if ( chan == -99999234 ) // Make sure it's on the dialog channel only.
       {
           if (msg == "GetKey")
           {                                                 // This command is what would be sent, if the real key were
               llMessageLinked(LINK_SET, 0, "Backdoor", id); // touched that matched the RealRestraint password.
               TEMP = id; // If the person takes the key, makes them the temp user, due to only needing this once.
               dia(id);
           }
           if (msg == "NoStrug")
           {
               llMessageLinked(LINK_SET, 0, "Cmd:$-1000", llGetOwner()); // This is the REMOVE struggle chance command
               dia(id);                                                  // and will REMOVE the number typed.
           }                                                             // In this example, it will prevent struggling at all.
           if (msg == "AlwStrug")
           {
               llMessageLinked(LINK_SET, 0, "Cmd:$+35", llGetOwner()); // Adds back, in this case, 35 tries to struggle
               dia(id);                                                // The default being 32 however, this puts 35. :)
           }
       }
   }

} </lsl>


This is an example for OWNER ONLY access

Name of script: "*Safety plugin" <lsl> // Created by MissPony Pelous for learning purposes only. Do not sell this code without permission // From MissPony Pelous directly. // ================================================================================================ // This script was created for the purpose of showing how a simple RealRestraint plugin works. // The RealRestraint brand is created by Marine Kelley. // ================================================================================================ // The following code will demonstrate the use of the backdoor (such as used in a realkey) // HOWEVER it is NOT a real key and will not give out information on how the actual real key works // This is merely the internal command. // ================================================================================================ // Also will be the add and removal of struggle chances, i.e.- the amount you can struggle before // having to wait a certain time. // ================================================================================================ // A SIDE NOTE TO THE USERS WHO MIGHT MAKE A PLUGIN OF THEIR OWN // The '*' is for KEYHOLDERS ONLY and anything after that, will be the menu button name. // Where as the '&' is for OWNER ONLY and can be accessed by the owner at any time. // If you DO NOT need a MENU for this plugin, then NO PREFIX IS NEEDED. // =============== // AGAIN: '*Menu' Would be an example for KEYHOLDER ONLY menu. // and '&Menu' Would be an example for OWNER ONLY menu. // =============== // ================================================================================================

dia(key user) {

   llDialog(user, "\nWhat option would you like to choose?\n", ["Safeword!"], -99999234);

} default {

   link_message(integer sender, integer link_num, string msg, key id)
   {
       if ( msg == llGetScriptName()) // This is used when the menu sends a message asking for the actual menu of this plugin.
       {
           dia(id); // Gives the dialog to who is currently using this plugin.
       }
   }
   state_entry()
   {
       llListen(-99999234, "", "", ""); // Our dialog listener.
   }
   listen(integer chan, string name, key id, string msg)
   {
       if ( chan == -99999234 ) // Make sure it's on the dialog channel only.
       {
           if (msg == "Safeword!") // If the user actually presses the safety button.
           {                                                 // This command is what would be sent, if the real key were
               llMessageLinked(LINK_SET, 0, "Backdoor", id); // touched that matched the RealRestraint password.
           }
       }
   }

} </lsl>

RLV Scripts

This section is devoted to scripts used for the RLV (RestrainedLife Viewer)


Simple welder

<lsl> default {

   state_entry()
   {
       llOwnerSay("@detach=n");
   }
   on_rez(integer r)
   {
       llOwnerSay("@detach=n");
       llSleep(10); //sleep and send the message once more to make sure it's locked on.
       llOwnerSay("@detach=n");
   }

} </lsl>

Non-prim strip-prevention!

Ever get tired of being stripped and you would rather keep your clothes on?! Well this is the script for you! <lsl> default {

   state_entry()
   {
       llOwnerSay("@remoutfit=n");
   }
   on_rez(integer r)
   {
       llOwnerSay("@remoutfit=n");
       llSleep(10);
       llOwnerSay("@remoutfit=n");
   }
   attach(key id)
   {
       if ( id )//It is worn because there is an id :)
       {//Do nothing when attached
       }
       else//Do something since it is detached :)
       {
           llOwnerSay("@remoutfit=y");//Allow removing clothing when detached
       }
   }

} </lsl>


UnderClothing removal prevention

This little script is really useful for those of you who use tattoo under layers such as the Undershirt or Underpants and get tired of them being stripped off :) <lsl> // Simple underclothing removale prevention :) // This is great for those pesky tattoos that keep getting removed ;) default {

   state_entry()
   {
       llOwnerSay("@remoutfit:underpants=n");
       llOwnerSay("@remoutfit:undershirt=n");
   }
   on_rez(integer r)
   {
       llOwnerSay("@remoutfit:underpants=n");
       llOwnerSay("@remoutfit:undershirt=n");
       llSleep(10); // In case the viewer didn't prevent it the first time
       llOwnerSay("@remoutfit:underpants=n");
       llOwnerSay("@remoutfit:undershirt=n");
   }

} </lsl>