Zaktak

csquadshield.lua

Nov 26th, 2020
492
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. if SERVER then
  4.     util.AddNetworkString("squad_shield_draw_circle")
  5.  
  6.     hook.Add('EntityTakeDamage','CSquadShield',function(ent,dmg)
  7.         if ent.PleaseKillMe then
  8.             local ed = EffectData()
  9.             local dmgpos = dmg:GetDamagePosition()
  10.             ed:SetOrigin(dmgpos)
  11.             ed:SetNormal((dmgpos-ent:GetPos()):GetNormalized())
  12.             ed:SetRadius(1)
  13.             util.Effect('cball_bounce',ed)
  14.             util.Effect('AR2Explosion',ed)
  15.             --ent:GetParent():EmitSound(('ambient/energy/weld%s.wav'):format(math.random(1,2)),80,math.random(144,192),.64)
  16.             return true
  17.         end
  18.     end)
  19.  
  20. end
  21.  
  22. if CLIENT then
  23.  
  24.     net.Receive("squad_shield_draw_circle", function()
  25.         sqshtab = {}
  26.         timer.Simple( .5, function()
  27.             for k, v in pairs( ents.GetAll() ) do
  28.                 if v:GetClass() == 'squad_shield' then
  29.                     sqshtab[ table.Count( sqshtab ) + 1] = v
  30.                 end
  31.             end
  32.         end)
  33.     end)
  34.  
  35.     local CDRAW = include('CDRAW.lua')
  36.  
  37.     surface.CreateFont('SHLACK',{font='Trebuchet MS',size=32,weight=400})
  38.  
  39.     local MSW, MSH = ScrW(), ScrH()
  40.     local off_h = MSH/2-32
  41.     local col_bg = Color(0,0,0,192)
  42.     local col_fill = Color(64,128,192,255)
  43.     local col_txt = Color(255,255,255)
  44.    
  45.     --[[
  46.     hook.Add('Tick','CSquadShield',function()
  47.         sqshtab = {}
  48.         for k,v in pairs(ents.GetAll()) do
  49.             if v:GetClass() == 'squad_shield' then
  50.                 sqshtab[#sqshtab+1] = v
  51.             end
  52.         end
  53.     end)
  54.     --]]
  55.  
  56.     hook.Add('HUDPaint','CSquadShield',function()
  57.         if !IsValid(LocalPlayer()) or !IsValid(LocalPlayer():GetActiveWeapon()) then return end
  58.         local squad_shield = LocalPlayer():GetNWEntity('CSquadShield')
  59.         if LocalPlayer():GetActiveWeapon():GetClass() == 'weapon_squadshield_arm' then
  60.             local cooldown = LocalPlayer():GetNWInt('CSqShCooldown',CurTime())-CurTime() <= 0 and ('Ready to deploy') or ('Cooldown: '..string.ToMinutesSeconds(LocalPlayer():GetNWInt('CSqShCooldown',CurTime())-CurTime()+1))
  61.             local str = IsValid(squad_shield) and (!squad_shield:GetActive() and cooldown or 'Deploy time: '..string.ToMinutesSeconds(squad_shield:GetTimeOffset()-CurTime()+squad_shield.LifeTime+1)) or cooldown
  62.             CDRAW.DrawRect(col_bg,MSW-256-16,off_h+80,256,64)
  63.             local fulfill = (IsValid(squad_shield) and squad_shield:GetActive()) and (squad_shield:GetTimeOffset()-CurTime()+squad_shield.LifeTime)/squad_shield.LifeTime or 0
  64.             CDRAW.DrawRect(col_fill,MSW-256-16+4,off_h+80+4,248*fulfill,56)
  65.             CDRAW.DrawText('SHLACK',MSW-256-8,off_h+80+16,col_txt,str)
  66.         end
  67.     end)
  68.  
  69.     surface.CreateFont('cents_ss',{font='Trebuchet MS',size=200})
  70.     surface.CreateFont('cents_ss_blur',{font='Trebuchet MS',size=200,blursize=4})
  71.  
  72.     local rendmat = Material('models/props_combine/stasisshield_sheet')
  73.     local rendmat2 = Material('models/props_combine/portalball001_sheet')
  74.     local beammat = Material('cable/physbeam')
  75.     local ringmat = Material('cable/blue_elec')
  76.     local solvemat = Material('effects/tool_tracer')
  77.     local text_col = Color(64,192,255)
  78.     local beamcol = Color(0,192,255)
  79.     local blue_shg = Color(0,64,255,64)
  80.     local quality = 32
  81.     local beamcount = 5
  82.     local beam_width = 4
  83.     local ring_width = 8
  84.     local spr = 128
  85.     local spr_rime = 0.1
  86.     local step = .02
  87.  
  88.     local function qc(t,p0,p1,p2)
  89.         return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2
  90.     end
  91.  
  92.     hook.Add('PostDrawTranslucentRenderables','CSquadShield',function(bDepth,bSkybox)
  93.         if bSkybox then return end
  94.         if ( sqshtab == nil ) then return end
  95.         for k,v in pairs(sqshtab) do
  96.             if !IsValid(v) or !v:GetActive() then continue end
  97.             local vpos = v:GetPos()
  98.             local qq1 = Vector(0,0,1)
  99.             local qq2 = qq1:Dot(vpos)
  100.             render.SetMaterial(beammat)
  101.             local startpos = vpos
  102.             local radius = v.Radius*v.SphereScale
  103.             local act_endpos = vpos+Vector(0,0,radius+16+math.sin(SysTime()*0.6)*32)
  104.             for pee = 0, beamcount-1 do
  105.                 local haha = math.pi*2*pee/beamcount
  106.                 local endpos = startpos+Vector(math.sin(haha+CurTime()*spr_rime)*spr,math.cos(haha+CurTime()*spr_rime)*spr,radius-32)
  107.                 local normal = (endpos-startpos):GetNormalized()
  108.                 local dist = startpos:Distance(endpos)
  109.                 local mt = Matrix()
  110.                 mt:SetAngles(normal:Angle()+Angle(90,0,0))
  111.                 local oldpos
  112.                 for i = 0, 1, step do
  113.                     local p = qc(i,startpos,act_endpos,endpos)
  114.                     if oldpos then
  115.                         render.DrawBeam(oldpos,p,beam_width,1,1,beamcol)
  116.                     end
  117.                     oldpos = p
  118.                 end
  119.             end
  120.             render.SetMaterial(ringmat)
  121.             for i = 1, quality do
  122.                 local p1 = vpos+Vector(math.sin((i/quality)*math.pi*2)*radius,math.cos((i/quality)*math.pi*2)*radius,0)
  123.                 local p2 = vpos+Vector(math.sin(((i+1)/quality)*math.pi*2)*radius,math.cos(((i+1)/quality)*math.pi*2)*radius,0)
  124.                 render.DrawBeam(p1,p2,ring_width,1,1,beamcol)
  125.             end
  126.             render.SetMaterial(solvemat)
  127.             render.DrawBeam(vpos+Vector(0,0,8),vpos+Vector(0,0,16),8,CurTime()*2,CurTime()*2-1,beamcol)
  128.             local oldEC = render.EnableClipping(true)
  129.             render.PushCustomClipPlane(qq1,qq2)
  130.             render.SetColorMaterial()
  131.             render.DrawSphere(vpos,radius,quality,quality,blue_shg)
  132.             render.SetMaterial(rendmat)
  133.             render.OverrideBlend(true,3,1,BLENDFUNC_ADD)
  134.             render.DrawSphere(vpos,radius,quality,quality)
  135.             render.OverrideBlend(false,3,1,BLENDFUNC_ADD)
  136.             render.SetMaterial(rendmat2)
  137.             render.OverrideBlend(true,2,1,BLENDFUNC_ADD)
  138.             render.DrawSphere(vpos,radius,quality,quality)
  139.             render.OverrideBlend(false,2,1,BLENDFUNC_ADD)
  140.             render.PopCustomClipPlane()
  141.             render.EnableClipping(oldEC)
  142.             local va = GetViewEntity():GetAngles()
  143.             local pos = vpos+Vector(0,0,64+math.sin(SysTime()*1.2)*2)
  144.             if v:GetShieldOwner() ~= LocalPlayer() then continue end
  145.             cam.Start3D2D(pos,Angle(0,va.y-90,90-va.p),0.08)
  146.                 CDRAW.DrawNiceText(text_col,0,'cents_ss','TIME LEFT: '..string.ToMinutesSeconds(v:GetTimeOffset()-CurTime()+v.LifeTime+1))
  147.             cam.End3D2D()
  148.         end
  149.     end)
  150. end
RAW Paste Data