Dispatching cockpit sounds in device - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 05-18-2017, 12:03 AM   #1
Wabacku
Junior Member
 
Join Date: Jul 2013
Posts: 37
Reputation power: 5
Wabacku is on a distinguished road
Default Dispatching cockpit sounds in device

Can anyone provide code to dispatch sound in a cockpit device (lua)? With an explanation?

I have no idea how to do this

Last edited by Wabacku; 05-18-2017 at 12:16 AM.
Wabacku is offline   Reply With Quote
Old 05-19-2017, 04:56 PM   #2
SilentEagle
Member
 
Join Date: Nov 2004
Location: Orlando, FL
Posts: 569
Reputation power: 26
SilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of light
Default

I wrote a how-to about this over a year ago for the A-4 devs, but I guess I should share it here.

https://pastebin.com/uKzbkhnA

Still no idea about how to do custom external sounds. Supposedly a sound API was released by ED devs, but nobody I know has ever figured out how to use it.
SilentEagle is offline   Reply With Quote
Old 05-19-2017, 06:43 PM   #3
Wabacku
Junior Member
 
Join Date: Jul 2013
Posts: 37
Reputation power: 5
Wabacku is on a distinguished road
Default

Quote:
Originally Posted by SilentEagle View Post
I wrote a how-to about this over a year ago for the A-4 devs, but I guess I should share it here.

https://pastebin.com/uKzbkhnA

Still no idea about how to do custom external sounds. Supposedly a sound API was released by ED devs, but nobody I know has ever figured out how to use it.
Thank you. My other question is queuing my engine crank with the icommand engine start commands. I have my electrical system fully coded but how do I prevent starting if my jet isnt prepared for starting?

Would just doing a simple if statement work?

"if (jet isnt ready) then if pilot icommandStart then (dispatch(icommandStop))"?
Wabacku is offline   Reply With Quote
Old 05-19-2017, 06:57 PM   #4
SilentEagle
Member
 
Join Date: Nov 2004
Location: Orlando, FL
Posts: 569
Reputation power: 26
SilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of light
Default

Quote:
Originally Posted by Wabacku View Post
Thank you. My other question is queuing my engine crank with the icommand engine start commands. I have my electrical system fully coded but how do I prevent starting if my jet isnt prepared for starting?

Would just doing a simple if statement work?

"if (jet isnt ready) then if pilot icommandStart then (dispatch(icommandStop))"?
You could undo the command like you are proposing, but I prefer to have wrapper-like functionality around built-in commands (SFM in this case). To do this, you would create a new custom key command that would dispatch the native engine start command only when your internal logic determines it is ready to do so. The original key command ID would be changed to the new custom one, so it is not possible to directly start the engone without going through your logic. Obviously, someone could go back into the default.lua and add it back in.
SilentEagle is offline   Reply With Quote
Old 05-19-2017, 08:05 PM   #5
Wabacku
Junior Member
 
Join Date: Jul 2013
Posts: 37
Reputation power: 5
Wabacku is on a distinguished road
Default

If I use play_once() in the If statement I want it to play it doesn't work. But if I use it in the else part of the If statement I want it works and plays when I want? play_continue() works where I want in the if statement...

So confused

Last edited by Wabacku; 05-19-2017 at 08:14 PM.
Wabacku is offline   Reply With Quote
Old 05-19-2017, 09:09 PM   #6
SilentEagle
Member
 
Join Date: Nov 2004
Location: Orlando, FL
Posts: 569
Reputation power: 26
SilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of light
Default

Quote:
Originally Posted by Wabacku View Post
If I use play_once() in the If statement I want it to play it doesn't work. But if I use it in the else part of the If statement I want it works and plays when I want? play_continue() works where I want in the if statement...

So confused
I would have to see your logic to know exactly what you mean, but what might be happening is that the sound is being told to play once every iteration, which restarts the sound audio at the beginning over and over, so you will never actually hear it play through the whole sound. That is the purpose of checking the is_playing function to avoid telling a sound to play when it is already playing.

The play_continue function, on the other hand, will internally loop through the entire sound audio before restarting, so you will hear it, even if you run that function every iteration.

Don't forget to tell the sound to stop when it should, even when it is only being told to play once. The sound will not automatically update its internal state after it is finished playing the audio. That is why the data structures I wrote for handling sounds included the sound length that I measured in a sound editing program.
SilentEagle is offline   Reply With Quote
Old 05-19-2017, 11:49 PM   #7
Wabacku
Junior Member
 
Join Date: Jul 2013
Posts: 37
Reputation power: 5
Wabacku is on a distinguished road
Default

Quote:
Originally Posted by SilentEagle View Post
I would have to see your logic to know exactly what you mean, but what might be happening is that the sound is being told to play once every iteration, which restarts the sound audio at the beginning over and over, so you will never actually hear it play through the whole sound. That is the purpose of checking the is_playing function to avoid telling a sound to play when it is already playing.

The play_continue function, on the other hand, will internally loop through the entire sound audio before restarting, so you will hear it, even if you run that function every iteration.

Don't forget to tell the sound to stop when it should, even when it is only being told to play once. The sound will not automatically update its internal state after it is finished playing the audio. That is why the data structures I wrote for handling sounds included the sound length that I measured in a sound editing program.
Ahh, okay. I guess your playSoundOnce function doesnt work anymore... I re wrote it and it sort of worked, but I couldn't get it to update the state to stopped. So, the sound would only play once when I flipped the switch the first time and never again. Anyway, your play once function gives the same results as play_once().

So it is just updating the sound to play again at the update rate. I just dont know how to edit your function to make it work. I made it play once by initiating and running a counter - as it == a certain time it played. I guess it wasnt a real counter since it updated only at the function call, but it looked like:

i = 0

func()
i = i +1
if i == 1 then play


Dont think you can reset the counter though... So it only plays each sound once and that sound can never play again...

EDIT: Im trying to play sounds from the update part.

EDIT #2: Got it working - still would be nice to play through the update()

Last edited by Wabacku; 05-20-2017 at 07:44 AM.
Wabacku is offline   Reply With Quote
Old 05-20-2017, 11:18 PM   #8
SilentEagle
Member
 
Join Date: Nov 2004
Location: Orlando, FL
Posts: 569
Reputation power: 26
SilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of lightSilentEagle is a glorious beacon of light
Default

Quote:
Originally Posted by Wabacku View Post
Ahh, okay. I guess your playSoundOnce function doesnt work anymore...
Everything should still work, but you'll probably need more logic than what I showed in my example. Here is how I do it using params.

Sound lua cockpit system:
https://pastebin.com/1e9WEW2A

Another lua system setting sound triggers:
https://pastebin.com/1Zmx5Z8D
SilentEagle is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 11:25 AM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.