User:Allen Kerensky/Myriad Lite/Myriad Lite Holster-Preview6.lsl

From OpenSimulator

< User:Allen Kerensky | Myriad Lite
Revision as of 15:30, 11 August 2012 by Allen Kerensky (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Myriad_Lite_Holster-Preview6.lsl

//============================================================================
// Myriad_Lite_Holster-Preview6.lsl
// Copyright (c) 2012 by Allen Kerensky (OSG/SL) All Rights Reserved.
// This work is dual-licensed under
// Creative Commons Attribution (CC BY) 3.0 Unported
// http://creativecommons.org/licenses/by/3.0/
// - or -
// Modified BSD License (3-clause)
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, 
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
// * Neither the name of Myriad Lite nor the names of its contributors may be
//   used to endorse or promote products derived from this software without
//   specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
// NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The Myriad RPG System was designed, written, and illustrated by Ashok Desai
// Myriad RPG System licensed under:
// Creative Commons Attribution (CC BY) 2.0 UK: England and Wales
// http://creativecommons.org/licenses/by/2.0/uk/
//============================================================================
 
//===========================================================================
// MESSAGE FORMAT REFERENCE
//===========================================================================
// CHANATTACH IN - DRAWLEFT,DRAWRIGHT,DRAWBOTH
// CHANATTACH IN - HOLSTERLEFT,HOLSTERRIGHT,HOLSTERBOTH
// CHANATTACH IN - SHEATHELEFT,SHEATHERIGHT,SHEATHEBOTH
 
string  VERSION = "0.0.1"; // version number
string  VERDATE = "20120201"; // version date
 
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) {
        rezparams = 0; // LSLINT
        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) {
        name = ""; // LSLINT
        uuid = NULL_KEY; // LSLINT
        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
//============================================================================
Personal tools
General
About This Wiki