Combined LockMeister Cuff script

From Second Life Wiki
Revision as of 17:04, 19 January 2010 by Tianna Violet (talk | contribs) (Comprehensive Lockmeister Cuff Script)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

An update for LockMeister Cuffs

This script implements a combination of extensions to the LockMeister system protocol LSL_Protocol/LockMeister_System using them together to bring added benefits.

<lsl>/////////////////////////////////////////////////////////////////////// // // Comprehensive Lockmeister Cuff Script // // Tianna Violet // 20 Jan 2010 // // This is a Lockmeister cuff script that combines many of the extensions // to the lockmeister protocol at defined here: // http://wiki.secondlife.com/wiki/LSL_Protocol/LockMeister_System // To the basic query response is added Amethyst Rosencrans' Sensations // extensions for allowing particle links between cuffs and // Henri Beauchamp's "here" and "gone" extensions which notify when a cuff // is attached and detached. Combining these allows a few extra features: // * Cuffs can delete or reassign particle chains if their target object // disappears. // * Cuffs can attach if the target point appears. // * Cuffs can reattach when an AV logs in. // // In addition is added a new command, "reset" defined as stopping the // particle chain and resetting the Age, Gravity, and Texture back to // their defaults. // // Although this script is new, reference was made to Amethyst Rosencrans' // "Free Amethyst cuff script v2" (which is a little out of date) and // from spying on the Lockmeister messages coming from the Amethyst cuffs // set. /////////////////////////////////////////////////////////////////////// // The lockmeister name of the cuff. See the above link for details string LOCKMEISTER_NAME = "lcuff"; /////////////////////////////////////////////////////////////////////// string gCuffMessage; string gRequestedTargets; string gWorkingTargets; key gCurrentTarget; float gAge; float gGravity; string gTexture;

// Start or update the particle stream updateParticles() {

   llParticleSystem( [PSYS_PART_START_SCALE, <0.1, 0.1, 0>, PSYS_PART_END_SCALE, <1, 1, 0>, PSYS_PART_START_COLOR, <1, 1, 1>, PSYS_PART_END_COLOR, <1, 1, 1>, PSYS_PART_START_ALPHA, 1.0, PSYS_PART_END_ALPHA, 1.0, PSYS_SRC_TEXTURE, gTexture, PSYS_SRC_BURST_PART_COUNT, 1, PSYS_SRC_BURST_RATE, 0.0, PSYS_PART_MAX_AGE, gAge, PSYS_SRC_MAX_AGE, 0.0, PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP, PSYS_SRC_BURST_RADIUS, 0.5, PSYS_SRC_INNERANGLE, 0.0, PSYS_SRC_OUTERANGLE, 0.0, PSYS_SRC_OMEGA, <0, 0, 0>, PSYS_SRC_ACCEL, <0, 0, -gGravity>, PSYS_SRC_BURST_SPEED_MIN, 1000.0, PSYS_SRC_BURST_SPEED_MAX, 1000.0, PSYS_SRC_TARGET_KEY, gCurrentTarget, PSYS_PART_FLAGS, PSYS_PART_FOLLOW_VELOCITY_MASK | PSYS_PART_FOLLOW_SRC_MASK | PSYS_PART_TARGET_POS_MASK]);

}

// ping the cuffs that can be used as possible targets, if any pingCuffs() {

   list cuffs;
   integer a;
   integer len;
   
   gWorkingTargets = gRequestedTargets;
   if (gWorkingTargets != "")
   {
       cuffs = llParseString2List(gWorkingTargets, ["-"], []);
       len = llGetListLength(cuffs);
       for (a = 0; a < len; a++)
       {
           llWhisper(-8888, (string) llGetOwner() + llList2String(cuffs, a));
       }
   }

}

default {

   state_entry()
   {
       gCuffMessage = (string) llGetOwner() + LOCKMEISTER_NAME;
       gRequestedTargets = "";
       gWorkingTargets = "";
       gCurrentTarget = NULL_KEY;
       gAge = 2;
       gGravity = 0.7;
       gTexture = "1ffb37fa-2fc1-dbec-d8ea-0607583a03c6";
       llListen(-8888, "", NULL_KEY, "");        
   }
   on_rez(integer start_param)
   {
       llParticleSystem([]);
       gCuffMessage = (string) llGetOwner() + LOCKMEISTER_NAME;
   }
   
   attach(key id)
   {
       string message;
       message = " gone";
       if (id)
       {
           gCuffMessage = (string) llGetOwner() + LOCKMEISTER_NAME;
           message = " here";
           pingCuffs();
       }
       llSay(-8888, gCuffMessage + message);	// send the "here" and "gone" message
   }
   listen(integer channel, string name, key id, string message)
   {
       list commands = ["gravity", "age", "texture", "target", "reset"];
       list responses = ["ok", "here", "gone"];
       list data;
       list cuffs;
       integer index;
       integer i;
       integer atThis;
       float tempf;
       string temps;
       if (channel == -8888)
       {
           if (message == gCuffMessage)	// quick early out for the basic response
           {
               llSay(-8888, gCuffMessage + " ok");
               return;
           }
           if (((key) llGetSubString(message, 0, 35)) == llGetOwner())
           {
               data = llParseStringKeepNulls(llGetSubString(message, 36, -1), ["|"], []);
               index = llListFindList(commands, llList2List(data, 0, 0));
               if (~index)
               {
                   if (index < 3)	// the 3 particle params that can change
                   {
                       if (index < 2)
                       {
                           tempf = (float) llList2String(data, 1);
                           if (tempf)
                           {
                               if (index)	// "age"
                               {
                                   gAge = tempf;
                               } else {		// "gravity"
                                   gGravity = tempf;
                               }
                           }
                       } else {	// "texture"
                           temps = llList2String(data, 1);
                           if (((key) temps) != NULL_KEY)
                           {
                               gTexture = temps;
                           }
                       }
                       if (gCurrentTarget)
                       {
                           updateParticles();
                       }
                   }
                   if (index == 3)	// "target"
                   {
                       temps = "";
                       atThis = TRUE;
                       if (llGetListLength(data) > 1)
                       {
                           i = llListFindList(llList2ListStrided(llList2List(data, 1, -1), 0, -1, 2), [LOCKMEISTER_NAME]);
                           if (~i)
                           {
                               temps = llList2String(data, (i + 1) << 1);
                           } else {
                               atThis = FALSE;
                           }
                       }
                       if (atThis)
                       {
                           gCurrentTarget = NULL_KEY;
                           gRequestedTargets = temps;
                           pingCuffs();
                           llParticleSystem([]);
                       }
                   }
                   if (index == 4) // "reset"
                   {
                       llParticleSystem([]);
                       llResetScript();
                   }
               } else { 
                   data = llParseString2List(llList2String(data, 0), [" "], []);
                   index = llListFindList(responses, llList2List(data, 1, 1));
                   if (~index) // "ok", "here" and "gone" messages from others
                   {
                       if (index < 2) // "ok" and "here" treated the same
                       {
                           if (gWorkingTargets != "")
                           {
                               cuffs = llParseString2List(gWorkingTargets, ["-"], []);
                               i = llListFindList(cuffs, llList2List(data, 0, 0));
                               if (~i)
                               {
                                   gWorkingTargets = llDumpList2String(llList2List(cuffs, i + 1, -1), "-");
                                   gCurrentTarget = id;
                                   updateParticles();
                               }
                           }
                       } else { // "gone"
                           if (gCurrentTarget == id)
                           {
                               gCurrentTarget = NULL_KEY;
                               llParticleSystem([]);
                               pingCuffs();
                           }
                       }
                   }
               }
           }
       }
   }

} </lsl>