Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Garage Door Script - Needs sound

Nerolus Mosienko
Registered User
Join date: 3 Aug 2006
Posts: 145
01-29-2007 17:16
Hey there,

I'm putting out a prefab for this garage, and I was given a Garage Door script to make the door go up and down. The top stays in place, the bottom resizes so the prim for the garage door itself "squishes" up to the top. I can set how far up the garage door goes. I've got the door itself all figured out, now I'd like to add a sound or two to the door, but I'm not talented enough with the scripting language to edit it and have the door stay functional.

Lets say the sound for the door opening is "Opensound" and closing is "Closesound"

Any help is GREATLY appreciated!

Here is the script:

From: someone


integer no_steps = 20; // Number of steps when opening/closing. More means smoother action, but takes longer
float open_height = 2.5; // Height of remaining door to show when open

vector closed_position;
vector closed_scale;
integer open;

open_door()
{
integer i;
float dz = (closed_scale.z - open_height) / no_steps;

for (i = 1; i <= no_steps; i++)
{
float height = closed_scale.z - i*dz;
llSetScale(<closed_scale.x, closed_scale.y, height>;);
//llSleep(1.0);
llSetPos(<closed_position.x, closed_position.y, closed_position.z + 0.5*(closed_scale.z - height)>;);
//llSleep(1.0);
}
}

close_door()
{
integer i;
float dz = (closed_scale.z - open_height) / no_steps;

for (i = no_steps - 1; i > 0; i--)
{
float height = closed_scale.z - i*dz;
llSetScale(<closed_scale.x, closed_scale.y, height>;);
//llSleep(1.0);
llSetPos(<closed_position.x, closed_position.y, closed_position.z + 0.5*(closed_scale.z - height)>;);
//llSleep(1.0);
}

// set to predefined closed position, to prevent errors accumulating
llSetScale(closed_scale);
llSetPos(closed_position);
}

default
{
state_entry()
{
open = FALSE;
closed_position = llGetPos();
closed_scale = llGetScale();
}

touch_start(integer total_number)
{
if (open) {
close_door();
} else {
open_door();
}

open = !open;
}
}

Lee Ludd
Scripted doors & windows
Join date: 16 May 2005
Posts: 243
01-29-2007 18:08
I have a free box of door sounds I give away at my store in Grass. Search places for "Lee Ludd", take the "Scripted Doors ... " landmark, turn to your right when you land and they're sitting in a blue box on a table about 15 meters from the landing poing.

Lee
Atashi Toshihiko
Frequently Befuddled
Join date: 7 Dec 2006
Posts: 1,423
01-29-2007 21:04
You just need to add a couple lines to your script in the right spot to fire off some sound effects.

CODE

integer no_steps = 20; // Number of steps when opening/closing. More means smoother action, but takes longer
float open_height = 2.5; // Height of remaining door to show when open
string openSound="Open Door Sound";
string closeSound="Close Door Sound";

vector closed_position;
vector closed_scale;
integer open;

open_door()
{
llPlaySound(openSound,0.5); // 0.5 is volume, 0.0 is mute 1.0 is loudest
integer i;
float dz = (closed_scale.z - open_height) / no_steps;

for (i = 1; i <= no_steps; i++)
{
float height = closed_scale.z - i*dz;
llSetScale(<closed_scale.x, closed_scale.y, height>);
//llSleep(1.0);
llSetPos(<closed_position.x, closed_position.y, closed_position.z + 0.5*(closed_scale.z - height)>);
//llSleep(1.0);
}
}

close_door()
{
llPlaySound(closeSound,0.5); // 0.5 is volume, 0.0 is mute 1.0 is loudest
integer i;
float dz = (closed_scale.z - open_height) / no_steps;

for (i = no_steps - 1; i > 0; i--)
{
float height = closed_scale.z - i*dz;
llSetScale(<closed_scale.x, closed_scale.y, height>);
//llSleep(1.0);
llSetPos(<closed_position.x, closed_position.y, closed_position.z + 0.5*(closed_scale.z - height)>);
//llSleep(1.0);
}

// set to predefined closed position, to prevent errors accumulating
llSetScale(closed_scale);
llSetPos(closed_position);
}

default
{
state_entry()
{
open = FALSE;
closed_position = llGetPos();
closed_scale = llGetScale();
llPreloadSound(openSound); // this preloads the sound so it *should* play faster
llPreloadSound(closeSound); // this preloads the sound so it *should* play faster
}

touch_start(integer total_number)
{
if (open) {
close_door();
} else {
open_door();
}

open = !open;
}
}


Note - I have not tested this in world but if your original script worked then this should work too. Just change the names of the sounds to whatever sounds you really have, and drop those sound files into the door object next to the script.

-Atashi.