User:Allen Kerensky/Myriad Lite Preview4/Myriad Lite Holster v0.0.0 20110904

From Second Life Wiki
Jump to navigation Jump to search

Myriad Lite Holster v0.0.0 20110904

<lsl> //============================================================================ // Myriad Lite Holster v0.0.0 20110904 // Copyright (c) 2011 By Allen Kerensky (OSG/SL) // The Myriad RPG System was designed, written, and illustrated by Ashok Desai // Myriad is published under a: // Creative Commons License (Attribution 2.0 UK: England and Wales) // Myriad Lite Holster is published under a: // Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported //===========================================================================

//=========================================================================== // MESSAGE FORMAT REFERENCE //=========================================================================== // CHANATTACH IN - DRAWLEFT,DRAWRIGHT,DRAWBOTH // CHANATTACH IN - HOLSTERLEFT,HOLSTERRIGHT,HOLSTERBOTH // CHANATTACH IN - SHEATHELEFT,SHEATHERIGHT,SHEATHEBOTH

string DIV = "|"; // field divider between parts of Myriad messages list LEFTATTACHED = [3,7,20,21,25,26,27,29]; // left side holster attachment slots list RIGHTATTACHED = [4,8,18,19,22,23,24,30]; // right side holster attachment slots

//=========================================================================== // GLOBAL RUNTIMES - runtime variables we change as we go // Don't alter anything below if your not familiar with it. //=========================================================================== integer CHANATTACH = 0; // dynamic channel for attachment messages integer HANDATTACH = 0; // chat channel handle for attachment dynamic channel

//=========================================================================== // GLOBAL SETUP //=========================================================================== SETUP() {

   CHANATTACH = (integer)("0x"+llGetSubString((string)llGetOwner(),1,7)); // calculate the dynamic attachment channel
   if ( HANDATTACH != 0 ) llListenRemove(HANDATTACH); // clean up a previous listener
   HANDATTACH = llListen(CHANATTACH,"",NULL_KEY,""); // start a listener on the attachment channel
   llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES); // make holster/sheathe visible

}

// DRAW THE WEAPON DRAW(string hand) {

   // draw code goes here
   if ( llListFindList(LEFTATTACHED,[llGetAttached()]) != -1 && ( hand == "left" || hand == "both" ) ) {
       llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES); // go invisible when weapon drawn
   }
   if ( llListFindList(RIGHTATTACHED,[llGetAttached()]) != -1 && ( hand == "right" || hand == "both" ) ) {
       llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES); // go invisible when weapon drawn
   }

}

// HOLSTER THE WEAPON HOLSTER(string hand) {

   // holster code goes here
   if ( llListFindList(LEFTATTACHED,[llGetAttached()]) != -1 && ( hand == "left" || hand == "both" ) ) {
       llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES); // go visible when weapon holstered/sheathed
   }
   if ( llListFindList(RIGHTATTACHED,[llGetAttached()]) != -1 && ( hand == "right" || hand == "both" ) ) {
       llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES); // go visible when weapon holstered/sheathed
   }

}

//=========================================================================== // STATE DEFAULT - the main state is the default state. // When a script is compiled, reset or loaded, this is the state it enters by default. //=========================================================================== default {

   //-----------------------------------------------------------------------
   // STATE_ENTRY EVENT - Triggered on any state transition and start up
   //-----------------------------------------------------------------------
   state_entry() {
       SETUP(); // call global setup
   }

   //-----------------------------------------------------------------------
   // ON_REZ EVENT - Triggered when object attached or rezzed on the ground
   //-----------------------------------------------------------------------
   on_rez(integer rezparams) {
       SETUP();
   }
   //-----------------------------------------------------------------------
   // ATTACH EVENT - when the object is attached or detached
   //-----------------------------------------------------------------------
   attach(key id) {
       if ( id != NULL_KEY ) { // attached from ground or inventory
           SETUP();
       }
   }
   //-----------------------------------------------------------------------
   // LISTEN EVENT - listen for whisper, say, shout, regionsay messages
   //-----------------------------------------------------------------------
   listen(integer channel, string name, key uuid, string message) {
       if ( channel == CHANATTACH ) { // did message come in on attachment channel?
           if ( message == "DRAWLEFT" ) { DRAW("left"); return;} // draw weapons if in left hand
           if ( message == "DRAWRIGHT" ) { DRAW("right"); return;} // draw weapons in right hand
           if ( message == "DRAWBOTH" ) { DRAW("both"); return; } // draw weapons in both hands
           if ( message == "HOLSTERLEFT" ) { HOLSTER("left"); return;} // holster left-hand weapons
           if ( message == "HOLSTERRIGHT" ) { HOLSTER("right"); return;} // holster right-hand weapons
           if ( message == "HOLSTERBOTH" ) { HOLSTER("both"); return; } // holster both weapons
           if ( message == "SHEATHELEFT" ) { HOLSTER("left"); return;} // sheathe left-hand weapon
           if ( message == "SHEATHERIGHT" ) { HOLSTER("right"); return;} // sheathe right-hand weapons
           if ( message == "SHEATHBOTH" ) { HOLSTER("both"); return; } // sheatheholster both weapons
       }
   }    

} // end of default //============================================================================ // END //============================================================================ </lsl>