User:Allen Kerensky/Myriad Lite Preview4/Myriad Lite Healing v0.0.1 20110813

From Second Life Wiki
Jump to navigation Jump to search

Myriad Lite Healing v0.0.1 20110813

<lsl> //============================================================================ // Myriad Lite Healing v0.0.1 20110813 // 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 Healing is published under a: // Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported //============================================================================

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