CapsAdmin

Untitled

Jul 23rd, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.49 KB | None | 0 0
  1. local POS = Vector(4625.017578125, -1312.3374023438, 9923.96484375)
  2. --if not LocalPlayer():CheckUserGroupLevel("developers") then return end
  3.  
  4. local mat_screenspace = Material("models/screenspace")
  5. local mdl_dome = Model("models/props_phx/construct/metal_dome360.mdl")
  6. local white = Color(255, 255, 255, 255)
  7.  
  8. SafeRemoveEntity(fractal_renderer)
  9.  
  10. local renderer = ClientsideModel(mdl_dome)
  11.  
  12. local function scale(ent, vec)
  13.     local mat = Matrix()
  14.     mat:Scale(vec)
  15.     ent:EnableMatrix("RenderMultiply", mat)
  16. end
  17.  
  18. RunConsoleCommand("pp_bloom", "1")
  19. RunConsoleCommand("pp_bloom_passes", "0")
  20. RunConsoleCommand("pp_bloom_multiply", "0")
  21. flomp = flomp or {} local f = flomp
  22. do -- particles
  23.    
  24.  
  25.     flomp.emitter = ParticleEmitter(EyePos(), false)
  26.     flomp.emitter:SetNoDraw(true)
  27.  
  28.     f.FFT = {}
  29.     f.FFT_Size = 1024
  30.  
  31.     f.FFT_Bass_1 = 0
  32.     f.FFT_Bass_2 = 0
  33.  
  34.     f.max_volume = 0
  35.     f.scale = 1
  36.     f.eye_angles = Angle(0,0,0)
  37.     f.eye_origin = vector_origin
  38.     f.vol_multplier = 1
  39.  
  40.     f.fft_detail = 10
  41.     f.mul_fft = f.FFT_Size/f.fft_detail
  42.  
  43.     for i = 1, f.FFT_Size do
  44.         f.FFT[i] = 0
  45.     end
  46.  
  47.     function flomp.SetSource(var)
  48.         var = type(var) == "number" and Entity(var) or var
  49.         if type(var) == "Vector" or (IsEntity(var) and var:IsValid()) then
  50.             f.source = var
  51.         end
  52.     end
  53.  
  54.     function flomp.SetScale(n)
  55.         f.scale = n
  56.     end
  57.  
  58.     function flomp.SetVolumeInputScale(n)
  59.         f.vol_multplier = n
  60.     end
  61.  
  62.     function flomp.GetSourcePos()
  63.         return type(f.source) == "Vector" and f.source or IsEntity(f.source) and f.source:IsValid() and f.source:EyePos() or vector_origin
  64.     end
  65.  
  66.     function flomp.GetAverage(istart, iend)
  67.         istart = math.Round(math.Clamp(istart, 1, f.FFT_Size))
  68.         iend = math.Round(math.Clamp(iend, 1, f.FFT_Size))
  69.         local n = 0
  70.         for i=istart, iend do
  71.         --  if f.FFT[i] then
  72.                 n = n + f.FFT[i]
  73.     --      end
  74.         end
  75.  
  76.         local div = (iend - istart)
  77.  
  78.         return div == 0 and 0 or (n / div)
  79.     end
  80.  
  81.     function flomp.IsAround(number, min, max)
  82.         return number > min and number < max and true or false
  83.     end
  84.  
  85.     function flomp.ScaleVolume(volume, peak)
  86.         return ((volume ^ flomp.powscale) * f.vol_multplier) * 2.5
  87.     end
  88.  
  89.     function flomp.Spectrum2D()
  90.         do return end
  91.         --if bawss and bawss.channel then bawss.channel:stop() bawss = nil end -- declan interuption protection
  92.  
  93.         local h = ScrH() + -400
  94.         local w = ScrW()
  95.         local volume = 0
  96.  
  97.         for fr = 1, f.FFT_Size do
  98.             volume = f.ScaleVolume(f.FFT[fr])
  99.  
  100.             surface.SetDrawColor(volume,volume,255*volume,255)
  101.             surface.DrawLine(
  102.                 (w+fr)-ScrW(), h,
  103.                 (w+fr)-ScrW(), h-(volume*50)
  104.             )
  105.         end
  106.     end
  107.  
  108.     local time = 0
  109.  
  110.     function flomp.SpectrumUpdate(data, peak)
  111.         if flomp.sound_vol == 0 then return end
  112.         f.FFT = data
  113.  
  114.         f.FFT_Bass_1 = flomp.GetAverage(1, 6)
  115.        
  116.         time = time + f.FFT_Bass_1 * 50
  117.  
  118.         for i = 1, 4 do
  119.  
  120.             local fr = (i * 256)
  121.  
  122.             local volume = f.ScaleVolume(f.FFT[math.Clamp(math.Round(i*f.mul_fft), 1, f.FFT_Size)], peak)
  123.  
  124.             if volume < 0.01 then continue end
  125.  
  126.             local n_fr = -(fr-30) + f.FFT_Size -- negative fr, f.FFT_Size to 0
  127.  
  128.             local f_fr = (fr-30)/f.FFT_Size -- fraction fr, 0, 1
  129.             local nf_fr = n_fr/f.FFT_Size -- negative fraction, 1, 0
  130.  
  131.             local max = 32
  132.            
  133.             for i2 = 1, max do
  134.                 local pi = (i2/max) * math.pi * 2
  135.  
  136.                 local size = (f.FFT_Bass_1 * 50 ^ 1.5)
  137.                 local color = HSVToColor((time+(pi*volume))%360, 1, 1)
  138.                
  139.                 local velocity = Vector(math.sin(pi+i+time), -volume / 5, math.cos(pi+i+time)) * volume ^ 1.3
  140.                 velocity = velocity
  141.  
  142.                 local particle = f.emitter:Add("sprites/light_glow02_add", f:GetSourcePos() + (velocity*2*f.scale))
  143.  
  144.                 particle:SetVelocity(velocity*1000*f.scale)
  145.  
  146.                 particle:SetLifeTime(0)
  147.                 particle:SetDieTime(math.Clamp(volume*0.1, 0.1, 0.8))
  148.  
  149.                 particle:SetStartLength(size*3*f.scale * 2*2)
  150.                 particle:SetEndLength(size*1.5*f.scale)
  151.                 particle:SetStartSize(size*f.scale*volume*0.5*2)
  152.                 particle:SetEndSize(0)
  153.  
  154.                 particle:SetStartAlpha(20)
  155.                 particle:SetEndAlpha(0)
  156.  
  157.                 particle:SetAirResistance(math.Clamp((-size+800), 10, 1200)*f.scale*2)
  158.                 --particle:SetGravity((VectorRand()*50)*f.scale)
  159.  
  160.                 particle:SetColor(color.r, color.g, color.b)
  161.                 particle:SetCollide(true)
  162.                 particle:SetBounce(0.1)
  163.             end
  164.         end
  165.        
  166.         flomp.SpectrumUpdate2(data)
  167.     end
  168.        
  169.     function flomp.SpectrumUpdate2(data)
  170.  
  171.         for i = 1, 4 do
  172.  
  173.             local fr = (i * 256)
  174.  
  175.             local volume = f.ScaleVolume(f.FFT[math.Clamp(math.Round(i*f.mul_fft), 1, f.FFT_Size)])
  176.  
  177.             if volume < 0.01 then continue end
  178.  
  179.             local n_fr = -(fr-30) + f.FFT_Size -- negative fr, f.FFT_Size to 0
  180.  
  181.             local f_fr = (fr-30)/f.FFT_Size -- fraction fr, 0, 1
  182.             local nf_fr = n_fr/f.FFT_Size -- negative fraction, 1, 0
  183.  
  184.             for i = 1, math.Clamp(math.Round(volume*4),0,15) do
  185.  
  186.                 local size = (f.FFT_Bass_1 * 15 ^ 1.8)
  187.                 local color = HSVToColor((time+(f_fr+volume*100))%360, f.FFT_Bass_1*20, 1)
  188.                 local velocity = ((f.eye_origin - f.GetSourcePos() ):Normalize() * 2 + VectorRand()):GetNormal()* volume ^ 2 * 3
  189.  
  190.                 local particle = f.emitter:Add("sprites/light_glow02_add", f:GetSourcePos() + (velocity*5*f.scale))
  191.  
  192.                 particle:SetVelocity(velocity*300*f.scale*2)
  193.  
  194.                 particle:SetLifeTime(0)
  195.                 particle:SetDieTime(math.Clamp(volume*0.3, 0.1, 0.8)^1.5)
  196.  
  197.                 particle:SetStartLength(size*7*f.scale*2)
  198.                 particle:SetEndLength(size*2*f.scale*4)
  199.                 particle:SetStartSize(size*f.scale*4)
  200.                 particle:SetEndSize(0)
  201.  
  202.                 particle:SetStartAlpha(255)
  203.                 particle:SetEndAlpha(0)
  204.  
  205.                 particle:SetAirResistance(math.Clamp((-size+800), 10, 2000)*f.scale*1.5)
  206.                 --particle:SetGravity((VectorRand()*50)*f.scale)
  207.  
  208.                 particle:SetColor(color.r, color.g, color.b)
  209.                 particle:SetCollide(true)
  210.                 particle:SetBounce(0.1)
  211.             end
  212.         end
  213.     end
  214.  
  215.     f.smooth_pp = 0
  216.     f.look_at_mult = 0
  217.  
  218.     function flomp.DrawPostProcess()
  219.         if flomp.sound_vol == 0 then return end
  220.         local w = ScrW()
  221.         local h = ScrH()
  222.  
  223.         local vec2 = f.GetSourcePos():ToScreen()
  224.  
  225.         local m = math.max(f.eye_angles:Forward():DotProduct((f.GetSourcePos()-f.eye_origin):GetNormalized()), 0) ^ 3
  226.         f.look_at_mult = m
  227.         m = m * (f.sound_vol * 2) ^ 2
  228.         m = m / 5
  229.        
  230.         --m = m * math.Clamp((-f.eye_origin:Distance(f.GetSourcePos()) / 15000) + 1, 0, 1)
  231.    
  232.         if m < 0.001 then return end
  233.  
  234.         m = math.Clamp(m, 0, 1)
  235.  
  236.         local vol = f.FFT_Bass_1
  237.         local darkness = (-m+1)
  238.  
  239.         local avr = math.Clamp(vol * 2  - 0.1,0,1) * m
  240.         local blur = math.Clamp((vol*-0.5)+1, 0.2, 1)
  241.         local invert = (vol*-10+1)
  242.  
  243.         local angle = Angle(math.Rand(-1,1), math.Rand(-1,1), math.Rand(-1,1)) * f.GetAverage(3, 7) * m
  244.         angle.x = math.Clamp(angle.p, -0.52, 0.52)
  245.         angle.y = math.Clamp(angle.y, -0.52, 0.52)
  246.         angle.z = 0
  247.         --LocalPlayer():SetEyeAngles(LocalPlayer():EyeAngles() + angle)
  248.  
  249.         f.smooth_pp = f.smooth_pp + ((avr - f.smooth_pp)*FrameTime()*10)
  250.  
  251.         local mscale = m * f.vol_multplier
  252.  
  253.         local tbl= {}
  254.         tbl[ "$pp_colour_addr" ] = 0
  255.         tbl[ "$pp_colour_addg" ] = 0
  256.         tbl[ "$pp_colour_addb" ] = 0
  257.         tbl[ "$pp_colour_brightness" ] = -0.025
  258.         tbl[ "$pp_colour_contrast" ] = 1.025-m
  259.         tbl[ "$pp_colour_colour" ] = 1.2+(m^0.75)
  260.         tbl[ "$pp_colour_mulr" ] = 0
  261.         tbl[ "$pp_colour_mulg" ] = 0
  262.         tbl[ "$pp_colour_mulb" ] = 0
  263.  
  264.  
  265.         --DrawMotionBlur(blur, 1, 0)
  266.         --DrawBloom(darkness, invert*m, math.max(invert*20+2, 5), math.max(invert*20+10, 5), 4, 10, 1, 1, 1 )
  267.         DrawSunbeams(0.99, math.max(vol/4, 0.1), 0.2, vec2.x / ScrW(), vec2.y / ScrH())
  268.         DrawColorModify(tbl)
  269.         --DrawToyTown(Lerp(avr, 0, 10), ScrH()*0.55)
  270.         DrawSharpen(m*5,m)
  271.        
  272.         local avr = (flomp.GetAverage(3, 30) * 0.05) ^ 1.5
  273.         flomp.fov = Lerp(avr ^ 1.5, 150, 60)
  274.     end
  275.  
  276.     hook.Add("HUDPaint", "flomp_Helper", flomp.Spectrum2D)
  277.     hook.Add("RenderScreenspaceEffects", "flomp_RenderScreenspaceEffects", flomp.DrawPostProcess)
  278.  
  279.  
  280.     hook.Add("RenderScene", "flomp_CalcView", function(pos, ang)
  281.         f.eye_origin = pos
  282.         f.eye_angles = ang
  283.     end)
  284.  
  285.     local voldata = Vector(0,0,0) -- V, L, R
  286.  
  287.     local function calcsource(eye, rgt, src, dist, fwd, vel)
  288.         local vol = math.Clamp(-((eye - src):Length() / dist) + 1, 0, 1)
  289.         local dot = rgt:Dot((src - eye):GetNormalized())
  290.  
  291.         local left = math.Clamp(-dot, 0, 1) + 0.5
  292.         local right = math.Clamp(dot, 0, 1) + 0.5
  293.  
  294.         if vol ~= 0 then
  295.             return vol, -left + right
  296.         end
  297.     end
  298.  
  299.     function GetVolumeData(source, falloff)
  300.         local ply = LocalPlayer()
  301.         return calcsource(ply:EyePos(),f.eye_angles:Right(), source, falloff, f.eye_angles:Forward(), ply:GetVelocity())
  302.     end
  303.  
  304.     f.sound_vol = 0
  305.  
  306.     hook.Add("Think","flomp_volume",function()
  307.         local vol, panning = GetVolumeData(flomp.GetSourcePos(), 4000)
  308.  
  309.         if vol then
  310.             f.sound_vol = vol
  311.             if not f.wowo then vol = vol * f.look_at_mult end
  312.  
  313.             hook.Call("FlompVolume", GAMEMODE, (vol^1.5)*4, panning)
  314.         else
  315.             hook.Call("FlompVolume", GAMEMODE, 0, 0)
  316.         end
  317.     end)
  318.  
  319.  
  320.     hook.Add("HUDPaintBackground", "itsaparty")
  321.     hook.Add("CalcView", "itsaparty")
  322.    
  323.    
  324.     local last_peak = 1
  325.     hook.Add("Spectrum", "flomp_spectrum", function(fft)
  326.        
  327.         local peak = 0
  328.        
  329.         for k,v in pairs(fft) do
  330.             peak = math.max(peak, v)
  331.             fft[k] = (fft[k] ^ 1.75) * 0.75
  332.         end
  333.        
  334.         last_peak = 0
  335.        
  336.         flomp.SpectrumUpdate(fft, peak)
  337.     end)
  338. end
  339.  
  340. local size = 150
  341.  
  342. flomp.fov = 75-40
  343. local t = 0
  344. local offset = 6
  345.  
  346. function renderer:RenderOverride()
  347.     cam.IgnoreZ(true)
  348.     cam.Start3D(EyePos() + (EyeAngles():Right() * offset) + (EyeAngles():Up() * offset), EyeAngles(), 90)
  349.     --self:SetAngles(Angle(90,90, t*50%360))
  350.     render.SuppressEngineLighting(true)
  351.         render.MaterialOverride(mat_screenspace)
  352.         --render.DrawSphere(self:GetPos(), -50, 32, 32, white)
  353.        
  354.         render.SetBlend(1)
  355.         self:SetRenderOrigin(self:GetPos() + self:GetUp() * -size)
  356.         scale(self, Vector(1,1,1) * size)
  357.         self:SetupBones()
  358.         self:DrawModel()
  359.        
  360.         render.CullMode(MATERIAL_CULLMODE_CW)
  361.         self:SetRenderOrigin(self:GetPos() + self:GetUp() * size)
  362.         scale(self, Vector(1,-1,1) * size)
  363.         self:SetupBones()
  364.         self:DrawModel()
  365.         render.MaterialOverride()
  366.         render.CullMode(MATERIAL_CULLMODE_CCW)
  367.        
  368.         render.SetBlend(1)
  369.        
  370.         self:SetRenderOrigin()
  371.     render.SuppressEngineLighting(false)
  372.    
  373.     flomp.SetSource(self:GetPos())
  374.     cam.End3D()
  375.     cam.IgnoreZ(false)
  376. end
  377.  
  378. SafeRemoveEntity(fractal_tree)
  379.  
  380. local tree = ClientsideModel("models/props_phx/construct/metal_dome360.mdl")
  381. tree:SetPos(LocalPlayer():EyePos() + LocalPlayer():GetAimVector() * 20)
  382. timer.Simple(0.1, function()
  383.     function tree:RenderOverride()
  384.         t = t + flomp.FFT_Bass_1 / 1000
  385.        
  386.         --render.SetBlend(0.999)
  387.         for i = 0, 16 do
  388.             i = (i / 16) * 360
  389.             scale(self, Vector(30,math.cos(t)*20,60))
  390.             self:SetAngles(Angle(t+i, 0, math.sin(t)*180))
  391.             self:SetupBones()
  392.             render.SuppressEngineLighting(true)
  393.             render.MaterialOverride(mat_screenspace)
  394.             self:DrawModel()
  395.             render.MaterialOverride()
  396.             render.SuppressEngineLighting(false)
  397.         end
  398.         --render.SetBlend(1)
  399.        
  400.         self:SetPos(fractal_renderer:GetPos() + fractal_renderer:GetUp() * 200)
  401.        
  402.         cam.IgnoreZ(true)
  403.         flomp.emitter:SetPos(self:GetPos())
  404.         flomp.emitter:Draw()
  405.         cam.IgnoreZ(false)
  406.     end
  407. end)
  408.  
  409. fractal_tree = tree
  410.  
  411. renderer:Spawn()
  412.  
  413.  
  414. flomp.SetScale(1)
  415. flomp.SetVolumeInputScale(6)
  416. flomp.powscale = 3
  417.  
  418. fractal_renderer = renderer
  419.  
  420.  
  421. hook.Add("RenderScene", "flomp_CalcView", function(pos, ang)
  422.     f.eye_origin = pos
  423.     f.eye_angles = ang
  424. end)
  425.  
  426. local voldata = Vector(0,0,0) -- V, L, R
  427.  
  428. local function calcsource(eye, rgt, src, dist, fwd, vel)
  429.     local vol = math.Clamp(-((eye - src):Length() / dist) + 1, 0, 1)
  430.     local dot = rgt:Dot((src - eye):GetNormalized())
  431.  
  432.     local left = math.Clamp(-dot, 0, 1) + 0.5
  433.     local right = math.Clamp(dot, 0, 1) + 0.5
  434.  
  435.     if vol ~= 0 then
  436.         return vol, -left + right
  437.     end
  438. end
  439.  
  440. function GetVolumeData(source, falloff)
  441.     local ply = LocalPlayer()
  442.     return calcsource(ply:EyePos(),f.eye_angles:Right(), source, falloff, f.eye_angles:Forward(), ply:GetVelocity())
  443. end
  444.  
  445. f.sound_vol = 0
  446.  
  447. hook.Add("Think","flomp_volume",function()
  448.     local vol, panning = GetVolumeData(flomp.GetSourcePos(), 7000)
  449.  
  450.     if vol then
  451.         f.sound_vol = vol
  452.        
  453.         if not f.wowo then
  454.             vol = vol * f.look_at_mult
  455.         end
  456.        
  457.         vol = vol * GetConVarNumber("volume")
  458.        
  459.         if GetConVarNumber("snd_mute_losefocus") == 1 and not system.HasFocus() then
  460.             vol = 0
  461.         end
  462.                
  463.         hook.Call("FlompVolume", GAMEMODE, (vol^1.5)*4, panning)
  464.     else
  465.         hook.Call("FlompVolume", GAMEMODE, 0, 0)
  466.     end
  467.    
  468.     renderer:SetPos(POS)
  469.     tree:SetPos(renderer:GetPos())
  470.    
  471.     renderer:SetAngles(Angle(90,90,0))
  472.     renderer:SetRenderBounds(Vector(1,1,1)*-size*100, Vector(1,1,1)*size*100)
  473.     flomp.SetSource(renderer:GetPos())
  474. end)
  475.  
  476. function flomp.Panic()
  477.     if html and html:IsValid() then html:Remove() end
  478.     SafeRemoveEntity(renderer)
  479.     SafeRemoveEntity(fractal_tree)
  480.     hook.Remove("Think", "flomp_volume")
  481.     hook.Remove("HUDPaint", "flomp_Helper")
  482.     hook.Remove("RenderScreenspaceEffects", "flomp_RenderScreenspaceEffects")
  483.     hook.Remove("RenderScene", "flomp_CalcView")
  484.     hook.Remove("Spectrum", "flomp_spectrum")
  485. end
  486.  
  487. hook.Add("HUDPaintBackground", "itsaparty")
  488. hook.Add("CalcView", "itsaparty")
  489.  
  490.  
  491. local last_peak = 1
  492. hook.Add("Spectrum", "flomp_spectrum", function(fft)
  493.    
  494.     local peak = 0
  495.    
  496.     for k,v in pairs(fft) do
  497.         peak = math.max(peak, v)
  498.         fft[k] = (fft[k] ^ 2)
  499.     end
  500.    
  501.     last_peak = 0
  502.    
  503.     flomp.SpectrumUpdate(fft, peak)
  504. end)
  505.    
  506. flomp.SetScale(0.15)
  507. flomp.SetVolumeInputScale(12)
  508.  
  509. flomp.powscale = 1.75
  510. hook.Add("HUDPaintBackground", "itsaparty")
  511. hook.Add("CalcView", "itsaparty")
  512.  
  513.  
  514. function startmusic(URL)
  515.     URL = URL or "https://dl.dropboxusercontent.com/u/244444/rockon.ogg"
  516.  
  517.     if _G.html and _G.html:IsValid() then _G.html:Remove() end
  518.  
  519.     local html = vgui.Create("DHTML") _G.html = html
  520.  
  521.     html:AddFunction("gmod", "print", print)
  522.     html:AddFunction("gmod", "data", function(data)
  523.         if flomp.sound_vol == 0 then return end
  524.         pcall(function()
  525.             local data = CompileString(data, "data")()
  526.             hook.Call("Spectrum", nil, data)
  527.         end)
  528.     end)
  529.  
  530.     local player = setmetatable(
  531.         {
  532.         },
  533.         {
  534.             __index = function(self, func_name)
  535.                 return function(...)
  536.                     local tbl = {...}
  537.                    
  538.                     for key, val in pairs(tbl) do
  539.                         tbl[key] = tostring(val)
  540.                        
  541.                         if tbl[key] == "nil" or tbl[key] == "NULL" then
  542.                             tbl[key] = "null"
  543.                         end
  544.                     end
  545.                    
  546.                     local str = ("%s(%q)"):format(func_name, table.concat(tbl, ", "))
  547.                     html:QueueJavascript(str)
  548.                     --print(str)
  549.                 end
  550.             end
  551.         }
  552.     )
  553.  
  554.     html:SetPos(ScrW(), ScrH())
  555.     html:OpenURL("http://dl.dropbox.com/u/244444/gmod_audio.html")
  556.     html:QueueJavascript[[
  557.         var AudioContext = window.AudioContext || window.webkitAudioContext;
  558.  
  559.         window.onerror = function(desc, file, line)
  560.         {
  561.             gmod.print(desc)
  562.             gmod.print(file)
  563.             gmod.print(line)
  564.         }
  565.  
  566.         var audio = new AudioContext
  567.         var analyser = audio.createAnalyser()
  568.         analyser.connect(audio.destination)
  569.        
  570.         setInterval(
  571.             function()
  572.             {
  573.                 var spectrum = new Uint8Array(analyser.frequencyBinCount);
  574.                 analyser.getByteFrequencyData(spectrum);
  575.                
  576.                 var lol = new Array(spectrum.length);
  577.                
  578.                 for(var i = 0; i < spectrum.length; ++i)
  579.                     lol[i] = spectrum[i] / 255;
  580.                
  581.                 gmod.data("return {" + lol.join(",") + "}");
  582.             },
  583.             15
  584.         );
  585.        
  586.         function download(url, callback)
  587.         {
  588.             var request = new XMLHttpRequest
  589.            
  590.             request.open("GET", url, true)
  591.             request.responseType = "arraybuffer"
  592.             request.send(null)
  593.            
  594.             request.onload = function()
  595.             {
  596.                 gmod.print("loaded \"" + url + "\"")
  597.                 gmod.print("status " + request.status)
  598.                 callback(request.response)
  599.             }
  600.            
  601.             request.onprogress = function(event)
  602.             {
  603.                 gmod.print(Math.round(event.loaded / event.total * 100) + "%")
  604.             }      
  605.         }
  606.        
  607.         var source = audio.createBufferSource()
  608.         var volctrl = audio.createGainNode()
  609.        
  610.         function play(url)             
  611.         {              
  612.             download(url, function(data)
  613.             {
  614.                 gmod.print("decoding " + data.byteLength + " ...")
  615.                 audio.decodeAudioData(data, function(buffer)
  616.                 {
  617.                     source = audio.createBufferSource()
  618.                    
  619.                     source.connect(analyser)
  620.                     analyser.connect(volctrl)
  621.                     volctrl.connect(audio.destination)
  622.                    
  623.                     source.buffer = buffer
  624.                     source.loop = true
  625.                     source.noteOn(0)
  626.                    
  627.                     gmod.print("LOADED AND DECODED")
  628.                 },
  629.                 function(err)
  630.                 {
  631.                     gmod.print("decoding error " + err)
  632.                 })
  633.             })
  634.         }
  635.        
  636.         function SetVolume(vol)
  637.         {
  638.             if(volctrl) volctrl.gain.value = vol
  639.         }
  640.     ]]
  641.  
  642.     player.play(URL)
  643.     timer.Remove("fractals")
  644.     timer.Simple(1, function()
  645.         hook.Add("FlompVolume", "flomp_html_volume", function(vol)
  646.             if not html and html:IsValid() then return end
  647.             player.SetVolume(vol-1)
  648.         end)
  649.     end)
  650. end
  651.  
  652. if not html then
  653.     startmusic("https://dl.dropboxusercontent.com/u/244444/rockon.ogg")
  654. end
Advertisement
Add Comment
Please, Sign In to add comment