Advertisement
Silverlan

Untitled

Jan 22nd, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.10 KB | None | 0 0
  1. local radioShuffle
  2. local nextThink = 0
  3. local tension = 0
  4. local entBoss
  5. local entBossID
  6. local bPlayTension = false
  7. local bForceTension
  8. local stypeMain
  9. function GM:SetMusicTension(_tension,force)
  10.     tension = _tension
  11.     bForceTension = force
  12. end
  13.  
  14. function GM:GetMusicTension() return tension end
  15. function GM:StopSoundtrack(tm)
  16.     if(!curTrack || !sound.IsSoundStillPlaying(curTrack)) then return end
  17.     if(!tm) then
  18.         local ISound = sound.GetByGuid(curTrack)
  19.         ISound:Stop()
  20.         return
  21.     end
  22.     sound.FadeOut(curTrack,tm)
  23. end
  24. function GM:SetMainSoundtrackType(stype)
  25.     if stypeMain == stype then return end
  26.     if prioCur == 100 then return end   -- TODO: Find a better way?
  27.     stypeMain = stype
  28.     if curTrack && !ValidEntity(entBoss) && tension < 80 && prioCur == 0 then sound.FadeOut(curTrack,3) end
  29. end
  30. function GM:SetRadioStation(ID)
  31.     LocalPlayer().stats.clientSettings.activeStation = ID
  32.     if curTrack && prioCur <= 1000 then sound.FadeOut(curTrack,1.5) end
  33.     if !ID then radioShuffle = nil; return end
  34.     radioShuffle = self:GetRadioStation(ID).songs
  35. end
  36. local entDominant
  37. local tensionDominant
  38. hook.Add("Think","musicThink",function()
  39.     if LocalPlayer().stats then
  40.         local station = LocalPlayer():GetActiveStation()
  41.         if station then
  42.             local station = GAMEMODE:GetRadioStation(station)
  43.             if station then
  44.                 if !curTrack || !sound.IsSoundStillPlaying(curTrack) || prioCur < 1000 then
  45.                     radioShuffle = radioShuffle || station.songs
  46.                     local i = math.random(1,#radioShuffle)
  47.                     GAMEMODE:PlaySoundtrack(radioShuffle[i],1000)
  48.                     table.remove(radioShuffle,i)
  49.                     if #radioShuffle == 0 then radioShuffle = station.songs end
  50.                 end
  51.                 return
  52.             end
  53.         end
  54.     end
  55.     if !curTrack || !sound.IsSoundStillPlaying(curTrack) then
  56.         prioCur = 0
  57.         if !ValidEntity(entBoss) || bForceTension then
  58.             bPlayTension = tension >= 80
  59.             local track
  60.             if(bPlayTension) then
  61.                 if(ValidEntity(entDominant)) then
  62.                     local tracks = entDominant:GetSoundtracks()
  63.                     local numTracks = #tracks
  64.                     if(numTracks > 0) then track = tracks[math.random(1,numTracks)] end
  65.                 else track = "Battle" end
  66.             else track = stypeMain end
  67.             if(track) then GAMEMODE:PlaySoundtrack(track,bPlayTension && 1 || 0) end
  68.         else
  69.             bPlayTension = true
  70.             local data = GAMEMODE.bossNPCs[entBoss.bossID]
  71.             GAMEMODE:PlaySoundtrack(data.soundtrack,2)
  72.         end
  73.     end
  74.     if prioCur == 100 then return end   -- TODO: Find a better way?
  75.     if CurTime() >= nextThink then
  76.         nextThink = CurTime() +4
  77.         if(!bForceTension) then
  78.             if(LocalPlayer().m_bPVPActive) then tension = 100
  79.             else tension = math.max(tension -35, 0) end
  80.             if !ValidEntity(entBoss) then
  81.                 if entBoss then entBoss = nil end
  82.                 local boss = GAMEMODE:GetBoss()
  83.                 if ValidEntity(boss) then
  84.                     local bAc = LocalPlayer():GetPos():Distance(boss:GetPos()) <= 2000
  85.                     if !bAc then
  86.                         local entHUD, keep = GAMEMODE:GetCurrentHUDTarget()
  87.                         if keep && entHUD == boss then bAc = true end
  88.                     end
  89.                     if bAc then
  90.                         tension = 100
  91.                         entBoss = boss
  92.                         entBossID = entBoss.bossID
  93.                         if curTrack then sound.FadeOut(curTrack,3) end
  94.                     end
  95.                 end
  96.             else
  97.                 local bAc = LocalPlayer():GetPos():Distance(entBoss:GetPos()) <= 2000
  98.                 if !bAc then
  99.                     local entHUD, keep = GAMEMODE:GetCurrentHUDTarget()
  100.                     if keep && entHUD == entBoss then bAc = true end
  101.                 end
  102.                 if !bAc then -- TODO: Take current boss enemy into account (If enemy is LocalPlayer...)
  103.                     entBoss = nil
  104.                     local data = GAMEMODE.bossNPCs[entBossID]
  105.                     entBossID = nil
  106.                     if !data.finale then sound.FadeOut(curTrack,3)
  107.                     else
  108.                         local ISound = sound.GetByGuid(curTrack)
  109.                         GAMEMODE:PlaySoundtrack(data.finale,2)
  110.                         nextThink = CurTime() +(ISound && ISound:Duration() || 0) +2
  111.                     end
  112.                 else tension = 100 end
  113.             end
  114.         end
  115.         if !entBoss || bForceTension then
  116.             if(!bForceTension) then
  117.                 local lvlPl = LocalPlayer().stats && LocalPlayer().stats.level || 0
  118.                 local _entDominant
  119.                 local _tensionDominant = 0
  120.                 for _, ent in ipairs(ents.FindInSphere(LocalPlayer():GetPos(),1600)) do
  121.                     if ent:IsValid() && ent:IsNPC() && ent:Disposition(LocalPlayer()) == D_HT then
  122.                         if ent:IsBoss() then tension = 100; break end
  123.                         local lvl = ent:GetLevel()
  124.                         local tensAdd = ent.Tension || math.min((lvl /(lvlPl +1)) *35,100)
  125.                         local tracks = ent:GetSoundtracks()
  126.                         local numTracks = #tracks
  127.                         local track
  128.                         if(numTracks > 0) then track = tracks[math.random(1,numTracks)] end
  129.                         if(track && tensAdd > _tensionDominant) then
  130.                             _tensionDominant = tensAdd
  131.                             _entDominant = ent
  132.                         end
  133.                         tension = tension +tensAdd
  134.                     end
  135.                 end
  136.                
  137.                 if(_entDominant && _entDominant != entDominant && (!ValidEntity(entDominant) || tensionDominant < _tensionDominant || (GAMEMODE:GetCurrentHUDTarget() != entDominant && LocalPlayer():OBBDistance(entDominant) > 6000 && !LocalPlayer():Visible(entDominant)))) then
  138.                     entDominant = _entDominant
  139.                     tensionDominant = _tensionDominant
  140.                     sound.FadeOut(curTrack,3)
  141.                     nextThink = 4
  142.                 elseif(_entDominant != entDominant && ValidEntity(entDominant) && entDominant.Tension) then tension = tension +entDominant.Tension end
  143.                 tension = math.min(math.floor(tension), 100)
  144.             end
  145.             if !bPlayTension then
  146.                 if tension >= 90 then sound.FadeOut(curTrack,3) end
  147.             elseif tension < 70 then
  148.                 if iBattleTrack then
  149.                     local dat = tblSounds["BattleFinale"][iBattleTrack]
  150.                     if(dat) then
  151.                         local ISound = sound.GetByGuid(curTrack)
  152.                         GAMEMODE:PlaySoundtrack("music/" .. dat,1)
  153.                         nextThink = CurTime() +(ISound && ISound:Duration() || 0) +2
  154.                     else
  155.                         sound.FadeOut(curTrack,3)
  156.                         nextThink = 4
  157.                     end
  158.                 else
  159.                     local bFinale
  160.                     if entBossID then
  161.                         local data = GAMEMODE.bossNPCs[entBossID]
  162.                         entBossID = nil
  163.                         if data.finale then
  164.                             bFinale = true
  165.                             local ISound = sound.GetByGuid(curTrack)
  166.                             GAMEMODE:PlaySoundtrack(data.finale,1)
  167.                             nextThink = CurTime() +(ISound && ISound:Duration() || 0) +2
  168.                         end
  169.                     end
  170.                     if !bFinale then
  171.                         sound.FadeOut(curTrack,3)
  172.                         nextThink = CurTime() +5
  173.                     end
  174.                 end
  175.             end
  176.         end
  177.     end
  178. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement