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>

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>