Two Avatars on single prim: Difference between revisions
Cay Trudeau (talk | contribs) mNo edit summary |
Cay Trudeau (talk | contribs) No edit summary |
||
| Line 23: | Line 23: | ||
integer secondnum; | integer secondnum; | ||
integer originalprims; | 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 | //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 | ||
// October 5th 2013 Pale Janus & Cay Trudeau | // October 5th 2013 Pale Janus & Cay Trudeau | ||
| Line 53: | Line 54: | ||
{ | { | ||
num = llGetNumberOfPrims(); | num = llGetNumberOfPrims(); | ||
// Below is where all the magic happens | // Below is where all the magic happens | ||
if (num > originalprims) | if (num > originalprims) // New avatar sitting down | ||
{ | { | ||
if (num > originalprims && num < originalprims + 2) | if (num > originalprims && num < originalprims + 2) // 1st avatar sitting | ||
{ | { | ||
firstnum = llGetNumberOfPrims(); | firstnum = llGetNumberOfPrims(); | ||
firstavatar = llGetLinkKey(firstnum);//the avatar's UUID (cannot use llGetKey(llAvatarOnSitTarget) bc two avatars) | firstavatar = llGetLinkKey(firstnum); //the avatar's UUID (cannot use llGetKey(llAvatarOnSitTarget) bc two avatars) | ||
llRequestPermissions(firstavatar,PERMISSION_TRIGGER_ANIMATION); | llRequestPermissions(firstavatar,PERMISSION_TRIGGER_ANIMATION); | ||
| Line 72: | Line 72: | ||
llSitTarget(ZERO_VECTOR,ZERO_ROTATION); //releasing the sit target for next avatar | llSitTarget(ZERO_VECTOR,ZERO_ROTATION); //releasing the sit target for next avatar | ||
lastnum = firstnum; | lastnum = firstnum; | ||
}//1st avatar sitting end | }//1st avatar sitting end | ||
if ( num > originalprims + | if ( num > originalprims + 1 )// second avatar sitting | ||
{ | { | ||
secondnum = num; | secondnum = num; | ||
lastnum = secondnum; // Cay added this | lastnum = secondnum; // Cay added this | ||
llMessageLinked(LINK_THIS,200,(string)secondnum,""); //sends key | llMessageLinked(LINK_THIS,200,(string)secondnum,""); //sends key | ||
}//second avatar sitting end | |||
} // num > | } // (num > originalprims && num < originalprims + 2) end | ||
| Line 99: | Line 96: | ||
{ | { | ||
llStopAnimation(animation); | llStopAnimation(animation); | ||
if ( num > originalprims && num < originalprims + | |||
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> ) ); | 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",""); | |||
// llMessageLinked(LINK_THIS,500,"1st avatar stood up",""); //This is a hint for how to make an edition for multiple avatars ;) | |||
} | } | ||
} | } | ||
| Line 158: | Line 157: | ||
link_message(integer sender, integer num, string str, key id) | link_message(integer sender, integer num, string str, key id) | ||
{ | { | ||
if(num == 200) //received 2nd avatar key | |||
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; | secondnum = (integer)str; | ||
secondavatar = llGetLinkKey(secondnum); | secondavatar = llGetLinkKey(secondnum); | ||
llRequestPermissions(secondavatar,PERMISSION_TRIGGER_ANIMATION); | llRequestPermissions(secondavatar,PERMISSION_TRIGGER_ANIMATION); | ||
//This is where we determine the avatar's sitting position | //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 > | llSetLinkPrimitiveParamsFast(secondnum,[PRIM_POS_LOCAL,<0.0, 0.8, -0.2>,PRIM_ROT_LOCAL,ZERO_ROTATION]); // < -front + back , -right + left, -down + up > | ||
| Line 170: | Line 171: | ||
llSitTarget(ZERO_VECTOR,ZERO_ROTATION); //releasing the sit target for next avatar | 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 | |||
Revision as of 06:28, 5 October 2013
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;
integer avatarcount = 0; key firstavatar; key secondavatar; string animation; integer num; integer firstnum; 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 // October 5th 2013 Pale Janus & Cay Trudeau
default {
on_rez(integer flag) { do { llResetScript(); } while (TRUE); }
state_entry()
{
//avatarcount = 0;
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,500,"1st avatar stood up",""); //This is a hint for how to make an edition for multiple avatars ;)
}
}
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;
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 == 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>