Difference between revisions of "Two Avatars on single prim"
Cay Trudeau (talk | contribs) |
Cay Trudeau (talk | contribs) |
||
Line 4: | Line 4: | ||
You need two kinds of scripts; the master (which calculates avatars sitting down and standing up) | You need two kinds of scripts; the master (which calculates avatars sitting down and standing up) | ||
and a slave script for each additional avatar | and a slave script for each additional avatar. | ||
This is a modification of Pale Janus's script, originally posted here: [http://forums.osgrid.org/viewtopic.php?f=5&t=4799 OsGrid] | |||
Here are the basic scripts: modified for two avatars on single prim | Here are the basic scripts: modified for two avatars on single prim |
Revision as of 06:11, 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
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(); // llOwnerSay((string)avatarcount); // llOwnerSay((string)num); // 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 { firstnum = llGetNumberOfPrims(); firstavatar = llGetLinkKey(firstnum);//the avatar's UUID (cannot use llGetKey(llAvatarOnSitTarget) bc two avatars) llSay(0,(string)firstavatar); 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; // Cay added this //avatarcount = //avatarcount + 1; // llMessageLinked(LINK_THIS,100,"1st avatar sat down",""); }//1st avatar sitting end if ( num > originalprims + 1 )//(avatarcount > 1) // second avatar sitting { secondnum = num; lastnum = secondnum; // Cay added this //avatarcount = //avatarcount + 1; llMessageLinked(LINK_THIS,200,(string)secondnum,""); //sends key llOwnerSay( "sending secondnum " + (string)secondnum); }//second avatar sitting end } // 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); //avatarcount = //avatarcount - 1; if ( num > originalprims && num < originalprims + 2 )//(avatarcount < 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",""); } //avatarcount = //avatarcount - 1; } 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;
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) { llSay(0,"link message" + (string) num + " str " + (string)str); if(num == 200) //received 2nd avatar key { secondnum = (integer)str; secondavatar = llGetLinkKey(secondnum); llRequestPermissions(secondavatar,PERMISSION_TRIGGER_ANIMATION); llSay(0,(string)secondnum); //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 }//200 } //05.10.2013 16:10 to make master ans slave scripts, only one detects change
run_time_permissions(integer perm) { if (perm == PERMISSION_TRIGGER_ANIMATION) { llStopAnimation("sit"); llSleep(0.1); llStartAnimation(animation); }
}
} </lsl>