Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

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
Cannon Avatar Cannon  

Avatar Cannon

This script moves an object via the avatars key strokes. It has a power variable which is controls the speed the avatar is shot.

Category: Cannon
By : Olly Butters
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Avatar Cannon
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. avatar cannon.lsl
1
2 //Person Cannon v0.9.4
3 //Author: Olly Butters
4 //13 February 2007
5 //Part of the schome initiative. (www.schome.ac.uk)
6 //You may copy/edit this, but please credit us.
7 //This script moves an object via the avatars key strokes. It has a power variable which is controls the speed the avatar is shot.
8 //Controls:
9 //Left/Right - rotate cannon left/right
10 //Forward/Back - rotate cannon up/down
11 //Up/Down - increase/decrease the power the avatar is shot out.
12 //Mouse-click - FIRE!!
13
14
15 //These are variables that could concievibly be altered.
16 float muzzle_velocity = 50; //speed of the avatar
17 float angle_increment = 10; //amount the cannon rotates by
18
19
20 //Nothing to edit below here at all, so don't even look!
21 integer no_of_inclination_moves = 0; //keeps track of how much the cannon inclination
22 integer no_of_rotation_moves = 0; //keeps track of the cannons rotation
23 integer first_touch = 0; //keeps track of wether avatar is in the cannon
24 key id; //avatar id.
25
26 //function to explain how to use.
27 instructions()
28 {
29 llSay(0, "Hello.\n This is the person cannon - the best way to get around!\n To move the cannon use forward/back/left/right.\n To change the power of the cannon use up/down.\n\n To fire yourself click on the cannon.");
30 }
31
32 //function to specify the precision of a float when converted to a string
33 string fixedPrecision(float input, integer precision)
34 {
35 if((precision = (precision - 7 - (precision < 1))) & 0x80000000)
36 return llGetSubString((string)input, 0, precision);
37 return (string)input;
38 }
39
40 default
41 {
43 {
44 //sets up the initial position
45 vector eul = <0, 0, 0>;
46 eul *= DEG_TO_RAD; //convert to radians rotation
47 rotation quat = llEuler2Rot( eul ); //convert to quaternion
48 llSetRot(quat); //rotate the object
49 llSitTarget(<0,0,0.1>, ZERO_ROTATION); //this needs to be tweeked! shooting straight up is no longer straight up!
50 llSetSitText("Climb in");//makes it say climb in istead of sit on in the pie menu.
51 }
52
53
54
55 //Move the cannon around and keeps track of the movement.
56 control( key ida, integer held, integer change ) // event for processing key press
57 {
58 vector position = llGetPos();
59
60 if( change & held & (CONTROL_LEFT | CONTROL_ROT_LEFT) )
61 {
62 rotation new_rot = llGetRot()*llAxisAngle2Rot(<0,0,1>, angle_increment*DEG_TO_RAD);
63 llSetRot(new_rot);
64 no_of_rotation_moves = no_of_rotation_moves+1;
65 }
66 else if( change & held & (CONTROL_RIGHT |CONTROL_ROT_RIGHT) )
67 {
68 rotation new_rot = llGetRot()*llAxisAngle2Rot(<0,0,1>, -angle_increment*DEG_TO_RAD);
69 llSetRot(new_rot);
70 no_of_rotation_moves = no_of_rotation_moves - 1;
71 }
72 else if( change & held & CONTROL_FWD )
73 {
74 rotation z_inc = llEuler2Rot( <0, angle_increment * DEG_TO_RAD, 0> );
75 rotation new_rot = z_inc*llGetRot();
76
77 llSetRot(new_rot);
78
79 no_of_inclination_moves = no_of_inclination_moves - 1;
80 }
81 else if( change & held & CONTROL_BACK )
82 {
83 rotation z_inc = llEuler2Rot( <0, -angle_increment * DEG_TO_RAD, 0> );
84 rotation new_rot = z_inc*llGetRot();
85
86 llSetRot(new_rot);
87
88 no_of_inclination_moves = no_of_inclination_moves + 1;
89 }
90 else if( change & held & CONTROL_UP )
91 {
92 muzzle_velocity = muzzle_velocity + 50;
93 string mv = "muzzle velocity=" + fixedPrecision(muzzle_velocity,0) + "m/s";
94 llSay(0, mv);
95 }
96 else if( change & held & CONTROL_DOWN )
97 {
98 muzzle_velocity = muzzle_velocity - 50;
99 if(muzzle_velocity<0)
100 {
101 muzzle_velocity=0;
102 }
103 string mv = "muzzle velocity=" + fixedPrecision(muzzle_velocity,0) + "m/s";
104 llSay(0, mv);
105 }
106 }
107
108 //Invoked when the avatar 'sits' on the cannon.
109 //Explains how to use,
110 //Sets a time limit,
111 //Gets permission for stuff,
112 //Moves the camera
113 //changes 'first_touch' to 1 indicating that avatar is in the cannon.
114 changed(integer change)
115 {
116 if(change & CHANGED_LINK)
117 {
118 instructions();
119 llSetTimerEvent(60); //makes it reset itself after 1 minute
120 // integer number;
122
123 integer desired_controls =
132
133
135 llTakeControls(desired_controls, TRUE, FALSE);
137
139 CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
140 CAMERA_BEHINDNESS_ANGLE, 0.0, // (0 to 180) degrees
141 CAMERA_BEHINDNESS_LAG, 0.0, // (0 to 3) seconds
142 CAMERA_DISTANCE, 8.0, // ( 0.5 to 10) meters
143 //CAMERA_FOCUS, <0,0,5>, // region relative position
144 CAMERA_FOCUS_LAG, 0.05 , // (0 to 3) seconds
145 CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
146 CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
147 PITCH" title="View Definition" class="tooltip">CAMERA_PITCH, 00.0, // (-45 to 80) degrees
148 //CAMERA_POSITION, <0,0,0>, // region relative position
149 CAMERA_POSITION_LAG, 0.1, // (0 to 3) seconds
150 CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
151 CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
152 CAMERA_FOCUS_OFFSET, <3,0,2> // <-10,-10,-10> to <10,10,10> meters
153 ]);
154
155 first_touch=1; //indicates that am inside
156 }
157 }
158
159 //If touching from the outside it explains that you have to get inside to use it. If touching from the inside it shoots.
160 touch(integer dave)
161 {
162 if(first_touch==0)
163 {
164 llSay(0, "Hello.\n This is the person cannon - the best way to get around!\n To use me simply right click, climb inside and follow the instructions.");
165 }
166 else
167 {
168
169 llUnSit(id);
170 llPushObject(id, <muzzle_velocity*llCos(no_of_rotation_moves*angle_increment*DEG_TO_RAD)*llCos((no_of_inclination_moves*angle_increment)*DEG_TO_RAD),
171 muzzle_velocity*llSin(no_of_rotation_moves*angle_increment*DEG_TO_RAD)*llCos((no_of_inclination_moves*angle_increment)*DEG_TO_RAD),
172 muzzle_velocity*llSin((no_of_inclination_moves*angle_increment)*DEG_TO_RAD)>, <1,1,1>, FALSE);
173 llSleep(2);
175 }
176 }
177
178
179 //resets the script
180 timer()
181 {
182 llSay(0, "You've had your fun, script resetting.");
184 }
185
186 }
187 // END //

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