Difference between revisions of "Punkysnippets"

From Second Life Wiki
Jump to navigation Jump to search
Line 258: Line 258:
</lsl>
</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
// Mr lovenkraft 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 = ["Mr Lovenkraft"];
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
Mr Lovenkraft
#Some more stuff to ignore :)

Revision as of 10:53, 25 August 2008

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>