User:Allen Kerensky/Myriad Lite Preview2/Myriad Lite Melee v0.0.1 20110606

From Second Life Wiki
< User:Allen Kerensky
Revision as of 12:56, 11 June 2011 by Allen Kerensky (talk | contribs) (created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Myriad Lite Melee v0.0.1 20110606

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

key WEARER = NULL_KEY; integer ATTACHPOINT = 0; integer MINMELEE = 1; integer MAXMELEE = 5; // Melee Attack Dice // 1D - Unarmed Combat // 2D - Short animal claws, knife, dagger, blackjack, knuckledusters // 3D - Long animal claws, short sword, machete, wooden baseball bat, staff // 4D - Fire axe, long sword, katana, aluminum baseball bat, poleaxe // 5D - Battleaxe, claymore, laser sword, daikatana, double-ended polearm integer MELEEATTACKDICE = 1; string DIV="|"; string ANIM_SWORD = "sword_strike_r"; integer CHANPLAYER; integer HANDPLAYER; integer CHANMYRIAD = -999; integer ANIM = FALSE; float WEAPON_LENGTH = 2.0;

default {

   state_entry() {
       CHANPLAYER = (integer)("0x"+llGetSubString((string)llGetOwner(),0,6));
       HANDPLAYER = llListen(CHANPLAYER,"",NULL_KEY,"");
   }
   
   attach(key id) {
       if ( id != NULL_KEY ) {
           WEARER = id;
           ATTACHPOINT = llGetAttached();
           integer dynchan = (integer)("0x"+llGetSubString((string)WEARER,0,6));
           llWhisper(dynchan,"ATTACHMELEE"+DIV+(string)MELEEATTACKDICE+DIV+(string)ATTACHPOINT+DIV+llGetObjectName());
           llRequestPermissions(id,PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION);
       } else {
           integer dynchan = (integer)("0x"+llGetSubString((string)WEARER,0,6));
           if ( dynchan != 0 ) {
               llWhisper(dynchan,"DETACHMELEE"+DIV+(string)MELEEATTACKDICE+DIV+(string)ATTACHPOINT+DIV+llGetObjectName());
           } else {
               llSay(DEBUG_CHANNEL,"DETACH EVENT WITHOUT PREVIOUS ATTACH?");
           }
           WEARER = NULL_KEY;
           ATTACHPOINT = 0;
       }
   }
   listen(integer channel,string speakername,key speakerid,string message) {
       if ( message == "REGISTERATTACHMENTS" ) {
           WEARER = llGetOwner();
           ATTACHPOINT = llGetAttached();
           integer dynchan = (integer)("0x"+llGetSubString((string)WEARER,0,6));
           llWhisper(dynchan,"ATTACHMELEE"+DIV+(string)MELEEATTACKDICE+DIV+(string)ATTACHPOINT+DIV+llGetObjectName());
       }
   }
   run_time_permissions(integer perm) {
       if ( perm & PERMISSION_TAKE_CONTROLS ) {
           llTakeControls(CONTROL_LBUTTON,TRUE,TRUE);
       }
       if ( perm & PERMISSION_TRIGGER_ANIMATION ) {
           ANIM = TRUE;
       }
   }
   control(key id,integer level,integer edge) {
       if ( id == WEARER ) {
           if ( ( level & CONTROL_LBUTTON ) && ( edge & CONTROL_LBUTTON ) ) {
               llSensor("",NULL_KEY,AGENT,WEAPON_LENGTH,PI/6);
               if ( ANIM == TRUE ) llStartAnimation(ANIM_SWORD);
               llSleep(0.2);
           }
       }
   }
   sensor(integer num_detected) {
       while(num_detected--) {
           // This is a trick to calculate a point in front of me weapon_length away
           // Thanks Mephistopheles Thalheimer (SL) for this trick
           //vector A = ( llGetPos() + < WEAPON_LENGTH,0,0> * llGetRot());
           // Where is Defender
           //vector D = llDetectedPos(num_detected);
           // Is defender center within 1m of my calculated point in front of me?
           // If so, my sword had a chance to hit when I swung it.
           //if ( llVecDist(A,D) < 1.0 ) { 
               integer dynchan = (integer)("0x"+llGetSubString((string)llGetOwner(),0,6));
               llRegionSay(dynchan,"CLOSECOMBAT"+DIV+(string)MELEEATTACKDICE+DIV+(string)llDetectedKey(num_detected)+DIV+(string)llGetOwner()+DIV+llGetObjectName());
           
               key who = llDetectedKey(num_detected);
               key owner = llList2Key(llGetObjectDetails(who,[OBJECT_OWNER]),0);
               if ( who == owner ) { // we hit an avatar
                   llRegionSay(CHANMYRIAD,"RPEVENT"+DIV+llKey2Name(llGetOwner())+" strikes "+llDetectedName(num_detected)+" in Close Combat!");
               }
           //}
       }
   }
   no_sensor() {
       //llOwnerSay("Missed!");
   }

} </lsl>