Difference between revisions of "Two Avatars on single prim"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(10 intermediate revisions by 2 users not shown)
Line 7: Line 7:


This is a modification of Pale Janus's script, originally posted here: [http://forums.osgrid.org/viewtopic.php?f=5&t=4799 OsGrid]
This is a modification of Pale Janus's script, originally posted here: [http://forums.osgrid.org/viewtopic.php?f=5&t=4799 OsGrid]
<pre>
DISCLAIMER:
    Do note, that in a linkset other child prims may move if you are not careful when setting this up.
    That means you have to tell the script how many prims is normal for your linkset and reset all scripts before testing.
</pre>


Here are the basic scripts: modified for two avatars on single prim
Here are the basic scripts: modified for two avatars on single prim
Line 12: Line 20:




MASTER
=== MASTER SCRIPT: ===
<lsl>
<source lang="lsl2">
  integer lastnum;  
//  October 5th 2013 Pale Janus & Cay Trudeau
integer avatarcount = 0;
 
key firstavatar;
//  NOTE:
key secondavatar;
//      An avatar counts as a child prim within a linkset, if you wish to move
string animation;
//      it after it has sat down, you need to know what her prim number is and
//      use llSetLinkPrimitiveParamsFast to move her
 
integer lastnum;
 
key     firstavatar;
key     secondavatar;
 
string animation;
 
integer num;
integer num;
integer firstnum;
integer firstnum;
integer secondnum;
integer secondnum;
integer originalprims;
 
//NOTE: An avatar is a CHILD prim, íf you wish to move it after it has sat down, you need to know what her prim number is and use llSetLinkPrimitiveParamsFast to move her
integer originalprims;


default
default
{
{
     on_rez(integer flag) { do { llResetScript(); } while (TRUE); }
     on_rez(integer start_param)
    {
        llResetScript();
    }


     state_entry()
     state_entry()
     {
     {
        //avatarcount = 0;
         animation = llGetInventoryName(INVENTORY_ANIMATION, 0);
       
 
         animation = llGetInventoryName(INVENTORY_ANIMATION,0);
//      do not remove the position offset of the sit target
         llSitTarget(<1,1,1>, llEuler2Rot( <0 * DEG_TO_RAD, 0 * DEG_TO_RAD, 0 * DEG_TO_RAD> ) ); // there has to be something as sit target here, or else  llSetLinkPrimitiveParamsFast fails
         llSitTarget(<1.0, 1.0, 1.0>, llEuler2Rot(ZERO_VECTOR*DEG_TO_RAD));
 
         llSetSitText("Sit");
         llSetSitText("Sit");
         llSetClickAction(CLICK_ACTION_SIT);
         llSetClickAction(CLICK_ACTION_SIT);
   
 
         lastnum=llGetNumberOfPrims();
         lastnum       = llGetNumberOfPrims();
         originalprims=llGetNumberOfPrims();
         originalprims = llGetNumberOfPrims();//  you can set this value to your unsitted object
     
 
         llSetCameraEyeOffset(<-1, 0, 1> *  <0.0, 0.0, 0.0, 0.0>);
         llSetCameraEyeOffset(<-1.0, 0.0, 1.0> * ZERO_ROTATION);
         llSetCameraAtOffset(<3, 0, 1> *  <0.0, 0.0, 0.0, 0.0>);
         llSetCameraAtOffset(< 3.0, 0.0, 1.0> * ZERO_ROTATION);
     }
     }


     changed(integer change)
     changed(integer change)
     {
     {
         if ( change &  CHANGED_REGION_START) do { llResetScript(); } while (TRUE);
         if (change &  CHANGED_REGION_START)
        {
            llResetScript();
            return;
        }


         if (change & CHANGED_LINK)
         if (change & CHANGED_LINK)
         {  
         {
             num = llGetNumberOfPrims();
             num = llGetNumberOfPrims();
      //  llOwnerSay((string)avatarcount);
 
        // llOwnerSay((string)num);
//         below is where all the magic happens
           
             if (num > originalprims)//  New avatar sitting down
            // Below is where all the magic happens
             if (num > originalprims) //(num > lastnum && avatarcount < 2) // New avatar sitting down
             {
             {
                 if (num > originalprims && num < originalprims + 2)         //(avatarcount < 1) // 1st avatar sitting
//              1st avatar sitting
                 if (num > originalprims && num < (originalprims + 2))
                 {
                 {
                      firstnum = llGetNumberOfPrims();
                    firstnum   = llGetNumberOfPrims();
                    firstavatar = llGetLinkKey(firstnum);//the avatar's UUID (cannot use llGetKey(llAvatarOnSitTarget) bc two avatars)
//                 the avatar's UUID (cannot use llGetKey(llAvatarOnSitTarget) because two avatars)
                  llSay(0,(string)firstavatar);
                    firstavatar = llGetLinkKey(firstnum);
                     
 
                    llRequestPermissions(firstavatar,PERMISSION_TRIGGER_ANIMATION);
                    llRequestPermissions(firstavatar, PERMISSION_TRIGGER_ANIMATION);
                   
 
            //This is where we determine the avatar's sitting position
//                 this is where we determine the avatar's sitting position
            llSetLinkPrimitiveParamsFast(firstnum,[PRIM_POS_LOCAL,<0.0, -0.8, 0.2>,PRIM_ROT_LOCAL,ZERO_ROTATION]); // < -front + back , -right + left, -down + up >
                    llSetLinkPrimitiveParamsFast(firstnum, [
                   
                        PRIM_POS_LOCAL, <0.0,-0.8, 0.2>,// < -front + back , -right + left, -down + up >
                     llSitTarget(ZERO_VECTOR,ZERO_ROTATION); //releasing the sit target for next avatar
                        PRIM_ROT_LOCAL, ZERO_ROTATION]);
                   
 
                     lastnum = firstnum; // Cay added this
                     llSitTarget(ZERO_VECTOR, ZERO_ROTATION);// releasing the sit target for next avatar
                    //avatarcount = //avatarcount + 1;
 
                  //  llMessageLinked(LINK_THIS,100,"1st avatar sat down","");
                     lastnum = llGetNumberOfPrims();
                  }//1st avatar sitting end
                }
               
//             2nd avatar sitting
                 
                if ( num > (originalprims + 1) )
               
                  if ( num > originalprims + 1 )//(avatarcount > 1) // second avatar sitting
                 {
                 {
                     secondnum = num;
                     secondnum = llGetNumberOfPrims();
                   
                     lastnum = llGetNumberOfPrims();
                     lastnum = secondnum; // Cay added this
 
                     //avatarcount = //avatarcount + 1;
                     llMessageLinked(LINK_THIS, 200, (string)secondnum, "");// sends key
                  llMessageLinked(LINK_THIS,200,(string)secondnum,""); //sends key
                }
                   
             }
                    llOwnerSay( "sending secondnum " + (string)secondnum);
//         standing up (I think this requires change upon the lastnum when the avatar sits, although it is mentioned at the bottom)
                  }//second avatar sitting end
            else if (num < lastnum)
           
           
             
                         
             } // num > lastnum && //avatarcount < 2 end
           
           
            else if (num < lastnum) //standing up ( I think this requires change upon the lastnum when the avatar sits, although it is mentioned at the bottom
             {
             {
                 llStopAnimation(animation);
                 llStopAnimation(animation);
            //avatarcount = //avatarcount - 1;
 
                 if ( num > originalprims && num < originalprims + 2 )//(avatarcount < 2)  
                 if ( num > originalprims && num < originalprims + 2 )
                 {
                 {
                 
                     llSitTarget(<0.8, -1.05, -0.2>, llEuler2Rot(ZERO_VECTOR*DEG_TO_RAD));
                     llSitTarget(<0.8, -1.05, -0.2>, llEuler2Rot( <0 * DEG_TO_RAD, 0 * DEG_TO_RAD, 0 * DEG_TO_RAD> ) );
 
                  // llMessageLinked(LINK_THIS,500,"1st avatar stood up","");
//                  next line is a hint for how to make an edition for multiple avatars ;) 1111 being a channel to all slaves
//                 llMessageLinked(LINK_THIS, 1111, "whostoodup", "");
                 }
                 }
                //avatarcount = //avatarcount - 1; 
             }
             }
         
 
             lastnum = num;
             lastnum = llGetNumberOfPrims();
         
         }
         }
     }
     }
Line 115: Line 129:
     run_time_permissions(integer perm)
     run_time_permissions(integer perm)
     {
     {
         if (perm == PERMISSION_TRIGGER_ANIMATION )      
         if (perm & PERMISSION_TRIGGER_ANIMATION)
         {
         {
             llStopAnimation("sit");
             llStopAnimation("sit");
             llSleep(0.1);
             llSleep(0.1);
             llStartAnimation(animation);
             llStartAnimation(animation);
                     
            }
         }
         }
    }
}
</source>


}//state default
=== SLAVE SCRIPT: ===
<source lang="lsl2">
// October 5th 2013 Pale Janus & Cay Trudeau


integer lastnum;
integer avatarcount;
key    coavatar;
string  animation;
string  whostoodup;


key    secondavatar;
integer secondnum;


</lsl>
SLAVE
<lsl>
    integer lastnum; 
integer avatarcount = 0;
key coavatar;
string animation;
key secondavatar;
integer secondnum;
default
default
{
{
     on_rez(integer flag) { do { llResetScript(); } while (TRUE); }
     on_rez(integer start_param)
    {
        llResetScript();
    }


     state_entry()
     state_entry()
     {
     {
          llSitTarget(<1,1,1>, llEuler2Rot( <0 * DEG_TO_RAD, 0 * DEG_TO_RAD, 0 * DEG_TO_RAD> ) ); // there has to be something as sit target here, or else  llSetLinkPrimitiveParamsFast fails
        llSitTarget(<1.0, 1.0, 1.0>, llEuler2Rot(ZERO_VECTOR*DEG_TO_RAD));
        animation = llGetInventoryName(INVENTORY_ANIMATION,0);
        animation = llGetInventoryName(INVENTORY_ANIMATION, 0);
         lastnum=llGetNumberOfPrims();
         lastnum   = llGetNumberOfPrims();
     }
     }
   


      
     link_message(integer sender_num, integer num, string str, key id)
      link_message(integer sender, integer num, string str, key id)
     {
     {
          llSay(0,"link message" + (string) num + " str " + (string)str);
//      someone just stood up
         if(num == 200) //received 2nd avatar key
        if(num == 1111)
        {
            whostoodup = str;
         }
 
//      when making multiple avatar sit arrangements,
//      a new slave will have different num for each,
//      third script would have num == 300, fourth script would have num ==400 etc.
 
//     received 2nd avatar key
        if (num == 200)
         {
         {
             secondnum = (integer)str;
             secondnum   = (integer)str;
             secondavatar = llGetLinkKey(secondnum);
             secondavatar = llGetLinkKey(secondnum);
                    llRequestPermissions(secondavatar,PERMISSION_TRIGGER_ANIMATION);
 
                    llSay(0,(string)secondnum);
            llRequestPermissions(secondavatar, PERMISSION_TRIGGER_ANIMATION);
            //This is where we determine the avatar's sitting position
 
             llSetLinkPrimitiveParamsFast(secondnum,[PRIM_POS_LOCAL,<0.0, 0.8, -0.2>,PRIM_ROT_LOCAL,ZERO_ROTATION]); // < -front + back , -right + left, -down + up >
//         this is where we determine the avatar's sitting position
                   
             llSetLinkPrimitiveParamsFast(secondnum, [
                    llSitTarget(ZERO_VECTOR,ZERO_ROTATION); //releasing the sit target for next avatar
                PRIM_POS_LOCAL, <0.0, 0.8, 0.2>,// < -front + back , -right + left, -down + up >
              
                PRIM_ROT_LOCAL, ZERO_ROTATION]);
           
 
           
//         releasing the sit target for next avatar
         
             llSitTarget(ZERO_VECTOR, ZERO_ROTATION);
         }//200
 
//          we message the third script
//          llMessageLinked(LINK_THIS, 300, "2nd avatar sat down", "");
         }
     }
     }
   
  //05.10.2013 16:10 to make master ans slave scripts, only one detects change
   
   
 


     run_time_permissions(integer perm)
     run_time_permissions(integer perm)
     {
     {
         if (perm == PERMISSION_TRIGGER_ANIMATION)      
         if (perm & PERMISSION_TRIGGER_ANIMATION)
         {
         {
             llStopAnimation("sit");
             llStopAnimation("sit");
             llSleep(0.1);
             llSleep(0.1);
             llStartAnimation(animation);
             llStartAnimation(animation);
         
         }
         }
     }
     }
 
}
}
</lsl>
</source>

Latest revision as of 10:08, 25 January 2015


Ever wondered how to make two or more avatars to sit on single prim, to save prim amount on a furniture?

You need two kinds of scripts; the master (which calculates avatars sitting down and standing up) and a slave script for each additional avatar.

This is a modification of Pale Janus's script, originally posted here: OsGrid


DISCLAIMER:
    Do note, that in a linkset other child prims may move if you are not careful when setting this up.
    That means you have to tell the script how many prims is normal for your linkset and reset all scripts before testing.


Here are the basic scripts: modified for two avatars on single prim


MASTER SCRIPT:

//  October 5th 2013 Pale Janus & Cay Trudeau

//  NOTE:
//      An avatar counts as a child prim within a linkset, if you wish to move
//      it after it has sat down, you need to know what her prim number is and
//      use llSetLinkPrimitiveParamsFast to move her

integer lastnum;

key     firstavatar;
key     secondavatar;

string  animation;

integer num;

integer firstnum;
integer secondnum;

integer originalprims;

default
{
    on_rez(integer start_param)
    {
        llResetScript();
    }

    state_entry()
    {
        animation = llGetInventoryName(INVENTORY_ANIMATION, 0);

//      do not remove the position offset of the sit target
        llSitTarget(<1.0, 1.0, 1.0>, llEuler2Rot(ZERO_VECTOR*DEG_TO_RAD));

        llSetSitText("Sit");
        llSetClickAction(CLICK_ACTION_SIT);

        lastnum       = llGetNumberOfPrims();
        originalprims = llGetNumberOfPrims();//  you can set this value to your unsitted object

        llSetCameraEyeOffset(<-1.0, 0.0, 1.0> * ZERO_ROTATION);
        llSetCameraAtOffset(< 3.0, 0.0, 1.0> * ZERO_ROTATION);
    }

    changed(integer change)
    {
        if (change &  CHANGED_REGION_START)
        {
            llResetScript();
            return;
        }

        if (change & CHANGED_LINK)
        {  
            num = llGetNumberOfPrims();

//          below is where all the magic happens
            if (num > originalprims)//  New avatar sitting down
            {
//              1st avatar sitting
                if (num > originalprims && num < (originalprims + 2))
                {
                    firstnum    = llGetNumberOfPrims();
//                  the avatar's UUID (cannot use llGetKey(llAvatarOnSitTarget) because two avatars)
                    firstavatar = llGetLinkKey(firstnum);

                    llRequestPermissions(firstavatar, PERMISSION_TRIGGER_ANIMATION);

//                  this is where we determine the avatar's sitting position
                    llSetLinkPrimitiveParamsFast(firstnum, [
                        PRIM_POS_LOCAL, <0.0,-0.8, 0.2>,//  < -front + back , -right + left, -down + up >
                        PRIM_ROT_LOCAL, ZERO_ROTATION]);

                    llSitTarget(ZERO_VECTOR, ZERO_ROTATION);//  releasing the sit target for next avatar

                    lastnum = llGetNumberOfPrims();
                }
//              2nd avatar sitting
                if ( num > (originalprims + 1) )
                {
                    secondnum = llGetNumberOfPrims();
                    lastnum = llGetNumberOfPrims();

                    llMessageLinked(LINK_THIS, 200, (string)secondnum, "");//  sends key
                 }
            }
//          standing up (I think this requires change upon the lastnum when the avatar sits, although it is mentioned at the bottom)
            else if (num < lastnum)
            {
                llStopAnimation(animation);

                if ( num > originalprims && num < originalprims + 2 )
                {
                    llSitTarget(<0.8, -1.05, -0.2>, llEuler2Rot(ZERO_VECTOR*DEG_TO_RAD));

//                  next line is a hint for how to make an edition for multiple avatars ;) 1111 being a channel to all slaves
//                  llMessageLinked(LINK_THIS, 1111, "whostoodup", "");
                }
            }

            lastnum = llGetNumberOfPrims();
        }
    }

    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStopAnimation("sit");
            llSleep(0.1);
            llStartAnimation(animation);
        }
    }
}

SLAVE SCRIPT:

//  October 5th 2013 Pale Janus & Cay Trudeau

integer lastnum;
integer avatarcount;
key     coavatar;
string  animation;
string  whostoodup;

key     secondavatar;
integer secondnum;

default
{
    on_rez(integer start_param)
    {
        llResetScript();
    }

    state_entry()
    {
        llSitTarget(<1.0, 1.0, 1.0>, llEuler2Rot(ZERO_VECTOR*DEG_TO_RAD));
        animation = llGetInventoryName(INVENTORY_ANIMATION, 0);
        lastnum   = llGetNumberOfPrims();
    }

    link_message(integer sender_num, integer num, string str, key id)
    {
//      someone just stood up
        if(num == 1111)
        {
            whostoodup = str;
        }

//      when making multiple avatar sit arrangements,
//      a new slave will have different num for each,
//      third script would have num == 300, fourth script would have num ==400 etc.

//      received 2nd avatar key
        if (num == 200)
        {
            secondnum    = (integer)str;
            secondavatar = llGetLinkKey(secondnum);

            llRequestPermissions(secondavatar, PERMISSION_TRIGGER_ANIMATION);

//          this is where we determine the avatar's sitting position
            llSetLinkPrimitiveParamsFast(secondnum, [
                PRIM_POS_LOCAL, <0.0, 0.8, 0.2>,//  < -front + back , -right + left, -down + up >
                PRIM_ROT_LOCAL, ZERO_ROTATION]);

//          releasing the sit target for next avatar
            llSitTarget(ZERO_VECTOR, ZERO_ROTATION);

//          we message the third script
//          llMessageLinked(LINK_THIS, 300, "2nd avatar sat down", "");
        }
    }

    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStopAnimation("sit");
            llSleep(0.1);
            llStartAnimation(animation);
        }
    }
}