Jump to content


Photo

GPWS for any aircraft in lua script


  • Please log in to reply
2 replies to this topic

#1 Marcelo peixoto

Marcelo peixoto

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationBrazil

Posted 16 June 2012 - 02:19 AM

Hi friends

My FSuipc is 4.831


I'm doing a GPWS Lua script for any aircraft.


I don´t know how to zero the volume, if i put 0 the sound still play quiet.

In the manual say

The vol ( volume) is a % value between 0% and 100%. This isn't the complete range from silence ot max, but 0 is very quiet. This defaults to 100.

This right? 0 is not absolute silence?

i put the line

if ipc.readSB(0x0B20) == 1 then

to play the sound only when the sound is on in FS.

Other think i wanna do, is play the sound only when the FS is in focus, but i don´t find a way.


see code:

gpws.lua

while 1 do
vol = 80
ralt = ipc.readUD(0x31E4)*3.28084/65536
if (ralt > 1000) then
altvar = 2000
snd = 1000
end
if (ralt < 1000) and (ralt > 500) then
if (snd == 1000) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_1000" ,0 ,vol)
end
snd = 500
end
end
if (ralt < 500) and (ralt > 400) then
if (snd == 500) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_500" ,0 ,vol)
end
snd = 400
end
end
if (ralt < 400) and (ralt > 300) then
if (snd == 400) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_400" ,0 ,vol)
end
snd = 300
end
end
if (ralt < 300) and (ralt > 250) then
if (snd == 300) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_300" ,0 ,vol)
end
snd = 250
end
end
if (ralt < 250) and (ralt > 200) then
if (snd == 250) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_min" ,0 ,vol)
end
snd = 200
end
end
if (ralt < 200) and (ralt > 100) then
if (snd == 200) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_200" ,0 ,vol)
ipc.writeSB("07BC", 0) -- DESLIGA AP MASTER
ipc.writeSB("07DC", 0) -- DESLIGA SPD
end
snd = 100
end
end
if (ralt < 100) and (ralt > 50) then
if (snd == 100) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_100" ,0 ,vol)
end
snd = 50
end
end
if (ralt < 50) and (ralt > 40) then
if (snd == 50) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_50" ,0 ,vol)
end
snd = 40
end
end
if (ralt < 40) and (ralt > 30) then
if (snd == 40) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_40" ,0 ,vol)
end
snd = 30
end
end
if (ralt < 30) and (ralt > 20) then
if (snd == 30) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_30" ,0 ,vol)
end
snd = 20
end
end
if (ralt < 20) and (ralt > 10) then
if (snd == 20) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_20" ,0 ,vol)
end
snd = 10
end
end
if (ralt < 10) then
if (snd == 10) then
if ipc.readSB(0x0B20) == 1 then
sound.play("jetone_10" ,0 ,vol)
end
snd = 0
end
end
end

To this work:
1 need download the sound package in http://www.4shared.c...CcY/Sound.html?
extract the files on your FS Sound folder
2 create a file in Modules folder called gpws.lua and copy the code inside this file
3 create a file in Modules folder called ipcready.lua and put the code below inside

ipc.runlua("gpws.lua")

Restart FS

For everyone use and improve.

Tanks!

Edited by Marcelo peixoto, 16 June 2012 - 02:49 AM.

  • 0

#2 Marcelo peixoto

Marcelo peixoto

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationBrazil

Posted 16 June 2012 - 02:31 AM

To play only when FS is in focus only change vol = 80 to vol = -80 in the code.
  • 0

#3 Pete Dowson

Pete Dowson

    Advanced Member

  • Moderators
  • 26,940 posts
  • LocationNear Stoke-on-Trent, UK

Posted 16 June 2012 - 09:58 AM

I don´t know how to zero the volume, if i put 0 the sound still play quiet.


Correct. Why play the sound with zero volume? Just don't play it, or stop it if playing.

FSUIPC scales the volume to give more precise control with 100 positions that otherwise you'd get.

This right? 0 is not absolute silence?


Yes, as it says. Why would you want to play sounds with no sound?

Other think i wanna do, is play the sound only when the FS is in focus, but i don´t find a way.


As Marcelo says, and as stated in the documentation for the sound.play function, just set the volume control -ve. (Obviously you cannot do this for zero, so don't use zero).

Regards
Pete
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users


About simFlight - simflight.com - simflight.de - simflight.fr - simflight.nl - simflight.pt - simflight.es - simflight.it - simflight.jp - simrussia.com - simMarket