Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Multiple sit on couch

Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
04-26-2009 23:06
Hi all,

i am making a couch with several pillows (all linked together)
People can sit on each pillow and if they touch the pillow they can change the animation.

i tried to place a script in each pillow to change the animation and so long it is
not linked it works fine but when linked the scripts interver with each other.
(touchpass = false but this don't work for the change event)

the question is how can i detected on which pillow someone is sitting?

So far i can see it has to be done in the change event because when someone
is sitting the touch event isn't triggered. (default action of the pillow is sit)

Or is it maybe better to make 1 master script that control all pillows but i don't
know how i can find out on which pillow someone is sitting.

or is there a better way to do this without using poseball?
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
04-27-2009 03:22
Store the last value of llAvatarOnSitTarget in a global. Then you can compare that with the new one, and be able to tell if that target has actually changed.
Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
04-27-2009 10:33
if i store the key i still not know on which pillow he/she is sitting.
there can me more then one avatar sitting on the couch.

The couch has at least 2 pillows that has to work independent of each other.

the problem i know have is when the first person sit it goes well but the 2th
person don't sit well (default sit in stead of the animation i use).
and if the 2th pillow is touch and change animation the 1th avatar moves to
the 2th pillow.

if it helps i can later put parts of the script here (i am now at work and don't have
the script with me)
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
04-27-2009 11:36
This is probably not the best solution, but you could have the main script keep a list, that is setup to be the size of how many pillows you have. When you get the message via a linked message, that the avatar has sat on the pillow, (have the linked message identify what pillow it is, and the avatar key) then store that avatar key in the appropriate place of the pillow list. Then when you get a toucher, just check to see if the person who touched the couch is in that list, if they are, then you know with the index, what pillow they are sitting on, and can change the animation.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
04-27-2009 11:45
From: Kaylan Draken
if i store the key i still not know on which pillow he/she is sitting.
there can me more then one avatar sitting on the couch.

How are you detecting avatars? Are you using a script for each position (the usual way)? Those are the places where you would put the globals, in each sit script.

If you are trying to control the sits from a single script, you can still use a list of the avatar keys to find who came and went.
Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
04-27-2009 12:15
thanks Victoria and Lazink,

For know i have a single script in each pillow. Think i make somewhere a think
error but i can't find it.
Below is part of the code maybe someone of you see what the error is.

string SitAnim; // String to hold the name of the animation
key Avi; // Key for detected avatar
integer Listen;
integer dialog_channel;
list MenuSit = ["1", "2", "3"];


// Functions
AvatarSit(vector POSITION, vector Rotdeg, integer iNrAnim)
{

if(Avi==llAvatarOnSitTarget())
{
llStopAnimation("sit";);
llStopAnimation(SitAnim);
SitAnim=llGetInventoryName(INVENTORY_ANIMATION,iNrAnim);
llSetLinkPrimitiveParams(iPrimsDefault +1, [PRIM_POSITION,llGetLocalPos()+
POSITION, PRIM_ROTATION, llEuler2Rot(Rotdeg*= DEG_TO_RAD)]);
llStartAnimation(SitAnim);
}
}

// STATES
default
{
state_entry()
{
dialog_channel = (integer)llRound(llFrand (1000000));
SitAnim=llGetInventoryName(INVENTORY_ANIMATION,0); //Load default animation
llSetClickAction(CLICK_ACTION_SIT);
llPassTouches(FALSE);
}

touch_start(integer num_detected)
{
Avi=llDetectedKey(0);
Listen=llListen (dialog_channel, "",Avi1, "";);
llSetTimerEvent(60);
llDialog (Avi1, "Make a choice ?", MenuSit, dialog_channel);
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
if (llAvatarOnSitTarget() != NULL_KEY)
{
llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION);
Avi=llAvatarOnSitTarget();
}
else
{
integer perm=llGetPermissions();
if ((perm & PERMISSION_TRIGGER_ANIMATION))
{
llStopAnimation("sit";);
llStopAnimation(SitAnim);
}
}
}
}
run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
AvatarSit( <0.25, 1.15, 0.0>, <0,180,180>, 0);
}
}

the listen event use also the AvatarSit function and the timer event only close the listen handle. Both pillow have the same script.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
04-27-2009 13:39
If looks like Avi is a global that gets recycled in the touch and changed events. You will need to set aside a separate one for use in the changed event, so it doesn't get clobbered elsewhere in the script.

So, let's make a new global:

key AviOnSeat;


And alter the changed event a little (holler if this is a little off, scribbled this down offline):

CODE

changed(integer change)
{
if (change & CHANGED_LINK)
{
key newAvi = llAvatarOnSitTarget();
if (AviOnSeat != newAvi) // is it really this prim that changed?
{
if (newAvi != NULL_KEY)
{
llRequestPermissions(newAvi, PERMISSION_TRIGGER_ANIMATION);
}
else
{
integer perm=llGetPermissions();
if ((perm & PERMISSION_TRIGGER_ANIMATION))
{
llStopAnimation("sit");
llStopAnimation(SitAnim);
}
}

AviOnSeat = newAvi; // store away for the next changed event
}
}
}
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
04-27-2009 19:08
Finishing this thought, sorry, today got busy. Now that you have the sitting avatar's key stored, you can compare that against llDetectedKey to decide what script gets to send out a dialog, and to whom. And with that it should be OK to let passes touch through, because you have something else to use as a filter.
Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
04-28-2009 09:28
Thanks Victoria :)
i will try your suggestion and will come later back on it.