Two Avatars on single prim
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
Here are the basic scripts: modified for two avatars on single prim
MASTER <lsl> integer lastnum; key firstavatar; key secondavatar; string animation; integer num; integer firstnum; integer secondnum; integer originalprims;
//NOTE: An avatar is a CHILD prim, 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 // October 5th 2013 Pale Janus & Cay Trudeau
default {
on_rez(integer flag) { do { llResetScript(); } while (TRUE); }
state_entry() { animation = llGetInventoryName(INVENTORY_ANIMATION,0); 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 llSetSitText("Sit"); llSetClickAction(CLICK_ACTION_SIT); lastnum=llGetNumberOfPrims(); originalprims=llGetNumberOfPrims(); llSetCameraEyeOffset(<-1, 0, 1> * <0.0, 0.0, 0.0, 0.0>); llSetCameraAtOffset(<3, 0, 1> * <0.0, 0.0, 0.0, 0.0>); }
changed(integer change) { if ( change & CHANGED_REGION_START) do { llResetScript(); } while (TRUE);
if (change & CHANGED_LINK) { num = llGetNumberOfPrims(); // Below is where all the magic happens if (num > originalprims) // New avatar sitting down { if (num > originalprims && num < originalprims + 2) // 1st avatar sitting { firstnum = llGetNumberOfPrims(); firstavatar = llGetLinkKey(firstnum); //the avatar's UUID (cannot use llGetKey(llAvatarOnSitTarget) bc two avatars) 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>,PRIM_ROT_LOCAL,ZERO_ROTATION]); // < -front + back , -right + left, -down + up > llSitTarget(ZERO_VECTOR,ZERO_ROTATION); //releasing the sit target for next avatar lastnum = firstnum; }//1st avatar sitting end if ( num > originalprims + 1 )// second avatar sitting { secondnum = num; lastnum = secondnum; // Cay added this llMessageLinked(LINK_THIS,200,(string)secondnum,""); //sends key }//second avatar sitting end } // (num > originalprims && num < originalprims + 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);
if ( num > originalprims && num < originalprims + 2 ) { llSitTarget(<0.8, -1.05, -0.2>, llEuler2Rot( <0 * DEG_TO_RAD, 0 * DEG_TO_RAD, 0 * DEG_TO_RAD> ) );
// llMessageLinked(LINK_THIS,1111,"whostoodup",""); //This is a hint for how to make an edition for multiple avatars ;) 1111 being a channel to all slaves } } lastnum = num; } }
run_time_permissions(integer perm) { if (perm == PERMISSION_TRIGGER_ANIMATION ) { llStopAnimation("sit"); llSleep(0.1); llStartAnimation(animation); } }
}//state default
</lsl>
SLAVE <lsl>
integer lastnum;
integer avatarcount = 0; key coavatar; string animation; string whostoodup;
key secondavatar;
// October 5th 2013 Pale Janus & Cay Trudeau
integer secondnum;
default {
on_rez(integer flag) { do { llResetScript(); } while (TRUE); }
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 animation = llGetInventoryName(INVENTORY_ANIMATION,0); lastnum=llGetNumberOfPrims(); }
link_message(integer sender, integer num, string str, key id) { if(num == 1111) //someone just stood up { whostoodup = str; }
if(num == 200) //received 2nd avatar key
// when making multiple avatar scipring, a new slave will have different num, fe. third script would have num == 300 a fourth num ==400 etc.
{ 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>,PRIM_ROT_LOCAL,ZERO_ROTATION]); // < -front + back , -right + left, -down + up > llSitTarget(ZERO_VECTOR,ZERO_ROTATION); //releasing the sit target for next avatar // llMessageLinked(LINK_THIS,300,"2nd avatar sat down",""); // We message the third script }//200 }
run_time_permissions(integer perm) { if (perm == PERMISSION_TRIGGER_ANIMATION) { llStopAnimation("sit"); llSleep(0.1); llStartAnimation(animation); }
}
} </lsl>