local U = require "scriptbank\\utillib" local soundId = 20 function combat_music_init( e ) LoadGlobalSound( "audiobank\\music\\theescape\\battle.ogg", soundId ) end local timer = 0 local period = 200 local dist = 2000 local minVolume = 60 local maxVolume = 99 local fadeInSpd = 0.25 local fadeOutSpd = 0.1 local musicState = 'silent' local curEnemies = {} local curVolume = minVolume local function not_in_list( list, element ) for _,v in pairs( list ) do if v == element then return false end end return true end function combat_music_main( e ) if musicState == 'fade_in' then if curVolume < maxVolume then curVolume = curVolume + fadeInSpd else curVolume = maxVolume musicState = 'playing' end SetGlobalSoundVolume( soundId, curVolume ) elseif musicState == 'fade_out' then if curVolume > minVolume then curVolume = curVolume - fadeOutSpd SetGlobalSoundVolume( soundId, curVolume ) else curVolume = minVolume musicState = 'silent' StopGlobalSound( soundId ) end end if g_Time < timer then return end timer = g_Time + period local list = U.ClosestEntities( dist ) local isCombat = false --Prompt( musicState .. ", " .. #list ) for _,v in pairs( list ) do local ai_state = ai_bot_state[ v ] if ai_state ~= nil then --PromptLocal( v, ai_state ) if ai_state == ai_state_startmove or ai_state == ai_state_move or ai_state == ai_state_avoid or ai_state == ai_state_hurt or ai_state == ai_state_punch or ai_state == ai_state_recoverstart or ai_state == ai_state_recover or ai_state == ai_state_startfireonspot or ai_state == ai_state_fireonspot or ai_state == ai_state_startreload or ai_state == ai_state_reload or ai_state == ai_state_reloadsettle or ai_state == ai_state_disable or ai_state == ai_state_duckstart or ai_state == ai_state_duck or ai_state == ai_state_unduckstart or ai_state == ai_state_unduck or ai_state == ai_state_rollstart or ai_state == ai_state_roll or ai_state == ai_state_crouchdashstart or ai_state == ai_state_crouchdash or ai_state == ai_state_checkforcover or ai_state == ai_state_strafeleftstart or ai_state == ai_state_strafeleft or ai_state == ai_state_straferightstart or ai_state == ai_state_straferight then curEnemies[ v ] = true isCombat = true break end end end local allDead = false for k,_ in pairs( curEnemies ) do if not_in_list( list, k ) then allDead = true curEnemies[ k ] = nil else allDead = false end end if allDead then PromptDuration( "All dead", 3000 ) end if isCombat then if musicState == 'silent' and GetGlobalSoundLooping( soundId ) == 0 then LoopGlobalSound ( soundId ) curVolume = minVolume SetGlobalSoundVolume( soundId, curVolume ) musicState = 'fade_in' end elseif musicState == 'playing' then if GetGlobalSoundLooping( soundId ) == 1 then musicState = 'fade_out' else musicState = 'silent' end end end