There might still be some problems as I haven't tested it thoroughly.
import App
import MissionLib
import Libs.LibEngineering
import Foundation
import Bridge.BridgeUtils
def init():
pGame = App.Game_GetCurrentGame()
#pEpisode = pGame.GetCurrentEpisode()
#pMission = pEpisode.GetCurrentMission()
pXOMenu = Bridge.BridgeUtils.GetBridgeMenu("XO")
Libs.LibEngineering.CreateMenuButton("Mute Alert Sound", "XO", __name__ + ".MuteSound")
pXOMenu.AddPythonFuncHandlerForInstance(App.ET_SET_ALERT_LEVEL, __name__ + ".AlertLevel")
def LoadSound():
pGame = App.Game_GetCurrentGame()
pBridgeRegion = App.TGSoundRegion_GetRegion("bridge")
pBridgeRegion.SetFilter(App.TGSoundRegion.FT_NONE)
for sFile, sSound, fVolume in (
("sfx/redalert.wav", "RedAlertSound", 1.0),
("sfx/yellowalert.wav", "YellowAlertSound", 1.0),
("sfx/greenalert.wav", "GreenAlertSound", 1.0)
):
pSound = pGame.LoadSoundInGroup(sFile, sSound, "BridgeGeneric")
pBridgeRegion.AddSound(pSound)
pSound.SetVolume(1.0)
def AlertLevel(pObject, pEvent):
sType = pEvent.GetInt()
pGame = App.Game_GetCurrentGame()
pPlayer = App.ShipClass_Cast(pGame.GetPlayer())
if (App.IsNull(pPlayer)):
pObject.CallNextHandler(pEvent)
return
sLevel = 0
if (sType == App.CharacterClass.EST_ALERT_GREEN):
sLevel = pPlayer.GREEN_ALERT
if (sType == App.CharacterClass.EST_ALERT_YELLOW):
sLevel = pPlayer.YELLOW_ALERT
if (sType == App.CharacterClass.EST_ALERT_RED):
sLevel = pPlayer.RED_ALERT
if (sLevel != pPlayer.GetAlertLevel()):
if (sType == App.CharacterClass.EST_ALERT_GREEN):
LoadSound()
pSound = App.g_kSoundManager.GetSound("RedAlertSound")
if (pSound != None):
pSound.SetLooping(0)
pSound.SetPriority(1.0)
pSound.Play()
print "green alert"
MuteSound(pObject, pEvent)
if (sType == App.CharacterClass.EST_ALERT_YELLOW):
LoadSound()
pSound = App.g_kSoundManager.GetSound("YellowAlertSound")
if (pSound != None):
pSound.SetLooping(0)
pSound.SetPriority(1.0)
pSound.Play()
print "yellow alert"
MuteSound(pObject, pEvent)
if (sType == App.CharacterClass.EST_ALERT_RED):
print "red alert"
LoadSound()
pSound = App.g_kSoundManager.GetSound("RedAlertSound")
if (pSound != None):
pSound.SetLooping(1)
pSound.SetPriority(1.0)
pSound.Play()
pAlertEvent = App.TGIntEvent_Create()
pAlertEvent.SetSource(pObject)
pAlertEvent.SetDestination(pPlayer)
pAlertEvent.SetEventType(App.ET_SET_ALERT_LEVEL)
pAlertEvent.SetInt(sLevel)
App.g_kEventManager.AddEvent(pAlertEvent)
pObject.CallNextHandler(pEvent)
def MuteSound(pObject, pEvent):
try:
App.g_kSoundManager.StopSound("RedAlertSound")
except:
pass
pObject.CallNextHandler(pEvent)