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

From OpenSimulator

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

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

Myriad_Lite_Healing-Preview6.lsl

// Myriad_Lite_Healing-Preview6.lsl
// Copyright (c) 2012 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/
 
string  VERSION = "0.0.2"; // version number
string  VERDATE = "20120130"; // version date
 
//============================================================================
// MESSAGE FORMAT REFERENCE
//============================================================================
// CHANMYRIAD OUT - RPEVENT|str eventmessage
// CHANPLAYER OUT - HEALALL
// CHANPLAYER OUT - HEALPARTIAL|str HEALAMOUNT
 
//============================================================================
// GLOBAL CONSTANTS
//============================================================================
float   TOUCH_RANGE = 3.0;      // meters - how close do you have to be for touch-to-heal to work
integer RESPAWN_FLAG = TRUE;    // once heal is used, respawn it after a certain time?
float   RESPAWN_TIME = 30.0;    // how long until heal respawns?
integer CHANMYRIAD = -999;      // channel for Myriad RP events
string  DIV = "|";              // Myriad message field divider
integer HEALALL = TRUE;         // heal all? if FALSE...
integer HEALAMOUNT = 0;         // heal how many critical/wound boxes?
 
//============================================================================
// GLOBAL SETUP()
//============================================================================
SETUP() {
    llSetLinkColor(LINK_SET,<1,0,0>,ALL_SIDES); // set all prims to red on all sides
    llTargetOmega(<0,0,1>,0.25,1.0); // set the object slowly spinning around the Z (vertical) axis
    if ( HEALALL == TRUE ) { // what label do we set?
        llSetText("Full Healing",<1,0,0>,1.0); // Set a red FULL heal hovertext
    } else { // this is only a partial heal
        llSetText("Partial Healing",<1,0,0>,1.0); // set a read PARTIAL heal hovertext
    }
}
 
//============================================================================
// DEFAULT STATE
//============================================================================
default {
    //------------------------------------------------------------------------
    // STATE_ENTRY EVENT
    //------------------------------------------------------------------------
    state_entry() {
        SETUP(); // if reset, go to setup
    }
 
    //------------------------------------------------------------------------
    // ON_REZ EVENT
    //------------------------------------------------------------------------
    on_rez(integer start_param) {
        start_param = 0; // LSLINT
        SETUP(); // if rezzed from inventory, go to setup
    }
 
    //------------------------------------------------------------------------
    // COLLISION_START EVENT - if player runs into the heal object, try healing them
    //------------------------------------------------------------------------
    collision_start(integer collisions) {
        while (collisions--) { // count down through each collision in this event
            if ( RESPAWN_FLAG == FALSE ) { // this heal has already been used recently
                return; // so just return since we're not going to heal anyone at the moment
            }
            key who = llDetectedKey(collisions); // what hit the heal object?
            // we check the owner of the colliding object to see if its an avatar, or someone's bullet, etc
            key whoowner = llList2Key(llGetObjectDetails(who,[OBJECT_OWNER]),0);
            if ( who == whoowner) { // this is an avatar that owns itself
                // calculate the CHANPLAYER dynamic channel for who is being healed
                integer chanplayer = (integer)("0x"+llGetSubString((string)who,0,6));
                if ( HEALALL == TRUE ) { // are we healing all damage?
                    llRegionSay(CHANMYRIAD,llKey2Name(who)+" is fully healed!");
                    llWhisper(chanplayer,"HEALALL"); // tell that player's HUD to heal ALL damage
                } else {
                    llRegionSay(CHANMYRIAD,llKey2Name(who)+" is partially healed!");
                    llWhisper(chanplayer,"HEALPARTIAL"+DIV+(string)HEALAMOUNT); // tell player HUD to heal some damage
                }
                llSetLinkColor(LINK_SET,<.5,.5,.5>,ALL_SIDES); // make the heal item grey and used looking
                llSetTimerEvent(RESPAWN_TIME); // set a timer to respawn this heal item after a while
                RESPAWN_FLAG=FALSE; // set a flag so the heal can't be reused until it respawns
                return; // collision is done, let's exit after healing first avatar found in collisions
            }
        }
    }
 
    //------------------------------------------------------------------------
    // TOUCH_START EVENT - when player clicks heal, see if they are close enough
    //------------------------------------------------------------------------
    touch_start(integer touches) {        
        while (touches--) { // count down through all touches in this touch-start event
            if ( RESPAWN_FLAG == FALSE ) { // this heal has been used recently and has not respawned
                return; // so exit early since we're not healing anyone right now
            }
 
            key who2 = llDetectedKey(touches); // who clicked us, we don't check for avatar since objects can't click
            // find the current location of what clicked us
            vector whopos = llList2Vector(llGetObjectDetails(who2,[OBJECT_POS]),0);
 
            if ( llVecDist(whopos,llGetPos()) <= TOUCH_RANGE ) { // check distance between heal item and whoever clicked
                // calculate CHANPLAYER dynamic player channel to send healing message to
                integer chanplayer2 = (integer)("0x" + llGetSubString((string)who2,0,6));
                if ( HEALALL == TRUE ) { // are we healing all damage?
                    llRegionSay(CHANMYRIAD,llKey2Name(who2)+" is fully healed!"); // tell region someone is healing
                    llWhisper(chanplayer2,"HEALFULL"); // heal all damage
                } else {
                    llRegionSay(CHANMYRIAD,llKey2Name(who2)+" is partially healed!"); // tell region someone is healing
                    llWhisper(chanplayer2,"HEALPARTIAL"+DIV+(string)HEALAMOUNT); // heal some damage
                }
                llSetLinkColor(LINK_SET,<.5,.5,.5>,ALL_SIDES); // make the heal item grey and unused looking
                llSetTimerEvent(RESPAWN_TIME); // set a timer to respawn this heal item after a while
                RESPAWN_FLAG=FALSE; // set a flag so the heal can't be reused until it respawns
                return; // touch is done, let's exit after healing first avatar found in clicks
            }
        } // end while
    }
 
    //------------------------------------------------------------------------
    // TIMER EVENT
    //------------------------------------------------------------------------
    timer() {
        llSetLinkColor(LINK_SET,<1,0,0>,ALL_SIDES); // set color to red again to show this can be used
        RESPAWN_FLAG=TRUE; // set a flag to all the next heal attempt to work
        llSetTimerEvent(0.0); // stop the timers until the next heal event starts a new one
    }
} // end default
//============================================================================
// END
//============================================================================
Personal tools
General
About This Wiki