Difference between revisions of "User:Allen Kerensky/Myriad Lite Preview2/Myriad Lite Armor v0.0.2 20110611"

From Second Life Wiki
Jump to navigation Jump to search
(created)
 
m (added lsl header)
 
Line 1: Line 1:
{{LSL Header}}
= Myriad Lite Armor v0.0.2 20110611 =
= Myriad Lite Armor v0.0.2 20110611 =
<lsl>
<lsl>

Latest revision as of 14:10, 11 June 2011

Myriad Lite Armor v0.0.2 20110611

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

//============================================================================ // MESSAGE FORMATS //============================================================================ // ATTACHARMOR|int ARMORRATING|int ATTACHPOINT|string OBJECTNAME // DETACHARMOR|int ARMORRATING|int ATTACHPOINT|string OBJECTNAME // REGISTERATTACHMENTS

//============================================================================ // CONSTANTS - variables which don't change over runtime //============================================================================ // Example Armor (Myriad PDF p64, Myriad Special Edition p98) // Archaic Armor Ratings // 1 Soft leather, heavy cloth // 2 Hardened leather, thick hide // 3 Chain mail, dragon hide // 4 Full plate mail, mithril chain // 5 Mithril plate mail // Modern Armor Ratings // 1 Leather jacket // 2 Bullet-proof vest // 3 SWAT tactical armor // 4 Advanced military armor // 5 Sci-fi powered battle armor integer ARMORRATING = 1; // the *actual* amount of protection THIS piece of armor provides integer MINARMOR = 1; // the minimum amount of protection a piece of armor can offer, checked by HUD integer MAXARMOR = 5; // the maximum amount of protection a piece of armor can offer, checked by HUD string DIV="|"; // the divider used between fields on a Myriad Lite messages integer MINATTACHPOINT = 1; // minimum allowed attachment point number integer MAXATTACHPOINT = 30; // maximum allowed avatar/inworld attachpoint number for multiattach/HUD attach cheaters

//============================================================================ // RUNTIME VARIABLES - variables which should change during runtime //============================================================================ key OWNER = NULL_KEY; // holds UUID of owner key WEARER = NULL_KEY; // holds UUID of last wearer, so we can send detach message to correct meter integer ATTACHPOINT = 0; // the avatar position where armor attached to or detached from integer CHANOWNER; // the chat channel the owner's ML HUD should be listening on integer HANDOWNER; // a chat channel handle to remove the listener with later

//============================================================================ // GLOBAL SETUP() //============================================================================ SETUP() {

   // calculate a dynamic chat channel based on owner key, for where the
   // wearer's ML HUD should be listening of player-specific events
   CHANOWNER = (integer)("0x"+llGetSubString((string)llGetOwner(),0,6));
   // open a channel, listening on player HUD channel, save handle for later close if needed
   HANDOWNER = llListen(CHANOWNER,"",NULL_KEY,"");

}

//============================================================================ // DEFAULT //============================================================================ default {

   //------------------------------------------------------------------------
   // DEFAULT STATE ENTRY - begin our setup or call a setup block
   //------------------------------------------------------------------------
   state_entry() {
       SETUP(); // call the event-independent SETUP code
   }
   //------------------------------------------------------------------------
   // DEFAULT ON_REZ
   //------------------------------------------------------------------------
   on_rez(integer start_param) {
       SETUP(); // call event independent SETUP code        
   }   
   //------------------------------------------------------------------------
   // DEFAULT ATTACH - Called for detach too
   //------------------------------------------------------------------------
   attach(key id) {
       SETUP(); // call event-independent SETUP code
       // is this an attach event or detach event?
       if ( id != NULL_KEY ) { // a valid key means its an attach
           WEARER = id; // save who attached this armor piece for use during detach
           ATTACHPOINT = llGetAttached(); // where was this armor attached?
           // this should NOT be necessary, since it should match CHANPLAYER
           // however, armor can be dropped! So, wearer may NOT be owner. Need changed block?
           integer dynchan = (integer)("0x"+llGetSubString((string)WEARER,0,6));
           // Send ATTACHARMOR message to WEARER HUD
           llWhisper(dynchan,"ATTACHARMOR"+DIV+(string)ARMORRATING+DIV+(string)ATTACHPOINT+DIV+llGetObjectName());
       } else { // else the id equals NULL_KEY which happens for detach
           // calculate dynamic channel for person last wearing armor piece
           integer dynchan = (integer)("0x"+llGetSubString((string)WEARER,0,6));
           if ( dynchan != 0 ) { // did the dynamic channel check give us usable channel number <0 or >0 but not actually 0?
               // Send DETACHARMOR message to previous wearer's HUD
               llWhisper(dynchan,"DETACHARMOR"+DIV+(string)ARMORRATING+DIV+(string)ATTACHPOINT+DIV+llGetObjectName());
           } else { // the dynamic channel was 0?
               // how did we get in this mess? a detach without an attach. Report error. Design failure somewhere. THIS SHOULD NEVER HAPPEN.
               llSay(DEBUG_CHANNEL,"DETACH EVENT WITHOUT PREVIOUS ATTACH?");
           } // end of if dynchan not equal zero
           WEARER = NULL_KEY; // armor detached and reported as such, so we can forget previous wearer
           ATTACHPOINT = 0; // armor detached and reported as such, so we can forget previous attach point
       } // end of if id not equal null key
   }
   //------------------------------------------------------------------------
   // DEFAULT CHANGED
   //------------------------------------------------------------------------
   changed(integer change) {
       if ( change & CHANGED_OWNER ) { // if armor has a new owner from take-from-ground or copy, resetup
           SETUP(); // call event-independent setup code, in this case to update channels
       }
   }    
   //------------------------------------------------------------------------
   // DEFAULT LISTEN
   //------------------------------------------------------------------------
   listen(integer channel,string speakername,key speakerid,string message) {
       ATTACHPOINT = llGetAttached(); // get location we're attached to
       // ML HUD sent a request for any attached items
       if ( ( message == "REGISTERATTACHMENTS" ) && ( ATTACHPOINT >= MINATTACHPOINT ) && ( ATTACHPOINT <= MAXATTACHPOINT ) ) {
           WEARER = llGetOwner(); // get armor owner BUG: what if owner not equal wearer?
           // calculate the dynamic channel of the wearer
           integer dynchan = (integer)("0x"+llGetSubString((string)WEARER,0,6));
           // send the ATTACHARMOR to ML HUD to register that this armor piece is worn
           llWhisper(dynchan,"ATTACHARMOR"+DIV+(string)ARMORRATING+DIV+(string)ATTACHPOINT+DIV+llGetObjectName());
       } // end of if message equal REGISTERATTACHMENTS
   }

} //============================================================================ // END //============================================================================ </lsl>