Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Play a sound when you start/stop flying?

Casey Arai
Registered User
Join date: 27 Oct 2007
Posts: 8
04-27-2009 18:35
I'm making a jetpack for myself and it's been a LONG time since I last scripted, so anyone mind giving me a refresher on how to make a script to play a sound when you start flying and a different one when you stop?
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
04-27-2009 18:45
you need to see this pages

http://wiki.secondlife.com/wiki/LlGetAgentInfo

to know the state of the avatar , flying, runing, etc.

to play a sound (loop)when you know the avatar state

http://wiki.secondlife.com/wiki/LlLoopSound
or
http://wiki.secondlife.com/wiki/LlPlaySound
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
Casey Arai
Registered User
Join date: 27 Oct 2007
Posts: 8
04-27-2009 18:55
From: Papalopulus Kobolowski
you need to see this pages

http://wiki.secondlife.com/wiki/LlGetAgentInfo

to know the state of the avatar , flying, runing, etc.

to play a sound (loop)when you know the avatar state

http://wiki.secondlife.com/wiki/LlLoopSound
or
http://wiki.secondlife.com/wiki/LlPlaySound


Thanks, but I know how to make a sound loop while in the air, what I'm having a tough time remembering is how to make a sound play just once when you start and stop flying.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
04-27-2009 20:41
Unfortunately there isn't an event that captures the switch between in air/flying and on the ground, even the flying control is missing from llTakeControls. So about the best you might do is poll with a timer and look for changes.
Casey Arai
Registered User
Join date: 27 Oct 2007
Posts: 8
04-27-2009 21:00
Well, with the take off I suppose I could make it play the sound when you press up, and for the landing... Would it be possible to make a script that plays a sound once when you go back to walking then stops the script, then resets when you take off again?
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
04-27-2009 21:28
what about checking if the avi is on air or not?

AGENT_IN_AIR and check if the "F" key was pressed or not

look at the example

http://wiki.secondlife.com/wiki/LlGetAgentInfo

you only need to know if the avi is on air or not if im not wrong



check = llGetAgentInfo(owner);

if(check & AGENT_FLYING)
{

llPlaySound("some_sound",1.0);

}
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
Casey Arai
Registered User
Join date: 27 Oct 2007
Posts: 8
04-27-2009 22:30
I modified a script I had for the takeoff sound, it only works when you start flying by holding up since it doesn't detect F, but since for now the JP is only for me that's fine.
CODE

string gsSound = "SteamBurst1" ;
float giVolume = 0.3 ;
float fSoundDelay = 0.4;


integer giHasperms = FALSE ;

default
{
attach( key id )
{
if( id != NULL_KEY )
{
llRequestPermissions( id, PERMISSION_TAKE_CONTROLS ) ;
}

else
{
llReleaseControls() ;
giHasperms = FALSE ;
}
}

run_time_permissions( integer perms )
{
if( ( perms & PERMISSION_TAKE_CONTROLS ) && !giHasperms )
{
giHasperms = TRUE ;
llTakeControls( CONTROL_UP, TRUE, TRUE ) ;
}
}

control( key id, integer held, integer change )
{

if( held & change & CONTROL_UP )
{
integer agentstatus = llGetAgentInfo( id ) ;

if( ( ~agentstatus & AGENT_FLYING ) && ( ~agentstatus & AGENT_IN_AIR ) )
{
llSleep(fSoundDelay);
llPlaySound( gsSound, giVolume ) ;
}
}
}
}


I'm still having trouble making the landing noise though... I can't figure out a way for the script to play the sound once when not flying instead of spamming it because of the state check. This is what I'm trying to modify, it's the script I use to loop a sound while in the air.

CODE

default
{
state_entry()
{
llSetTimerEvent(0.1);
}
timer()
{
if(llGetAgentInfo(llGetOwner())& AGENT_IN_AIR)
{
llLoopSound("ai_smjet", 0.06);
}
else
{
llStopSound();
llPlaySound("SteamShortHiss", 0.5);
}
}
}


I figured if I threw "llPlaySound("SteamShortHiss", 0.5);" (SteamShortHiss is the landing sound) after the "llStopSound();" at the end of the script, but then it just spams the sound when I'm not flying...
Casey Arai
Registered User
Join date: 27 Oct 2007
Posts: 8
04-30-2009 11:14
Still havent figured out a good way... bump.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-30-2009 11:31
integer was_flying = -1;

checkup() {
integer status = llGetAgentInfo( id );
integer is_flying = (status & AGENT_FLYING) != 0;

// Was flying, now falling, pretend we're still flying...
if( (is_flying == FALSE) && (was_flying == TRUE) && (status & AGENT_IN_AIR) )
is_flying = TRUE;

// State changed and not first time through...
if(was_flying != is_flying && was_flying != -1) {
if( is_flying ) llPlaySound(TAKEOFF, 1);
else llPlaySound(LANDING, 1);
}
was_flying = is_flying;
}

default
{
state_entry() {
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
if(llGetPermissions() & PERMISSION_TAKE_CONTROLS)
llTakeControls(CONTROL_FWD|CONTROL_UP, TRUE, TRUE);
llSetTimerEvent(1);
}
control(key id, integer level, integer edge) {
checkup();
}
timer() {
checkup();
}
}
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Casey Arai
Registered User
Join date: 27 Oct 2007
Posts: 8
04-30-2009 11:50
Doesn't seem to be working, Argent...
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-30-2009 11:54
I'm sure it doesn't work, I haven't checked it in-world, just desk-checked it: it's a framework to start with that I wrote off the top of my head. Any programmer of moderate skill should be able to complete the job.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Casey Arai
Registered User
Join date: 27 Oct 2007
Posts: 8
04-30-2009 11:56
From: Argent Stonecutter
I'm sure it doesn't work, I haven't checked it in-world, just desk-checked it: it's a framework to start with that I wrote off the top of my head. Any programmer of moderate skill should be able to complete the job.

That's off the top of your head...? 0_o

...Anyhoo, I tweaked it a bit to this:

integer was_flying = -1;

checkup()
{
integer status = llGetAgentInfo(llGetOwner());
integer is_flying = (status & AGENT_FLYING) != 0;

// Was flying, now falling, pretend we're still flying...
if( (is_flying == FALSE) && (was_flying == TRUE) && (status & AGENT_IN_AIR) )
is_flying = TRUE;

// State changed and not first time through...
if(was_flying != is_flying && was_flying != -1)
{
if( is_flying ) llPlaySound("SteamBurst1", 1);
else llPlaySound("SteamShortHiss", 1);
}
was_flying = is_flying;
}

default
{
on_rez(integer p)
{
llResetScript();
}
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
if(llGetPermissions() & PERMISSION_TAKE_CONTROLS)
llTakeControls(CONTROL_FWD|CONTROL_UP, TRUE, TRUE);
llSetTimerEvent(0.1);
}
control(key id, integer level, integer edge)
{
checkup();
}
timer()
{
checkup();
}
}

And it plays the sounds, but only for a split second.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-30-2009 12:01
From: Casey Arai
That's off the top of your head...? 0_o
Yeh. I've been hacking code since 1972. :)
From: someone
And it plays the sounds, but only for a split second.
Ah, you want it to continue to play sounds while flying, not just when you take off and land.

Change the inner code of checkup()

if(was_flying != is_flying && was_flying != -1) {
if(is_flying) llLoopSound(FLYING_SOUND, 1);
else llStopSound();
}

You can put other special effects into there, like flashing lights, flames, warning sirens, what have you...
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Casey Arai
Registered User
Join date: 27 Oct 2007
Posts: 8
04-30-2009 12:05
No, I meant just when I take off and land, I had another script that looped another sound when flying. Which actually turned out to be the problem, heh. After I stopped the script for the other sound from running your script works fine now. Thanks :)
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-30-2009 12:07
Might as well put it all in one script now. :)
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore