Jump to content

help using Json multi sit array with specified animation


LamyaeNeferati
 Share

You are about to reply to a thread that has been inactive for 1412 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

hello, i'm trying to set a bed with JSON multisit array, therefore i've to use a lying anim instead of default sit. With using following script i ve an issue where only the first avi to sit uses the correct animation. Others avi are only using the default sit anim :/

//multi sit prim using Json Arrays (expects 6 seats)
//written by To-mos Codewarrior(tomos.halsey)
string SEATS_data;
list getFreeSeat()
{
string avi;integer i=llGetNumberOfPrims();
list avatarCheck;list sittingAvis;
integer listIndex;string newAvi;
integer newAviFlag=FALSE;
//get current avatars on seat
for (;i--;)
{
if(llGetAgentSize(llGetLinkKey(i+1)) != ZERO_VECTOR)
{
avatarCheck += [llGetLinkKey(i+1)];
}
}
//llOwnerSay("Current Avatars: "+llList2CSV(avatarCheck));
//run garbage cleaning loop to dump dead keys
//and store the existing ones for checking
i=2;
for(;i--;)
{
avi=llJsonGetValue(SEATS_data,["seat"+(string)i,"key"]);
if(avi!="empty")
{//if avi isn't on the list set it to empty
listIndex=llListFindList(avatarCheck,[(key)avi]);
if(!~listIndex)
SEATS_data=llJsonSetValue(SEATS_data,["seat"+(string)i,"key"],"empty");
else
sittingAvis+=avi;
}
}
//identify the new key
i=llGetListLength(avatarCheck);
for(;i--;)
{
listIndex=llListFindList(sittingAvis,[llList2String(avatarCheck,i)]);
if((!~listIndex)&&!newAviFlag)
{
newAviFlag=TRUE;
newAvi=llList2String(avatarCheck,i);
//llOwnerSay("The new avatar is: "+newAvi);
}
}
//check their numbers
if(llGetListLength(avatarCheck)>6)
{
if(newAvi!="")
llSay(0,"Too many avatars are on me, please get off "+llKey2Name(newAvi));
else
llSay(0,"More avatars need to get off me.");
return ["full"];
}
//no need to go further after cleaning
//up the array and have empty newAvi
if(newAvi=="")return ["none"];
//llOwnerSay("New avatar is: "+(string)newAvi);
//now find first instance of empty to dump the new key
//reset the new avi flag for the next loop
newAviFlag=FALSE;
i=2;
for(;i--;)
{
avi=llJsonGetValue(SEATS_data,["seat"+(string)i,"key"]);
if(avi=="empty"&&!newAviFlag)
{
SEATS_data=llJsonSetValue(SEATS_data,["seat"+(string)i,"key"],(string)newAvi);
//just use avatarCheck list as a temp variable for the output
avatarCheck=[llJsonGetValue(SEATS_data,["seat"+(string)i,"pos"]),llJsonGetValue(SEATS_data,["seat"+(string)i,"twist"])];
newAviFlag=TRUE;
}
}
return avatarCheck;
}
default
{
state_entry()
{
SEATS_data=llList2Json(JSON_OBJECT,
[
"seat0",llList2Json(JSON_OBJECT,["key","empty","pos",<0.35, 0.25,-0.05>,"twist",3*PI/2]), //left
"seat1",llList2Json(JSON_OBJECT,["key","empty","pos",<-0.35, 0.25,-0.05>,"twist",3*PI/2]) //right
]);
llSetClickAction(CLICK_ACTION_SIT);
llSitTarget(<0.0,0.0,0.1>,ZERO_ROTATION);
}
changed(integer change)
{
if(change & CHANGED_LINK)
{
list output=getFreeSeat();
if(output!=["full"]&&output!=["none"])
{
llSetLinkPrimitiveParamsFast(llGetNumberOfPrims(),[PRIM_POS_LOCAL,(vector)llList2String(output,0),PRIM_ROT_LOCAL,llEuler2Rot(<0.0,0.0,llList2Float(output,1)>)]);
}
}
if (llAvatarOnSitTarget() != NULL_KEY)
llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION);
}

run_time_permissions(integer perm) {
string anim = "sleeping - on back, arms under head";
llStopAnimation("sit");
llStartAnimation(anim);
}
}

is anybody able to help me to debug this issue? Please.

Link to comment
Share on other sites

You might want to ask for this to be moved to the Scripting forum, since it's really a scripting question, and scripting and animating are two separate specialties 

Also, it would be a lot easier to advise you with the original script available.    You've clearly removed parts of it (that getFreeSeat() routine never gets called, for example, and you never do anything with SEATS-data).    I suspect the original needs only minor changes to make it work for you.

ETA.   I've now found the original script in the wiki.   As it stands, it's not really designed for what you want to do.   It's more an example of how to position the avatars rather than to animate them.   It also has to be installed in a child prim.

if you really want to use it, I'd start with the original, uncut, version and then, in the changed event,  put something like this:

	if(change & CHANGED_LINK)		{			list output=getFreeSeat();			if(output!=["full"]&&output!=["none"])				llSetLinkPrimitiveParamsFast(llGetNumberOfPrims(),[PRIM_POS_LOCAL,(vector)llList2String(output,0),PRIM_ROT_LOCAL,llEuler2Rot(<0.0,0.0,llList2Float(output,1)>)]);			//lines below added by Innula			key k = llGetLinkKey(llGetNumberOfPrims());//get the uuid of the last prim in the linkset			if(llGetAgentSize(k)!=ZERO_VECTOR){//if the uuid is that of an avatar (i.e. someone is sitting on me				llRequestPermissions(k, PERMISSION_TRIGGER_ANIMATION);//ask to animate it			}		}

 then start the animation in the run_time_permissions event.   

This uses the fact that, if one or more avatars are sitting on an object, llGetLinkKey(llGetNumberOfPrims()) returns the UUID of the last one to sit down.   

 

Link to comment
Share on other sites

  • 5 years later...

Hi , I found this thread while googling . I did  make a script to do this once upon a time but its lost in an object in my inventory . I realise this is several years ago that you asked but felt it needed a reply. The premiss of the script you borrowed uses JSON table to assign seats and keys . The animation you set only applies to one avatar as you do not record  in the json array seperate animations used by each avatar with each key.   As Inula says its not written with animation in mind but it could be used as a frame work to get you were you need to be. If i find it I will post it for you  alllon secondlife .

Denise

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1412 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...