Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local radioShuffle
- local nextThink = 0
- local tension = 0
- local entBoss
- local entBossID
- local bPlayTension = false
- local bForceTension
- local stypeMain
- function GM:SetMusicTension(_tension,force)
- tension = _tension
- bForceTension = force
- end
- function GM:GetMusicTension() return tension end
- function GM:StopSoundtrack(tm)
- if(!curTrack || !sound.IsSoundStillPlaying(curTrack)) then return end
- if(!tm) then
- local ISound = sound.GetByGuid(curTrack)
- ISound:Stop()
- return
- end
- sound.FadeOut(curTrack,tm)
- end
- function GM:SetMainSoundtrackType(stype)
- if stypeMain == stype then return end
- if prioCur == 100 then return end -- TODO: Find a better way?
- stypeMain = stype
- if curTrack && !ValidEntity(entBoss) && tension < 80 && prioCur == 0 then sound.FadeOut(curTrack,3) end
- end
- function GM:SetRadioStation(ID)
- LocalPlayer().stats.clientSettings.activeStation = ID
- if curTrack && prioCur <= 1000 then sound.FadeOut(curTrack,1.5) end
- if !ID then radioShuffle = nil; return end
- radioShuffle = self:GetRadioStation(ID).songs
- end
- local entDominant
- local tensionDominant
- hook.Add("Think","musicThink",function()
- if LocalPlayer().stats then
- local station = LocalPlayer():GetActiveStation()
- if station then
- local station = GAMEMODE:GetRadioStation(station)
- if station then
- if !curTrack || !sound.IsSoundStillPlaying(curTrack) || prioCur < 1000 then
- radioShuffle = radioShuffle || station.songs
- local i = math.random(1,#radioShuffle)
- GAMEMODE:PlaySoundtrack(radioShuffle[i],1000)
- table.remove(radioShuffle,i)
- if #radioShuffle == 0 then radioShuffle = station.songs end
- end
- return
- end
- end
- end
- if !curTrack || !sound.IsSoundStillPlaying(curTrack) then
- prioCur = 0
- if !ValidEntity(entBoss) || bForceTension then
- bPlayTension = tension >= 80
- local track
- if(bPlayTension) then
- if(ValidEntity(entDominant)) then
- local tracks = entDominant:GetSoundtracks()
- local numTracks = #tracks
- if(numTracks > 0) then track = tracks[math.random(1,numTracks)] end
- else track = "Battle" end
- else track = stypeMain end
- if(track) then GAMEMODE:PlaySoundtrack(track,bPlayTension && 1 || 0) end
- else
- bPlayTension = true
- local data = GAMEMODE.bossNPCs[entBoss.bossID]
- GAMEMODE:PlaySoundtrack(data.soundtrack,2)
- end
- end
- if prioCur == 100 then return end -- TODO: Find a better way?
- if CurTime() >= nextThink then
- nextThink = CurTime() +4
- if(!bForceTension) then
- if(LocalPlayer().m_bPVPActive) then tension = 100
- else tension = math.max(tension -35, 0) end
- if !ValidEntity(entBoss) then
- if entBoss then entBoss = nil end
- local boss = GAMEMODE:GetBoss()
- if ValidEntity(boss) then
- local bAc = LocalPlayer():GetPos():Distance(boss:GetPos()) <= 2000
- if !bAc then
- local entHUD, keep = GAMEMODE:GetCurrentHUDTarget()
- if keep && entHUD == boss then bAc = true end
- end
- if bAc then
- tension = 100
- entBoss = boss
- entBossID = entBoss.bossID
- if curTrack then sound.FadeOut(curTrack,3) end
- end
- end
- else
- local bAc = LocalPlayer():GetPos():Distance(entBoss:GetPos()) <= 2000
- if !bAc then
- local entHUD, keep = GAMEMODE:GetCurrentHUDTarget()
- if keep && entHUD == entBoss then bAc = true end
- end
- if !bAc then -- TODO: Take current boss enemy into account (If enemy is LocalPlayer...)
- entBoss = nil
- local data = GAMEMODE.bossNPCs[entBossID]
- entBossID = nil
- if !data.finale then sound.FadeOut(curTrack,3)
- else
- local ISound = sound.GetByGuid(curTrack)
- GAMEMODE:PlaySoundtrack(data.finale,2)
- nextThink = CurTime() +(ISound && ISound:Duration() || 0) +2
- end
- else tension = 100 end
- end
- end
- if !entBoss || bForceTension then
- if(!bForceTension) then
- local lvlPl = LocalPlayer().stats && LocalPlayer().stats.level || 0
- local _entDominant
- local _tensionDominant = 0
- for _, ent in ipairs(ents.FindInSphere(LocalPlayer():GetPos(),1600)) do
- if ent:IsValid() && ent:IsNPC() && ent:Disposition(LocalPlayer()) == D_HT then
- if ent:IsBoss() then tension = 100; break end
- local lvl = ent:GetLevel()
- local tensAdd = ent.Tension || math.min((lvl /(lvlPl +1)) *35,100)
- local tracks = ent:GetSoundtracks()
- local numTracks = #tracks
- local track
- if(numTracks > 0) then track = tracks[math.random(1,numTracks)] end
- if(track && tensAdd > _tensionDominant) then
- _tensionDominant = tensAdd
- _entDominant = ent
- end
- tension = tension +tensAdd
- end
- end
- if(_entDominant && _entDominant != entDominant && (!ValidEntity(entDominant) || tensionDominant < _tensionDominant || (GAMEMODE:GetCurrentHUDTarget() != entDominant && LocalPlayer():OBBDistance(entDominant) > 6000 && !LocalPlayer():Visible(entDominant)))) then
- entDominant = _entDominant
- tensionDominant = _tensionDominant
- sound.FadeOut(curTrack,3)
- nextThink = 4
- elseif(_entDominant != entDominant && ValidEntity(entDominant) && entDominant.Tension) then tension = tension +entDominant.Tension end
- tension = math.min(math.floor(tension), 100)
- end
- if !bPlayTension then
- if tension >= 90 then sound.FadeOut(curTrack,3) end
- elseif tension < 70 then
- if iBattleTrack then
- local dat = tblSounds["BattleFinale"][iBattleTrack]
- if(dat) then
- local ISound = sound.GetByGuid(curTrack)
- GAMEMODE:PlaySoundtrack("music/" .. dat,1)
- nextThink = CurTime() +(ISound && ISound:Duration() || 0) +2
- else
- sound.FadeOut(curTrack,3)
- nextThink = 4
- end
- else
- local bFinale
- if entBossID then
- local data = GAMEMODE.bossNPCs[entBossID]
- entBossID = nil
- if data.finale then
- bFinale = true
- local ISound = sound.GetByGuid(curTrack)
- GAMEMODE:PlaySoundtrack(data.finale,1)
- nextThink = CurTime() +(ISound && ISound:Duration() || 0) +2
- end
- end
- if !bFinale then
- sound.FadeOut(curTrack,3)
- nextThink = CurTime() +5
- end
- end
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement