User:Allen Kerensky/Myriad Lite Preview4/Myriad Lite Target v0.0.5 20110813

From Second Life Wiki
Jump to navigation Jump to search

Myriad Lite Target v0.0.5 20110813

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

//============================================================================ // 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 //============================================================================ 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 rez_param) {
       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) {
       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 //============================================================================ </lsl>