User:Cow Taurog/Interceptor

From Second Life Wiki
Jump to navigation Jump to search

float gfFreq=0.01; // The scanning speed float gfRange=15; // The scanning range vector gvOffset=<2,0,0>; // Shield plate offset from the avatar float gfTolerance=0.05; // The sensitivity for detecting speed (anything slower than this is considered to be still) float gfInnerLimit=0.95; // Object is too close, don't intercept to avoid putting panels through you integer giChan=74347; integer listen0; integer giStatus;

default{

   link_message(integer sender,integer num,string mess,key id){
       if(mess=="getstatus"){if(id=="interceptor"){llMessageLinked(LINK_SET,1,"status|interceptor|"+(string)giStatus,"status");}}
       if(llToLower(mess)=="touched"){if(id=="interceptor"){state running;}}
   }
   state_entry(){
       giStatus=0;
       llMessageLinked(LINK_SET,1,"status|interceptor|"+(string)giStatus,"status");
   }

} state running{

   link_message(integer sender,integer num,string mess,key id){
       if(mess=="getstatus"){if(id=="interceptor"){llMessageLinked(LINK_SET,1,"status|interceptor|"+(string)giStatus,"status");}}
       if(llToLower(mess)=="touched"){if(id=="interceptor"){llMessageLinked(LINK_SET,1,"status|interceptor|0","status");llOwnerSay("Interceptors off.");state default;}}
       if(llToLower(mess)=="held"){if(id=="interceptor"){
           listen0=llListen(giChan,"","","");
           llSetTimerEvent(30);
           llTextBox(llGetOwner(),"Say sensor range and rez distance seperated by commas\n(i.e. 15,2)\nRange: "+(string)llRound(gfRange)+"m, Rez distance: "+(string)llRound(gvOffset.x)+"m",giChan);
       }}
   }
   changed(integer change){if(change&CHANGED_OWNER){llResetScript();}}
   state_entry(){
       giStatus=1;
       llMessageLinked(LINK_SET,1,"status|interceptor|1","status");
       llOwnerSay("Interceptors on. Scan range: "+(string)llRound(gfRange)+"m. Intercept distance: "+(string)llRound(gvOffset.x)+"m.");
       llSensorRepeat("","",AGENT|ACTIVE,gfRange,PI,gfFreq);
   }
   timer(){llListenRemove(listen0);llSetTimerEvent(0);}
   listen(integer chan,string name,key id,string mess){if(llGetOwnerKey(id)==llGetOwner()){if(mess!=""){
       list lR=llParseString2List(mess,[",","|","/"],[]);
       gfRange=(float)llList2String(lR,0);
       if((float)llList2String(lR,1)>10){llOwnerSay("The maximum inctercept distance is 10m.");gvOffset=<10,0,0>;}
       else{gvOffset=<(float)llList2String(lR,1),0,0>;}
       llSensorRepeat("","",AGENT|ACTIVE,gfRange,PI,gfFreq);
       llOwnerSay("Sensor range is now "+(string)llRound(gfRange)+"m, rez distance is now "+(string)llRound(gvOffset.x)+"m.");
       llListenRemove(listen0);
   }}}
   sensor(integer num){
       integer x;
       integer i;
       for(i=0;i<num;i++){if(llDetectedOwner(i)!=llGetOwner()){ // if not the owner's
           if(llVecMag(llDetectedVel(i))>gfTolerance){ //if moving
           //if(llVecDist(llGetPos(),llDetectedPos(i))>=gvOffset.x){
           if(llVecDist(llGetPos(),llDetectedPos(i))<=(gvOffset.x*PI)){ //*2
           if(llVecDist(llGetPos(),llDetectedPos(i))<gvOffset.x){ // inner shield //
               vector vCloseOffset=<((llVecMag(llGetPos()-llDetectedPos(i)))/1),0,0>; ///pos/2
               if(llVecDist(llGetPos(),llGetPos()+(<vCloseOffset.x,0,0>*llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos())))>gfInnerLimit){
                   // Inner shield
                   llRezObject("Shield panel",
                   llGetPos()+(<vCloseOffset.x-0.375,0,0>*llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos())),
                   ZERO_VECTOR,
                   llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos()),4
                   );
                   // Outer shield
                   llRezObject("Shield panel",
                   llGetPos()+(<vCloseOffset.x-0.25,0,0>*llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos())),
                   ZERO_VECTOR,
                   llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos()),4
                   );
                   return;
               }
           }}
           if(llVecMag(llDetectedVel(i))>gfTolerance){ // perimeter shield
               llRezObject("Shield panel",
                   llGetPos()+(gvOffset*llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos())),
                   ZERO_VECTOR,
                   llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos()),
                   4);
                   llRezObject("Shield panel",
                   llGetPos()+((gvOffset+<0.125,0,0>)*llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos())),
                   ZERO_VECTOR,
                   llGetRot()*llRotBetween(<1.33,0,0>*llGetRot(),llDetectedPos(i)-llGetPos()),
                   4);
               } // distance check
           } // moving check
       }} // loop and owner check
   }

}