User:Cow Taurog/Teleporter

From Second Life Wiki
Jump to navigation Jump to search

This script makes a simple teleporter that will warp to anywhere in the sim, provided your objects are allowed to cross property lines. Create an object to use as a teleport beam, make sure it is temporary and phantom, and drop the second script inside. Take it back into your inventory. To change the script, you'll have to make a new one, or rez it and then stop the script rather fast before it deletes itself. Once you've got your teleport beam, drop it inside the object you want to use as the teleporter, then drop the first script inside there also. There are a couple of destinations already programmed in, but these are just examples. Once a destination is chosen, the teleporter will scan to see if there is already a beam in place. If there is, it will wait for 5 seconds, and scan again. Once the area is clear, it will rez another beam.

Teleporter

<lsl> integer giDialog=9126; //Change both of these to something unique, match the script below to these integer giTPChan=-92760; // vector gvOffset=<0,0,0.25>; // Offset to add to the destination vector gvRezOffset=<0,0,1.5>; // How far away to rez the TP beam float gfTimeout=20; // How long to wait before killing the listen string gsMain="Pick a destination..."; list glDestName=["Sky","Ground"]; list glDestPos=["<128,128,1000>","<128,128,1>"]; vector gvDest; integer listen0; key gkId; mainmenu(){

   llSetTimerEvent(gfTimeout);
   listen0=llListen(giDialog,"","","");
   llDialog(gkId,gsMain,glDestName,giDialog);

}

default{

   on_rez(integer param){llResetScript();}
   timer(){gkId="";llListenRemove(listen0);}
   touch_start(integer num){
       gkId=llDetectedKey(num-1);
       mainmenu();
   }
   listen(integer chan,string name,key id,string mess){
       gkId=id;
       if(llListFindList(glDestName,[mess])!=-1){
           gvDest=(vector)llList2String(glDestPos,llListFindList(glDestName,[mess]));
           llSensor("TP","",SCRIPTED,10,PI);
       }
   }
   sensor(integer num){llSleep(5);llSensor("TP","",SCRIPTED,10,PI);}
   no_sensor(){
       llRezObject("TP",llGetPos()+gvRezOffset,ZERO_VECTOR,ZERO_ROTATION,0);
       llSleep(0.2);
       llSay(giTPChan,(string)(gvDest+gvOffset));
       gkId="";
       gvDest=ZERO_VECTOR;
       llListenRemove(listen0);
   }

} </lsl>

Teleport beam

This script will listen on a given channel for a position. Once a valid position is heard, it will warp there once it is sat upon (click type is also sit, not touch). Once it is there, or once it has been sitting around for too long, it will die. The range of this object is around 4000m in one jump, anything beyond that will use normal llSetPos movement after the initial jump. <lsl> integer giTPChan=-92760; // change this to match the script above float gfTimeout=30; float gfPostTimeout=0.2; float gfGlow=0.2; float gfAlpha=0.85; vector gvSitTarget=<0,0,0.1>; vector gvDest; vector gvOrigin; integer listen0; warpPos(vector destpos){if(destpos!=ZERO_VECTOR){

   integer jumps=(integer)(llVecDist(destpos,llGetPos())/10)+1;
   if(jumps>411){jumps=411;}list rules=[PRIM_POSITION,destpos];integer count=1;
   while((count=count<<1)<jumps){rules=(rules=[])+rules+rules;}
   llSetPrimitiveParams((rules=[])+rules+llList2List(rules,(count-jumps)<<1,count)); 
   if(llVecDist(llGetPos(),destpos)>0.001){while(--jumps){llSetPos(destpos);}}

}} default{

   on_rez(integer param){llResetScript();}
   state_entry(){
       llSetTimerEvent(gfTimeout);
       llSetStatus(STATUS_PHANTOM,TRUE);
       llSitTarget(gvSitTarget,ZERO_ROTATION);
       gvOrigin=llGetPos();
       llSetClickAction(CLICK_ACTION_SIT);
       listen0=llListen(giTPChan,"","","");
   }
   listen(integer chan,string name,key id,string mess){if((vector)mess!=ZERO_VECTOR){
       gvDest=(vector)mess;
       state running;
   }}
   timer(){
       llDie();
   }  

} state running{

   state_entry(){
       llSetSitText("Teleport");
       llSetAlpha(gfAlpha,ALL_SIDES);
       llSetPrimitiveParams([PRIM_GLOW,ALL_SIDES,gfGlow]);
       llSetTimerEvent(gfTimeout);
   }
   on_rez(integer param){
       llSitTarget(gvSitTarget,ZERO_ROTATION);
       llSetTimerEvent(gfTimeout);
   }
   changed(integer change){
       key agent=llAvatarOnSitTarget();
       if(change&CHANGED_LINK){if(agent){
           if(gvDest!=gvOrigin){if(gvDest!=ZERO_VECTOR){
               llSetAlpha(0,ALL_SIDES);
               warpPos(gvDest);
               llSleep(gfPostTimeout);
               llDie();
           }}
       }}
   }
   timer(){
       llDie();
   }  

} </lsl>