Join us in Outworldz at or follow us:

[Table of Contents]

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Pose Balls Sit_Animation_Script  


Sit Animation Script.lsl

Category: Pose Balls
By : Moopf
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Sit_Animation_Script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Sit_Animation_Script_1.lsl
2 //Sit Animation Script by Moopf (All Rights Reserved).
5 //If you purchased this script from me you may use it as much as you like.
6 //If you didn't purchase this script from me let me know where you got it!
8 //Instructions
9 //This script will allow you to create an object with an animation other than the standard sitting
10 //animation. There is a notecard in this object which contains a full list of possible animations
11 //as of 1.3
13 //This is used to store the key of the avatar currently sitting on the object
14 key agentKey = NULL_KEY;
16 //When an avatar sits down we request permission to animate them, and this gets set to TRUE if we
17 //receive those permissions. The avatar isn't normally requested to give permissions with a pop up box - it just
18 //happens.
19 integer permissionResult = FALSE;
21 //This is the animation we want to use when the avatar sits down. A full list is in the notecard contained in this
22 //object.
23 string theAnim = "sit_ground";
25 //This is the text that will be shown in place of 'Sit' on the pie menu the avatar sees when they right-click on
26 //the object
27 string sitText = "Meditate";
29 //Sitting position. This is the X,Y and Z position of where the avatar should sit on the object,
30 //in relation to the center of the object. <0,0,0> cancels the sit position. Different objects need
31 //different sitting positions to look right, so you'll need to play with the X, Y and Z values until
32 //you are happy. You can use + or - numbers. For simplicity (so you don't have to worry about rotation,
33 //you should orient your object so that the Z axis points up and the X axis (the axis the avatar will
34 //face) points forward.
35 vector sittingPosition = <-0.1,0,0.7>;
38 //init() - runs on state_entry and on_rez
39 init()
40 {
41 //Change the text shown on the pie menu to what we've specified in sitText
42 llSetSitText(sitText);
43 //Set the position on the object that the avatar should sit. For simplicity
44 //you should orient your object with the Z axis (blue one) pointing up.
45 //The <0,0,0,1> is a quaternionrotation and if you follow the sitting
46 //position notes about axis, you won't need to touch this and it's not easy
47 //to explain!
48 llSitTarget(sittingPosition,<0,0,0,1>);
49 }
51 default
52 {
53 //state_entry - launches whenever the script is reset (or on change of
54 //state but this script doesn't use other states!)
56 {
57 init();
58 }
60 //on_rez - launches whenever the object is rezzed
61 on_rez(integer times)
62 {
63 init();
64 }
66 //changed - launches whenever something about the object changes, such as a new
67 //object is linked which is exactly what happens when you sit on an object!
68 changed(integer change) {
70 //Check to see if the number if linked objects has changed
71 if(change & CHANGED_LINK)
72 {
73 //If it has try to get the key of the avatar that's sat down.
74 key agent = llAvatarOnSitTarget();
75 //Check to see if it was an avatar and that we
76 //don't currently have an avatar sitting down.
77 if( agentKey == NULL_KEY && agent != NULL_KEY ) {
78 //OK, we now now there's an avatar sitting on this object and we have their key
79 agentKey = agent;
80 //Request permission to animate the avatar
82 } else if( agentKey != NULL_KEY && agent == NULL_KEY) {
83 //The person sitting down has got up. If we managed to get permission
84 //to animate then we need to stop the animation.
85 if(permissionResult) {
86 //Stop animating the avatar
87 llStopAnimation(theAnim);
88 }
89 //So the object is ready for the next person to sit down let's reset the script
90 //to reset everything.
92 }
93 }
94 }
96 //run_time_permissions - launched when llRequestPermissions is used and
97 //the script receives the result of that request
99 //Check to see if we got permission to animate the avatar
101 //Set the permission flag for use later.
102 permissionResult = TRUE;
103 //Stop the default "sit" animation
104 llStopAnimation("sit");
105 //Start the animation we want to use.
106 llStartAnimation(theAnim);
107 }
108 }
109 }// END //

Back to the Best Free Tools in Second Life and OpenSim.