2 // huffware script: minnow, modifications by fred huffhines.
4 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
5 // do not use it in objects without fully realizing you are implicitly accepting that license.
7 // original attributions:
8 // Fixit Galatea generic boat script
9 // This script uses the basic direction keys for boat operation and requires
10 // the final prim to be oriented at rotation <0, 0, 0>.
12 //****************************************************************************
13 //****************************************************************************
14 //****************************************************************************
15 //* The following items can be edited in this script. See the comment for each
16 //* item to see how it work when it is changed.
17 //****************************************************************************
19 //* When the forward key is pressed and the mouse button is pressed at the
20 //* same time, this speed is used. This number should be between 0.0 and 30.0,
21 //* with higher numbers giving faster performance.
22 float fastspeed = 16.0;
24 //* When the forward key is pressed and the mouse button is NOT pressed, this
25 //* speed is used. This number should be between 0.0 and whatever the
26 //* fastspeed value was set at, with higher numbers giving faster performance.
27 float slowspeed = 8.0;
29 //* This is the reverse speed. It shouldn't be too fast, but can be between
31 float backspeed = 2.0;
33 //* This is the vehicle 'hover' height, or how far it sits out of the water.
34 //* Adjust this as necessary for your boat.
35 float floatheight = 0.44;
37 //* If the boat is to ramp up speed slowly, set the following value to '1'.
38 //* Otherwise, the board will instantly reach full speed when the forward
40 integer fastforward = 0; // NOT IMPLEMENTED YET
42 //* Turning speed, a small turning speed is best
43 float turnspeed = 1.5;
45 //* If the boat 'angles' into turns, set the following value to '1'.
46 //* Otherwise, the boat will do flat turns.
47 integer angledturn = 1; // NOT IMPLEMENTED YET
49 //* Height offset of seat
50 //vector seatheight = <.2, 0, 0.35>;
52 vector camera_lives_at = <-7, 0, 3>;
53 // where the camera is poised when the avatar is seated.
55 vector camera_looks_at = <4, 0, 1>;
57 //****************************************************************************
58 //****************************************************************************
59 //****************************************************************************
61 // Initialize the vehicle as a boat
64 llSetVehicleType(VEHICLE_TYPE_BOAT);
66 // least for forward-back, most friction for up-down
67 llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <10, 1, 3>);
69 // uniform angular friction (setting it as a scalar rather than a vector)
70 llSetVehicleFloatParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, 0.1);
72 // linear motor wins after about five seconds, decays after about a minute
73 llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0>);
74 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.1);
75 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.05);
77 // agular motor wins after four seconds, decays in same amount of time
78 llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0>);
79 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);
80 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.2);
83 llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, floatheight);
84 llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.2);
85 llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 0.4);
86 llSetVehicleFloatParam(VEHICLE_BUOYANCY, 1.0);
88 // Slight linear deflection with timescale of 1 seconds
89 llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.1);
90 llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 1);
92 // Slight angular deflection
93 llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.1);
94 llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 6);
96 // somewhat bounscy vertical attractor
97 llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5);
98 llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 1);
100 // weak negative damped banking
101 llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 1.0);
102 llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 1.0);
103 llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.1);
105 // default rotation of local frame
106 llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME,
107 llEuler2Rot(<0, 0, 0>));
109 // remove these flags.
110 //disabled due to opensim problems running this call.
111 // llRemoveVehicleFlags(VEHICLE_FLAG_HOVER_TERRAIN_ONLY
112 // | VEHICLE_FLAG_LIMIT_ROLL_ONLY
113 // | VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT);
116 // llSetVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP
117 // | VEHICLE_FLAG_HOVER_WATER_ONLY
118 // | VEHICLE_FLAG_HOVER_UP_ONLY
119 // | VEHICLE_FLAG_LIMIT_MOTOR_UP);
125 // Display version number
126 llWhisper(0, "running script " + llGetScriptName());
127 llSetStatus(STATUS_PHYSICS, FALSE);
129 // Set sit direction (forward) and sight location slightly up and behind
130 // llSitTarget(seatheight, llEuler2Rot(<0, 0, 0>));
131 llSetCameraAtOffset(camera_looks_at);
132 llSetCameraEyeOffset(camera_lives_at);
133 llSetSitText("Pilot");
135 // Initialize vehicle states
138 // Set up listener callback function
139 llListen(0, "", llGetOwner(), "");
143 // huffware script: auto-retire, by fred huffhines, version 2.5.
144 // distributed under BSD-like license.
145 // !! keep in mind that this code must be *copied* into another
146 // !! script that you wish to add auto-retirement capability to.
147 // when a script has auto_retire in it, it can be dropped into an
148 // object and the most recent version of the script will destroy
149 // all older versions.
151 // the version numbers are embedded into the script names themselves.
152 // the notation for versions uses a letter 'v', followed by two numbers
153 // in the form "major.minor".
154 // major and minor versions are implicitly considered as a floating point
155 // number that increases with each newer version of the script. thus,
156 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
157 // and "hazmap v3.2" is a more recent version.
159 // example usage of the auto-retirement script:
162 // auto_retire(); // make sure newest addition is only version of script.
165 // this script is partly based on the self-upgrading scripts from markov brodsky
166 // and jippen faddoul.
169 string self = llGetScriptName(); // the name of this script.
170 list split = compute_basename_and_version(self);
171 if (llGetListLength(split) != 2) return; // nothing to do for this script.
172 string basename = llList2String(split, 0); // script name with no version attached.
173 string version_string = llList2String(split, 1); // the version found.
175 // find any scripts that match the basename. they are variants of this script.
176 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
177 //log_it("invpo=" + (string)posn);
178 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
179 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
180 // found a basic match at least.
181 list inv_split = compute_basename_and_version(curr_script);
182 if (llGetListLength(inv_split) == 2) {
183 // see if this script is more ancient.
184 string inv_version_string = llList2String(inv_split, 1); // the version found.
185 // must make sure that the retiring script is completely the identical basename;
186 // just matching in the front doesn't make it a relative.
187 if ( (llList2String(inv_split, 0) == basename)
188 && ((float)inv_version_string < (float)version_string) ) {
189 // remove script with same name from inventory that has inferior version.
190 llRemoveInventory(curr_script);
197 // separates the base script name and version number. used by auto_retire.
198 list compute_basename_and_version(string to_chop_up)
200 // minimum script name is 2 characters plus a version.
201 integer space_v_posn;
202 // find the last useful space and 'v' combo.
203 for (space_v_posn = llStringLength(to_chop_up) - 3;
204 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
206 // look for space and v but do nothing else.
207 //log_it("pos=" + (string)space_v_posn);
209 if (space_v_posn < 2) return []; // no space found.
210 //log_it("space v@" + (string)space_v_posn);
211 // now we zoom through the stuff after our beloved v character and find any evil
212 // space characters, which are most likely from SL having found a duplicate item
213 // name and not so helpfully renamed it for us.
215 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
216 //log_it("indy=" + (string)space_v_posn);
217 if (llGetSubString(to_chop_up, indy, indy) == " ") {
218 // found one; zap it. since we're going backwards we don't need to
219 // adjust the loop at all.
220 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
221 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
224 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
225 // ditch the space character for our numerical check.
226 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
227 // strip out a 'v' if there is one.
228 if (llGetSubString(chop_suffix, 0, 0) == "v")
229 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
230 // if valid floating point number and greater than zero, that works for our version.
231 string basename = to_chop_up; // script name with no version attached.
232 if ((float)chop_suffix > 0.0) {
233 // this is a big success right here.
234 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
235 return [ basename, chop_suffix ];
237 // seems like we found nothing useful.
243 // State (default) event handlers
246 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
247 on_rez(integer parm) { state rerun; }
249 state rerun { state_entry() { state default; } }
259 on_rez(integer start_param)
261 llSetStatus(STATUS_PHYSICS, FALSE);
264 run_time_permissions(integer permissions)
266 // Get user permissions
267 if ((permissions & PERMISSION_TAKE_CONTROLS) ==
268 PERMISSION_TAKE_CONTROLS)
270 llTakeControls(CONTROL_ML_LBUTTON | CONTROL_FWD |
271 CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT |
272 CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT, TRUE, FALSE);
276 changed(integer change)
278 if (change & CHANGED_LINK)
280 key agent = llAvatarOnSitTarget();
283 if (agent != llGetOwner())
285 llSay(0, "This boat isn't yours, but you can buy a copy!");
290 llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS);
291 llSetStatus(STATUS_PHYSICS, TRUE);
297 llSetStatus(STATUS_PHYSICS, FALSE);
302 control(key name, integer levels, integer edges)
309 if (levels & CONTROL_ML_LBUTTON)
312 turn = 1.5 * turnspeed;
313 // forw = 2 * PI / 3;
315 else if (levels & CONTROL_FWD)
318 turn = 1.0 * turnspeed;
321 else if (levels & CONTROL_BACK)
325 // turn = -1.0 * turnspeed;
328 if (levels & (CONTROL_LEFT | CONTROL_ROT_LEFT))
330 if (move == fastspeed)
342 side = .67 * turnspeed;
347 else if (levels & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
349 if (move == fastspeed)
361 side = -.67 * turnspeed;
369 llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0>);
373 llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION,
375 llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,
376 <-side / 5, 0, side>);
380 listen(integer channel, string name, key id, string message)
382 list params = llParseString2List(message, [" "], [":"]);
383 string cmd = llList2String(params, 0);
384 integer enable = llList2Integer(params, 1);
390 touch_start(integer total_number)
392 key id = llDetectedOwner(total_number - 1);
393 // llGiveInventory(id, "Info card");