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

From OpenSimulator

Jump to: navigation, search

Myriad_Lite_Target-Preview6.lsl

// Myriad_Lite_Target-v0.0.6-20120202.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
//============================================================================
// CHANPLAYER IN - DEPRECATED - HITCHECK|int attackstat|int attackskill|int attackdice|key owner|str name
// CHANPLAYER IN - RANGEDHIT|int attackstat|int attackskill|int attackdice|key weaponowner|str name
// CHANPLAYER IN - CLOSEHIT|int attackstat|int attackskill|int attackdice|key weaponowner|str name
 
//============================================================================
// GLOBAL VARIABLES
//============================================================================
string  VERSION = "0.0.6"; // version number
string  VERDATE = "20120202"; // version date
 
integer CHANOBJECT; // channel the target listens on for attacks
integer HANDOBJECT; // chat channel handle to remove channel later if needed
integer MINSTAT = 1; // minimum value of a statistic
integer MAXSTAT = 10; // maximum value of a statistic
integer MINSKILL = 1; // minimum value of a skill
integer MAXSKILL = 5; // maximum value of a skill
integer MINDAMAGE = 1; // minimum damage dice a weapon can inflict
integer MAXDAMAGE = 5; // maximum damage dice a weapon can inflict
 
//============================================================================
// GLOBAL ERROR() - report errors on debug channel
//============================================================================
ERROR(string errmsg) {
    llSay(DEBUG_CHANNEL,"ERROR: "+errmsg);
}
 
//============================================================================
// DEFAULT STATE
//============================================================================
default {
    //------------------------------------------------------------------------
    // STATE_ENTRY EVENT
    //------------------------------------------------------------------------
    state_entry() {
        llSetPrimitiveParams([PRIM_PHANTOM, FALSE]); // ensure all prims are not phantom to register collisions
        CHANOBJECT = (integer)("0x"+llGetSubString((string)llGetKey(),0,6)); // calculate dynamic channel to listen on
        HANDOBJECT = llListen(CHANOBJECT,"",NULL_KEY,""); // start listener for attack events
    }
 
    //------------------------------------------------------------------------
    // ON_REZ EVENT
    //------------------------------------------------------------------------
    on_rez(integer param) {
        param = 0; // LSLINT
        llResetScript(); // nothing drastic, just reset script and start from the top
    }
 
    //------------------------------------------------------------------------
    // LISTEN EVENT - whispers, says, shouts, regionsays
    //------------------------------------------------------------------------
    listen(integer channel,string speakername,key speakerid,string message) {
        speakername = ""; // LSLINT
        speakerid = NULL_KEY; // LSLINT
        if ( channel == CHANOBJECT ) { // is this message on the dynamic channel?        
            list fields = llParseString2List(message,["|"],[]); // break message into parts split by | symbol
            string command = llList2String(fields,0); // field 0 is the command
            if ( command == "HITCHECK" || command == "RANGEDHIT" || command == "CLOSEHIT" ) { // is this an attack command?
                integer attackstat = llList2Integer(fields,1); // get the value of the attacker's stat
                integer attackskill = llList2Integer(fields,2); // get the attackers skill level
                integer attackdice = llList2Integer(fields,3);  // get the attackers weapon attack dice
                key owner = llList2Key(fields,4); // get the owner of the attacking object
                string item = llList2String(fields,5); // get the name of the attacking object
                if ( attackstat < MINSTAT || attackstat > MAXSTAT ) { // is attack stat valid?
                    ERROR("Attack stat value out of range: "+(string)MINSTAT+"-"+(string)MAXSTAT); // report the invalid value
                    return; // exit early since we've hit a fatal error with message
                }
                if ( attackskill < MINSKILL || attackstat > MAXSKILL ) { // is attacker skill value valid?
                    ERROR("Attack skill value out of range: "+(string)MINSKILL+"-"+(string)MAXSKILL); // report invalid value
                    return; // exit early since we've hit a fatal error with message
                }                
                if ( attackdice < MINDAMAGE || attackdice > MAXDAMAGE ) { // is attack dice of object valid?
                    ERROR("Attack dice value out of range: "+(string)MINDAMAGE+"-"+(string)MAXDAMAGE); // report invalid value
                    return; // exit early since we've hit a fatal error with message
                }
                // its all good - report the hit
                llShout(PUBLIC_CHANNEL,"/me hit by "+llKey2Name(owner)+"'s "+item+" for "+(string)attackdice+" attack dice!");
                return; // exit early in case we add more commands later
            } // end if attack command           
        } // end if channel object        
    }    
} // end default
//============================================================================
// END
//============================================================================
Personal tools
General
About This Wiki