Difference between revisions of "Pointing Stick"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Made this to point at folk when its their turn at games lolz right. the useful tidbit is how it  goes in the direction of what ever angle its pointing in.
Made this to point at folk when its their turn at games lolz right. the useful tidbit is how it  goes in the direction of what ever angle its pointing in.


Line 6: Line 5:


   
   
<lsl>
<source lang="lsl2">
integer switch = TRUE;
integer switch = TRUE;
key user;
key user;
Line 13: Line 12:
{
{
     state_entry()
     state_entry()
     {
     {
    vector goal = <90,0,90>;
        vector goal = <90, 0, 90>;
   
        llSetRot(llEuler2Rot(goal*DEG_TO_RAD));
      llSetRot(llEuler2Rot(goal*DEG_TO_RAD));
        llSetText("Touch to activate", <0,1,0>, 1);
      llSetText("Touch to activate",<0,1,0>,1);
     
     }
     }
 
    on_rez(integer x)
  changed(integer change)
  {
      if(change & (CHANGED_OWNER | CHANGED_INVENTORY))
          llResetScript();
  }
       
on_rez(integer x)
      {
          llResetScript();
   
}    touch_start(integer y)
     {
     {
      if (switch == TRUE)
        llResetScript();
      {
          user = llDetectedKey(0);
          llRequestPermissions(user,
              PERMISSION_TAKE_CONTROLS);
              switch = FALSE;
              llSetText("Touch to Release Controls",<1,0,0>,1);
     }
     }
     else if (switch == FALSE)
     touch_start(integer y)
     {
     {
     
        if (switch)
         llReleaseControls();
         {
      switch = TRUE;
            user = llDetectedKey(0);
        llRegionSayTo(user,0,"Controls Released");
            llRequestPermissions(user, PERMISSION_TAKE_CONTROLS);
        llSetText("Touch to activate",<0,1,0>,1);    
            llSetText("Touch to Release Controls", <1,0,0>, 1);
        }
        else
        {
            if (llDetectedKey(0) != user)    return;
            llReleaseControls();
            llRegionSayTo(user, 0, "Controls Released");
            llSetText("Touch to activate", <0,1,0>, 1);
        }
        switch = !switch;
     }
     }
     run_time_permissions(integer perm)
     run_time_permissions(integer perm)
     {
     {
         if (perm & PERMISSION_TAKE_CONTROLS)
         if (perm & PERMISSION_TAKE_CONTROLS)
    {
        {
             llTakeControls( CONTROL_FWD|CONTROL_BACK|CONTROL_ROT_LEFT|CONTROL_ROT_RIGHT|CONTROL_UP|CONTROL_DOWN,TRUE,FALSE);
             llTakeControls( CONTROL_FWD|CONTROL_BACK|CONTROL_ROT_LEFT|CONTROL_ROT_RIGHT|CONTROL_UP|CONTROL_DOWN,TRUE,FALSE);
  }
        }
}      
    }
   
     control(key id, integer level, integer edge)
     control(key id, integer level, integer edge)
     {
     {
         
        if (level & CONTROL_UP)
      if (level & CONTROL_UP)
        {
          {
            llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,0,0.20> ]);
         
        }
          llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0.0,0.0,00.20> ]);
        if (level & CONTROL_DOWN)
        {
            llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,0,-0.20> ]);
        }
        if (level & CONTROL_FWD)
        {
            llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,0,0.20> * llGetLocalRot()]);
        }
        if (level & CONTROL_BACK)
        {
            llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,0,-0.20> * llGetLocalRot()]);
        }
        if(level & CONTROL_ROT_LEFT)
        {
            llSetLinkPrimitiveParamsFast(-4,[PRIM_ROT_LOCAL, llGetLocalRot() * llEuler2Rot(<0,0,4>*DEG_TO_RAD)]);
         }
         }
         
         if (level& CONTROL_ROT_RIGHT)
        if (level & CONTROL_DOWN)
      {
       
          llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0.0,00.0,-0.20> ]);   
    }
          
     
    if (level & CONTROL_FWD)
         {
         {
          llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,00,0.20> * llGetLocalRot()]);
            llSetLinkPrimitiveParamsFast(-4,[PRIM_ROT_LOCAL, llGetLocalRot() * llEuler2Rot(<0,0,-4>*DEG_TO_RAD)]);
        }
     }
     }
      if (level & CONTROL_BACK)
    {
          llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,00,-0.20> * llGetLocalRot()]);
}
    if(level & CONTROL_ROT_LEFT)
  {
                llSetLinkPrimitiveParamsFast(-4,[PRIM_ROT_LOCAL, llGetLocalRot() * llEuler2Rot(<0,0,4>*DEG_TO_RAD)]);
}
    if (level& CONTROL_ROT_RIGHT)
{
     
                llSetLinkPrimitiveParamsFast(-4,[PRIM_ROT_LOCAL, llGetLocalRot() * llEuler2Rot(<0,0,-4>*DEG_TO_RAD)]);
}
        }
     
   
   
}
}

Latest revision as of 22:28, 24 January 2015

Made this to point at folk when its their turn at games lolz right. the useful tidbit is how it goes in the direction of what ever angle its pointing in.



<source lang="lsl2"> integer switch = TRUE; key user;

default {

   state_entry()
   {
       vector goal = <90, 0, 90>;
       llSetRot(llEuler2Rot(goal*DEG_TO_RAD));
       llSetText("Touch to activate", <0,1,0>, 1);
   }
   on_rez(integer x)
   {
       llResetScript();
   }
   touch_start(integer y)
   {
       if (switch)
       {
           user = llDetectedKey(0);
           llRequestPermissions(user, PERMISSION_TAKE_CONTROLS);
           llSetText("Touch to Release Controls", <1,0,0>, 1);
       }
       else
       {
           if (llDetectedKey(0) != user)     return;
           llReleaseControls();
           llRegionSayTo(user, 0, "Controls Released");
           llSetText("Touch to activate", <0,1,0>, 1);
       }
       switch = !switch;
   }
   run_time_permissions(integer perm)
   {
       if (perm & PERMISSION_TAKE_CONTROLS)
       {
           llTakeControls( CONTROL_FWD|CONTROL_BACK|CONTROL_ROT_LEFT|CONTROL_ROT_RIGHT|CONTROL_UP|CONTROL_DOWN,TRUE,FALSE);
       }
   }
   control(key id, integer level, integer edge)
   {
       if (level & CONTROL_UP)
       {
           llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,0,0.20> ]);
       }
       if (level & CONTROL_DOWN)
       {
           llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,0,-0.20> ]);
       }
       if (level & CONTROL_FWD)
       {
           llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,0,0.20> * llGetLocalRot()]);
       }
       if (level & CONTROL_BACK)
       {
           llSetLinkPrimitiveParamsFast(-4,[ PRIM_POSITION, llGetPos() +<0,0,-0.20> * llGetLocalRot()]);
       }
       if(level & CONTROL_ROT_LEFT)
       {
           llSetLinkPrimitiveParamsFast(-4,[PRIM_ROT_LOCAL, llGetLocalRot() * llEuler2Rot(<0,0,4>*DEG_TO_RAD)]);
       }
       if (level& CONTROL_ROT_RIGHT)
       {
           llSetLinkPrimitiveParamsFast(-4,[PRIM_ROT_LOCAL, llGetLocalRot() * llEuler2Rot(<0,0,-4>*DEG_TO_RAD)]);
       }
   }

}