Jump to content
The simFlight Network Forums

delta757

Members
  • Posts

    10
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by delta757

  1. Folks, below is code that will successfully trigger a sound file when turbulence is detected, Conversely, once the turbulence no longer exists, the sound file stops. I have tested and retested the script and all is well.

    Credits to Pete Dowson and "cellular55" of which some code was ported.

    ___________________________________________________________________

    Instructions for use:

    1. Copy the below code (only in blue) and paste into Windows Notepad.

    2. Save the file with the name: ipcready.lua

    3. Place this file into your FS9/modules folder

    4. Choose a sound (wav) file that best represents the sound of turbulence to you. i.e. rattle, bumps, etc.

    5. Name this sound file turb.wav and place it into your FS9/sound folder.

    Note: I have attached the turb.wav file that I am using and it is specifically edited to use with tactile transducers. It may or may not suit you as well.

    Thats it.

    Regards,

    Michael Lehkamp

    __________________________________________________________________________

    -- Turbulence looping sound --

    -- Initializing flags --

    sndflg=0 -- turbulence sound flag

    ref=0

    -- Function to play sound if and until turbulence is detected --

    function turbulence(offset,value)

    ground=ipc.readUW(0x0366)

    if (value > 0) and (sndflg == 0) and (ground == 0) then

    ref=sound.playloop("turb.wav")

    sndflg=1

    end

    if (value == 0) and (sndflg == 1) then

    sound.stop(ref)

    sndflg=0

    end

    end

    -- FSUIPC LUA events

    event.offset(0x0E88,"UW","turbulence")

    event.offset(0x0E98,"UW","turbulence")

    turb.wav

  2. Pete,

    Having tested for the better part of the last hour, I can confirm the below code does successfully work and achieve the desired purpose for which it was written - to detect turbulence within FS2004 and trigger a preferred sound file. At the conclusion or absence of further turbulence, the file successfully ceases or stops. Many thank you's for your patience and guidance.

    -- Turbulence looping sound --

    -- Initializing flags --

    sndflg=0 -- turbulence sound flag

    ref=0

    -- Function to play sound if and until turbulence is detected --

    function turbulence(offset,value)

    ground=ipc.readUW(0x0366)

    if (value > 0) and (sndflg == 0) and (ground == 0) then

    ref=sound.playloop("turb.wav")

    sndflg=1

    end

    if (value == 0) and (sndflg == 1) then

    sound.stop(ref)

    sndflg=0

    end

    end

    -- FSUIPC LUA events

    event.offset(0x0E88,"UW","turbulence")

    event.offset(0x0E98,"UW","turbulence")

  3. Pete,

    your right and I got ahead of myself. And you were just educating me earlier on "patience and examination". Ergh.

    Yes I will thoroughly test this morning and report back my results. I did in fact have it working nicely last night although with a slightly different code - the one mentioning atc chatter etc. I re-wrote after testing and omitted comments that were not desired. But yes, I will remove the 4th reference "End", test again, and report back.

    On another note, now that I have the main FS PC playing this loop, which activates the tactile transducers for turbulence thumps, I would like to run the same code on a WideFS PC which will play a slightly different sound - rattling & shaking.

    On PC2, I have WideFS working beautifully with Radar Contact. In the WideFS folder where Wideclient is located, I copied in a LUA file (the one I tested and had working last night) but I was unsure where the sound file should go. Should the sound file reside in the same folder with Wideclient and the LUA script, or should the script be written to point at a sound file in the main FS sound folder?

  4. Ok Pete, I think I have it now. My changes are in Red. Would like your review before I add it to Contributions folder:

    ipcready.lua

    -- Turbulence looping sound --

    -- Initializing flags --

    sndflg=0 -- turbulence sound flag

    ref=0

    -- Function to play sound if and until turbulence is detected --

    function turbulence(offset,value)

    ground=ipc.readUW(0x0366)

    if (value > 0) and (sndflg == 0) and (ground == 0) then

    ref=sound.playloop("turb.wav")

    sndflg=1

    end

    if (value == 0) and (sndflg == 1) then

    sound.stop(ref)

    sndflg=0

    end

    end

    end

    -- FSUIPC LUA events

    event.offset(0x0E88,"UW","turbulence")

    event.offset(0x0E98,"UW","turbulence")

  5. Okay. At a quick perusal, not checking everything for you, why create a directory called D:\esounds\sounds when you have the instruction pointing to a different drive altogether? See:

    Incidentally, why not just put whatever sounds you want into FS's "sounds" folder, which is the default path for the Lua sound library, and so save yourself all this directory hassle in the first place? Then you simply need

    ref=sound.playloop("turb.wav")

    And what was wrong with your original posted earlier? Do you also want all that other stuff?

    Programming in any sort of language, whether an easy scripting one like Lua or a complex one like C++ is an activity demanding a level of care and attention not often needed in normal pursuits. This isn't just a matter of expertise or experience but patience ans examnation. Inspecting each line of code is an important part of checking and debugging. Ask youself, at each step, whether it makes sense, is it going to do what you actually want.

    Regards

    Pete

    Great advise Peter and thank you much for taking the time to respond. I know you often feel like your pulling your hair out with some of us. Just the same, my project would never be where it is without FSUIPC and Wideclient. Thank you ever so much.

    Yes, I will point the sound to the FS sound directory as per your example above.

    • Upvote 1
  6. Ok, thank you. In an effort not to repeat what others have slaved over, I went to the "Contributions" folder and retrieved the turbulence script from another gentlemen. He however is using FSX while I am using FS2004. As I understand the documentation however, the offsets are now the same or have been added for FS2004.

    I assume since this script has been approved for the "Contributions" folder, it must work.

    I have pasted the script below for review.

    When I returned home an hour ago or so, this is what I did in order:

    1. Went to the Contributions folder and copied cellular55's script and pasted it into Windows Notepad. I then saved it as ipcready.lua. 2. I then copied the ipcready.lua into the FS2004 modules folder.

    3. Installed the "payed" version of FSUIPC (3.999).

    4. I then created a directory called D:/esound/sounds and placed a turb.wav file within.

    Please note that I did not add all the other sound wav files called for in the script as I assume LUA will look for the files and if it is absent will merely overlook it. The "turb.wav" file is there.

    5. Started FS2004. Got airborne, and cleared all weather.

    6. Then changed the theme to "Building Storms" and the airplane began to rock.

    However, the script as is did nothing. No sound file played.

    I'm confused. I'm a novice to this script writing and I am damned to learn it one way or the other.

    ------------------------------------------------------------------------------

    -- Turbulence looping sound -- Seat Belts Messages -- ATC Radio Chatter

    -- Initializing flags --

    sndflg=0 -- turbulence sound flag

    seatfl=0 -- seat belt flag

    -- Function to play sound if and until turbulence is detected --

    function turbulence(offset,value)

    ground=ipc.readUW(0x366)

    if (value > 0) and (sndflg == 0) and (ground == 0) then

    ref=sound.playloop("c:\\esound\\sounds\\turb.wav")

    sndflg=1

    ipc.sleep(1000)

    if (seatfl == 2) or (seatfl == 4) then

    sound.play("c:\\mysound\\paxsign.wav")

    ipc.sleep(1000)

    end

    sound.play("c:\\mysound\\fastenwind.wav.wav")

    end

    if (value == 0) and (sndflg == 1) then

    sound.stop(ref)

    sndflg=0

    if (seatfl == 2) or (seatfl ==4) then

    sound.play("c:\\mysound\\paxsign.wav")

    ipc.sleep(1000)

    sound.play("c:\\mysound\\unfastenseatbelt.wav")

    end

    end

    end

    -- Function to manage messages when seat belts sign changes - welcome on board -- descent --- on cruise ---- parked at the arrival gate

    function seatbelt(offset,value)

    if (value == 1) and (seatfl == 0) then

    sound.play("c:\\mysound\\paxsign.wav")

    ipc.sleep(1000)

    sound.play("c:\\mysound\\welcomeonboard.wav")

    seatfl=1

    end

    if (value == 1) and (seatfl == 2) then

    sound.play("c:\\mysound\\paxsign.wav")

    ipc.sleep(1000)

    sound.play("c:\\mysound\\descent.wav")

    seatfl=3

    end

    if (value == 0) and (seatfl == 1) then

    sound.play("c:\\mysound\\paxsign.wav")

    ipc.sleep(1000)

    sound.play("c:\\mysound\\levelautobelt.wav")

    seatfl=2

    end

    if (value == 0) and (seatfl == 3) then

    sound.play("c:\\mysound\\paxsign.wav")

    ipc.sleep(1000)

    sound.play("c:\\mysound\\atgate.wav")

    seatfl=4

    end

    end

    -- Function to play ATC chatter - COM2 freqs 118.10 and 118.20 - 70 wavs for each freq - y var to make the frequency of chat random - x var to make the messages random

    function ATC_Radio()

    -- Radio squelch if a valid freq is selected

    n = ipc.readUW(0x3118)

    if (n == 0x1810) or (n == 0x1820) then

    if (n1 ~= n) then

    sound.play("c:\\mysound\\Radio.wav")

    n1=n

    end

    end

    -- Radio chatter play routine

    y= math.random(1,5)

    if (y == 2) or (y == 4) then

    if (n == 0x1810) then

    x=math.random (1,70)

    suono = "c:\\mysound\\11810\\"..x..".wav"

    sound.play(suono)

    end

    if (n == 0x1820) then

    x=math.random (1,70)

    suono = "c:\\mysound\\11820\\"..x..".wav"

    sound.play(suono)

    end

    end

    end

    -- FSUIPC LUA calls for the different events -- timer to exec the ATC function every 1 min

    event.offset(0x0E88,"UW","turbulence")

    event.offset(0x0E98,"UW","turbulence")

    event.offset(0x341D,"UB","seatbelt")

    event.timer(60000,"ATC_Radio")

    ------------------------------------------------------------------------

  7. Thank you Mr. Dowson for the reply. Forgive me for not testing as I am away on work and attempting to write this script as I have downtown (and peace) which allows me to concentrate more on the documentation.

    I searched and found documentation on "pre-defining" functions but am a bit confused as a novice. I concluded on adding ref=0 towards the top of the script which I'm sure is probably not what you were referring to in point #1.

    Regarding point #2, in the below pasted (updated) script, I have added the tandem backslashes.

    Regarding point #3, the sleep call has been removed.

    UPDATED SCRIPT for FS2004 TURBULENCE: (ipcready.lua)

    (BEGIN)

    -- Turbulence looping sound

    -- Initializing flags --

    sndflg=0 -- turbulence sound flag

    ref=0

    -- Function to play sound when turbulence is detected --

    function turbulence(offset,value)

    ground=ipc.readUW(0x366)

    if (value > 0) and (sndflg == 0) and (ground == 0) then

    ref=sound.playloop("d:\\esound\\sounds\\turb.wav")

    sndflg=1

    end

    if (value == 0) and (sndflg == 1) then

    sound.stop(ref)

    sndflg=0

    end

    end

    -- FSUIPC LUA events

    event.offset(0x0E88,"UW","turbulence")

    event.offset(0x0E98,"UW","turbulence")

    (END)

  8. Hello Pete.

    I am attempting to write a LUA script that will detect turbulence (in and around the aircraft I'm flying) and trigger a wav file to rattle the tactile transducers attached to the simulator platform. Conversely, the same script will stop the sound wav once the aircraft exits the turbulent area.

    I have read and re-read the documentation and looked at others scripts for guidance. Below is the script that I have currently. Will this in your opinion function?

    ipcready.lua

    -- FS2004 Turbulence Loop WAV (Tactile Transducers)

    -- Initializing flags --

    sndflg=0 -- turbulence sound flag

    -- Function to play when turbulence is detected --

    function turbulence(offset,value)

    ground=ipc.readUW(0x366)

    if (value > 0) and (sndflg == 0) and (ground == 0) then

    ref=sound.playloop("d:\\esound\sounds\turbrattle.wav")

    sndflg=1

    ipc.sleep(1000)

    end

    -- Function to terminate WAV once turbulence subsides --

    if (value == 0) and (sndflg == 1) then

    sound.stop(ref)

    sndflg=0

    end

    end

    -- FSUIPC LUA events

    event.offset(0x0E88,"UW","turbulence")

    event.offset(0x0E98,"UW","turbulence")

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.