Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Can't get this to work for the life of me

Veldin Finesmith
Registered User
Join date: 27 Jun 2008
Posts: 16
06-29-2008 12:31
It's become painfully obvious that my scripting skills are nigh on nonexistent and I need some help :/

I have a script which I was trying to figure out for the last few hours (read 4ish) and now that I've got a migraine and ended up using a script from a scripting tutorial place that now kind of works, but not quite. So can someone please help me out here?

The idea is a chair with 4 sit animations in it. The person clicks the chair and a menu pops up giving them the choice of what sit animation they wish to use to sit down. The menu pops up, the people do a sit animation but NOT in the chair but on the ground right where they are, and worse they're stuck in that sit animation with no stand up button! /SIGH

I need the stand up button to show and for them to actually sit on the chair cushion.

CODE

integer MENU_CHANNEL = 333; // set a dialog channel
list MENU_MAIN = [ "Sit 1", "Sit 2", "Sit 3", "Sit 4" ];

string anim;

default
{
touch_start(integer total_number) //wait for an avatar to touch the chair
{
llSay(0, "Respond to the dialog box and then touch the chair again");
llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION); //ask permission to animate the avatar that touched the poster
state new;
}
}

state new
{

state_entry()
{
llListen(MENU_CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users
}

touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "What animation do you want your avatar to perform?", MENU_MAIN, MENU_CHANNEL); // present dialog on click
}

listen(integer channel, string name, key id, string message)
{
if ((llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)) //if animate permission has been given
{
if (message == "Sit 1")
{
anim = "sit g M";
llStartAnimation(anim);
llResetScript();
}

if (message == "Sit 2")
{
anim = "sit g F";
llStartAnimation(anim);
llResetScript();
}

if (message == "Sit 3")
{
anim = "meditation";
llStartAnimation(anim);
llResetScript();
}
if (message == "Sit 4")
{
anim = "bond6";
llStartAnimation(anim);
llResetScript();
}
}

if (! (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)) //if animate permission has not been given
{
llSay(0, "Agent has not given permission");
llResetScript();
}
}
}



// End of code;



Thank you for all assistance
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
06-29-2008 13:15
To reliably sit on an object it needs to be given a sit target using: llSitTarget

To get you started you might try: llSitTarget(<0, 0, 0.1>, ZERO_ROTATION); in state_entry(). I say: to get you started, because you'll probably then need to play with things to get your AV seated in a pleasing postion.
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
06-29-2008 14:59
The main problem is that you animate them before they have a chance to sit.

here is a commented version of one way to do what you require, warning untested in world.

[PHP
integer MENU_CHANNEL = -112233; // much better to use a large negative channel
list MENU_MAIN = [ "Sit 1", "Sit 2", "Sit 3", "Sit 4" ];

string anim = "sit g m"; //set up a default animation
integer handle; //handle for the listen
key av; //to store the key for the av

default
{
state_entry()
{
llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION);//set the sit target for the default animation

}

//First lets select the animation we want
touch_start(integer total_number)
{
av = llDetectedKey(0); //store the av
handle = llListen(MENU_CHANNEL, "", av, "";); //ONly start the listen when touched to prevent having an open listen
llSetTimerEvent(30.0); //set timer so we can kill the listen if no response
llDialog(av, "What animation do you want your avatar to perform?", MENU_MAIN, MENU_CHANNEL); //then ask the question

}

//Then wait for the reply
listen(integer channel, string name, key id, string message)
{
if (message == "Sit 1";)
{
anim = "sit g M"; //store the selected animation
llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION);//set the sit target for the animation
}
else if (message == "Sit 2";)
{
anim = "sit g F";
llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION);//set the sit target for the animation
}
else if (message == "Sit 3";)
{
anim = "meditation";
llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION);//set the sit target for the animation
}
else if (message == "Sit 4";)
{
anim = "bond6";
llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION);//set the sit target for the animation
}
llListenRemove(handle); //remove the listener
llSetTimerEvent(0.0);
}

timer()
{
llListenRemove(handle);//no reply so remove listener
llSetTimerEvent(0.0);
}

//Now that the anim is selected wait for them to sit
changed(integer change)
{
if(change & CHANGED_LINK)
{
av = llAvatarOnSitTarget();
if(av) //if someone sat
{
llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION); //request permissions
}
}
}

//did we get permission
run_time_permissions(integer permissions)
{
if(permissions & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("sit";); //stop the generic sit
llStartAnimation(anim); //start our animation
}
}
}
[/PHP]
Veldin Finesmith
Registered User
Join date: 27 Jun 2008
Posts: 16
06-29-2008 17:12
Hmm it compiles ok but all that happens is the menu comes down for choosing a sit pose and then nothing else :/ It doesn't seem to be getting to the permission to sit part, nor does the person move to the cushion?
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
06-29-2008 18:28
From: Veldin Finesmith
Hmm it compiles ok but all that happens is the menu comes down for choosing a sit pose and then nothing else :/ It doesn't seem to be getting to the permission to sit part, nor does the person move to the cushion?

A script can't make a person sit. It might be easier to forget about touching beforehand, and instead call the menu from the changed event once the avatar sits down.
_____________________
Veldin Finesmith
Registered User
Join date: 27 Jun 2008
Posts: 16
06-29-2008 20:49
From: Viktoria Dovgal
A script can't make a person sit. It might be easier to forget about touching beforehand, and instead call the menu from the changed event once the avatar sits down.


Well your words are English but my brain has no idea what ou said or even the slightest idea on how to implement that. :(
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-29-2008 21:27
Try something like this:

(NOTE: Not yet compiled; may need minor syntax fixes.)
CODE

// Constants

integer CHANNEL = -1259349227;

// Extending this to multiple menu screens is left as an exercise.
integer MAX_ANIMATIONS = 12;


//// Variables

list animations = [];
integer nAnimations = 0;

key sitter = NULL_KEY;
integer listenHandle = 0;
string currAnimation = "";


//// Functions

integer canAnimate(key id)
{
return (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) &&
llGetPermissionsKey() == id;
}

offerAnimationChoice()
{
listenHandle = llListen(CHANNEL, "", sitter, "");

llDialog(
sitter,
"Choose an animation",
[ animations ],
CHANNEL);
}

animate()
{
llStopAnimation("sit");
llStartAnimation(currAnimation);
}

unanimate()
{
llStopAnimation(currAnimation);
llStartAnimation("stand");
}


//// States

default
{
state_entry()
{
nAnimations = llGetInventoryNumber(INVENTORY_ANIMATION);
if (nAnimations > MAX_ANIMATIONS)
{
nAnimations = MAX_ANIMATIONS;
}

integer i;
animations = [];
for (i = 0; i < nAnimations; ++i)
{
animations = (animations=[])+animations+
llGetInventoryName(INVENTORY_ANIMATION, i);
}
}

changed(integer changes)
{
if (changes & CHANGED_LINK)
{
key newSitter = llAvatarOnSitTarget();
if (newSitter == sitter)
{
return;
}

if (sitter != NULL_KEY && canAnimate(sitter))
{
unanimate();
currAnimation = "";
}

sitter = newSitter;

if (sitter != NULL_KEY)
{
if (canAnimate(sitter))
{
offerAnimationChoice();
} else
{
llRequestPermissions(sitter, PERMISSION_TRIGGER_ANIMATION);
}
}
}
}

run_time_permissions(integer perms)
{
if (perms & PERMISSION_TRIGGER_ANIMATION)
{
offerAnimationChoice();
}
}

listen(integer channel, string name, key id, string message)
{
llListenRemove(listenHandle);
listenHandle = 0;

integer index = llListFindList(animations, [ message ]);
if (index < 0)
{
llWhisper(0, "Invalid animation choice.");
llUnSit(sitter);
return;
}

currAnimation = message;
animate();
}
}
Veldin Finesmith
Registered User
Join date: 27 Jun 2008
Posts: 16
06-30-2008 03:36
Ok that one compiled fine ingame but gives me a runtime error when executed. Says lists may not be lists?

Well I took the item back into inventory and put it out again, now it doesn't give the list error but still doesn't work. :( This is SO frustrating.
Veldin Finesmith
Registered User
Join date: 27 Jun 2008
Posts: 16
06-30-2008 04:11
Ok i formatted it ingame a bit more and I see a few places where there is a { but no ending }, yet it compiles fine. Is there supposed to be an } paired with every {?
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
06-30-2008 14:35
Veldin, before you go any further, it may be a dead end... (others can correct me if I'm wrong).

I believe you can't change sit target once they are seated. They'd have to stand up...

And you want 4 animations on there. Changes are, unless you've made them and know the same sit target will work with each of them, that otherwise a target that is right for one, will be wrong for all the others.

So before they sit, they'd have to click, get a menu, choose the sitting animation. Behind the scenes, you then set the sit target. Then they park themselves down.....

(as I say I haven't done much with simple furniture stuff like this, others may tell me it's more flexible than I've come to believe.)
_____________________
Thread attempting to compile a list of which animations are freebies, and which are not:

http://forums.secondlife.com/showthread.php?t=265609
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-30-2008 14:45
From: Chaz Longstaff
I believe you can't change sit target once they are seated. They'd have to stand up...

You can change the sit target, but it only affects the position of the next sit that happens. If the position is far enough from the already seated avatar, another avatar can actually sit at the same time, at the new sit target location.

To move the avatar currently sitting, you must use llSetLinkPrimitiveParams(), which might require you figure out which link number the avatar is occupying using llGetLinkKey(). If you move the avatar away from the sit target, again another avatar may be able to sit down simultaneously.

Either way at most one sitting avatar will register to llAvatarOnSitTarget().
Veldin Finesmith
Registered User
Join date: 27 Jun 2008
Posts: 16
06-30-2008 15:58
So this simple sounding script isn't so simple and may be impossible. That is really weird. Ok does anyone have a script with the above menu that can spawn in a different poseball per choice?
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
06-30-2008 16:03
From: Veldin Finesmith
So this simple sounding script isn't so simple and may be impossible. That is really weird. Ok does anyone have a script with the above menu that can spawn in a different poseball per choice?


Really, you may be best to consider looking at MLP 1.2 or MLP 2.0 . All the heavy lifting's been done for you; you just use those tools to adjust the poses and create the menus. Why reinvent the wheel, unless you're looking for an intellectual exercise?
_____________________
Thread attempting to compile a list of which animations are freebies, and which are not:

http://forums.secondlife.com/showthread.php?t=265609