User:Allen Kerensky/Myriad Lite Preview 5/Holster

From OpenSimulator

< User:Allen Kerensky | Myriad Lite Preview 5(Difference between revisions)
Jump to: navigation, search
(created)
 

Revision as of 14:33, 6 February 2012

Myriad Lite Holster

Players can draw weapons from a holster or sheathe to begin combat, or sheathe/holster weapons to withdraw from combat.

See the Commands page for holster commands.

Setup

  1. Create an object to act as a wearable holster for a firearm or a sheathe for a melee weapon.
  2. Drag and Drop the Myriad Lite Holster script from inventory into the holster object: ?
  3. Attach the object to the desired attachment point.
  4. Adjust the position and rotation.
  5. Detach the object back to inventory to "save" the new default attach point.
  6. Attach or wear the holster when desired.

Myriad_Lite_Holster-v0.0.1-20120201.lsl

//============================================================================
// Myriad_Lite_Holster-v0.0.1-20120201.lsl
// Copyright (c) 2012 By Allen Kerensky (OSG/SL)
// The Myriad RPG System was designed, written, and illustrated by Ashok Desai
// Myriad RPG licensed under the Creative Commons Attribution 2.0 UK: England and Wales
// http://creativecommons.org/licenses/by/2.0/uk/
// Myriad Lite software Copyright (c) 2011-2012 by Allen Kerensky (OSG/SL)
// Baroun's Adventure Machine Copyright (c) 2008-2011 by Baroun Tardis (SL)
// Myriad Lite and Baroun's Adventure Machine licensed under the
// Creative Commons Attribution-Share Alike-Non-Commercial 3.0 Unported
// http://creativecommons.org/licenses/by-nc-sa/3.0/
// You must agree to the terms of this license before making any use of this software.
// If you do not agree to this license, simply delete these materials.
// There is no warranty, express or implied, for your use of these materials.
//===========================================================================

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

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
//============================================================================

General
About This Wiki