Jump to content
The simFlight Network Forums

Recommended Posts

Posted

This is my first attempt to build a LUA script and it intends to manage sound in particular situations during the flight.

Feedbacks are more than welcome as I am interested to know about your satisfaction with it and to receive suggestions for future improvements and new features.

First I would say a big, big thanks to Pete, for how he has supported me in this attempt with his competence, passion and patience and for his incredible and amazing tool.

Prerequisites: The script is done for FSX and needs FSUIPC 4.644 or superior where Pete has put special offsets allowing some functions of the script.

Installation: copy and paste the script (located at the end of this post) in a file called ipcready.lua and put it in the module directory of FSX (where also FSUIPC is).

To install the wav files look the notes below.

With that name the script will be active when you are ready to flight and until you close FSX.

Features

Turbulence sound: the script plays a looping sound when a turbulence is detected at the altitude where the aircraft is. The sound is stopped when the turbulence is no more present. Sounds advising to fasten the seat belts or to unfasten them are also in the routine

Seats belt advises: 4 different sounds are here to be played in the following sequence (in FSUIPC assign a key to toggle the seatbelt switch):

1. BELT SIGN ON 1st time: normally before to leave the gate to play a welcome on board message

2. BELT SIGN OFF 1st time: normally after the climbing to play the message regarding to unfasten the seat belt

3. BELT SIGN ON 2nd time: normally during the descent to play the message to fasten seat belt before the approach

4. BELT SIGN OFF 2nd time: normally parked at the arrival gate to play the message of ended flight

Note: at the moment no controls are in place regarding the fact that the flight is in the right condition to play the messages and no controls are in place to avoid simulaneous sounds if you click on the sign more than once at the same time.

ATC Chatter: ATC conversations are played on a random base (every 1 minute plus another random interval) if you tune the COM2 radio on 118.10 and 118.20. As is the routine is built to have 70 radio files in two directories (one for each radio-frequence).

General Notes: The script is built for my environment (sound directories, wav filenames). Even if you are not experts of LUA scripting (like me) is anywhere easy to understand which are the parts you need to modify.

I do not attach any wav file as the mine are for the most part coming from payware add-ons and I do not think I can distribute them, but similar files (crew announcements, radio chatters) are availble as freeware in several sites (like flightsim.com or avsim.com).

The WAV filenames are free, in the sense that you can change them in the script. Only exception are the ATC radio files (the name is expected to be 1,2,3,.. and so on until 70).

Hope the info are enough clear (i'm not native english speaker).

I'm not responsible of any problem, damage you could have using the script, even if I think the biggest possible issue you could face is only to have the script doing nothing (like during some of my first tests).

Have fun and good flights

Here start the script

------------------------------------------------------------------------------
-- 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:\\mysound\\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")
------------------------------------------------------------------------ 

  • Upvote 1
Posted

I am getting this log:

********* LUA: "ipcReady" Log [from FSUIPC version 4.645] *********

45568 System time = 20/12/2010 18:47:49, Simulator time = 12:40:31 (11:40Z)

45568 LUA: beginning "D:\Flight Simulator X\Modules\ipcReady.lua"

45568 *** LUA Error: D:\Flight Simulator X\Modules\ipcReady.lua:74: unexpected symbol near '-'

45568 LUA: ended "D:\Flight Simulator X\Modules\ipcReady.lua"

45568 System time = 20/12/2010 18:47:49, Simulator time = 12:40:31 (11:40Z)

********* LUA execution terminated: Log Closed *********

I need help since since I am really new to LUA.Thanks

fabio

  • 4 months later...
Posted

I've corrected it for you.

Pete

Hi Pete,

What do I need to change in this script to be able to use those seat belts advises but with project magenta seat belt offset ?

Thanks in advance !

Carlos Hermida

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • 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.