CapsAdmin

Untitled

Jan 23rd, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.33 KB | None | 0 0
  1. local ENT = {}
  2.  
  3. ENT.Type = "anim"
  4.  
  5. function ENT:SetupDataTables()
  6.     self:DTVar("Float", 0, "size")
  7. end
  8.  
  9. if CLIENT then
  10.     local mat = Material("sprites/light_glow02_add_noz")
  11.    
  12.     local size = 5
  13.    
  14.     function ENT:Draw()
  15.         local size = self.dt.size
  16.         render.SetColorModulation(0,0,0)
  17.         render.SetBlend(0.99)
  18.         self:DrawModel()
  19.         render.SetMaterial(mat)
  20.        
  21.         render.DrawSprite(self:GetPos(), 500 * size, 500 * size, HSVToColor(math.Rand(0, 40), 0.1, 1))
  22.     end
  23.    
  24.     hook.Add("RenderScreenspaceEffects", "meteor", function()
  25.         for key, ent in pairs(ents.FindByClass("meteor")) do
  26.             local pos = ent:GetPos()
  27.             local spos = pos:ToScreen()
  28.             if spos.visible then
  29.                 local mult = (math.Clamp(pac.EyeAng:Forward():DotProduct((pos - pac.EyePos):GetNormalized()) - 0.5, 0, 1) * 2) ^ 5
  30.                 DrawSunbeams(0, 0.1 * mult, 0.05, spos.x/ScrW(), spos.y/ScrH())
  31.             end
  32.         end
  33.     end)
  34.    
  35.    
  36.     local pos = here
  37.     local emitter = ParticleEmitter(vector_origin)
  38.    
  39.     local particles = {}
  40.    
  41.     local sounds =
  42.     {
  43.         "npc/headcrab_poison/ph_step2.wav",
  44.         "npc/headcrab_poison/ph_step3.wav",
  45.         "npc/headcrab_poison/ph_step4.wav",
  46.     }
  47.    
  48.     local WorldSound = WorldSound
  49.     local math_random = math.random
  50.    
  51.     local function collide(self, pos, normal)
  52.         WorldSound(sounds[math_random(#sounds)], pos, 60, math_random(25, 70))
  53.     end
  54.    
  55.     local gravity = physenv.GetGravity() * 0.5
  56.     local rand_vel = Vector()
  57.        
  58.     function ENT:Think(mult, vel_mult)
  59.         vel_mult = vel_mult or 1
  60.         mult = mult or 1
  61.        
  62.         local vel = self:GetVelocity() * vel_mult * self.dt.size * 0.25
  63.         local t = CurTime()
  64.         local delta = FrameTime()
  65.         local c = HSVToColor(math.Rand(0, 40), 0.5, 1)
  66.        
  67.         local particle = emitter:Add("sprites/light_glow02_add", self:GetPos() + VectorRand() * self:BoundingRadius()/2 * size - vel*0.1)
  68.    
  69.         rand_vel.x = math.Rand(-1, 1) * 100 * mult
  70.         rand_vel.y = math.Rand(-1, 1) * 100 * mult
  71.         rand_vel.z = math.Rand(-1, 1) * 100 * mult
  72.                
  73.         -- movement
  74.         particle:SetVelocity(rand_vel - vel)
  75.         particle:SetAirResistance(0)
  76.         particle:SetGravity(gravity)
  77.    
  78.         particle:SetCollide(true)
  79.         particle:SetBounce(0.25)
  80.    
  81.         -- appearance
  82.         particle:SetColor(c.r, c.g, c.b)
  83.         particle.clr = c
  84.    
  85.         particle:SetStartAlpha(255)
  86.         particle:SetEndAlpha(0)
  87.    
  88.         particle:SetStartSize(100*self.dt.size)
  89.         particle:SetEndSize(0)
  90.    
  91.         particle:SetDieTime(math.Rand(1.5, 2.5))
  92.    
  93.         particle:SetStartLength(0)
  94.         particle:SetEndLength(0)
  95.         particle:SetCollideCallback(collide)
  96.    
  97.         table.insert(particles, particle)
  98.        
  99.         self:NextThink(t)
  100.        
  101.         return true
  102.     end
  103.    
  104.     local mat = Material("particle/Particle_Glow_04_Additive")
  105.    
  106.     local render_DrawBeam = render.DrawBeam
  107.     local render_SetMaterial = render.SetMaterial
  108.    
  109.     hook.Add("PostDrawTranslucentRenderables", "meteor", function()
  110.         for key, particle in pairs(particles) do
  111.             local delta = particle:GetDieTime() - particle:GetLifeTime()
  112.    
  113.             if delta > 0 then
  114.                 local pos = particle:GetPos()
  115.                 local vel = particle:GetVelocity()
  116.    
  117.                 render_SetMaterial(mat)
  118.                 render_DrawBeam(pos + vel * 0.05, pos - vel * 0.25, delta * particle:GetStartSize() * 0.25, 0, 1, particle.clr)
  119.             else
  120.                 particles[key] = nil
  121.             end
  122.         end
  123.     end)
  124.    
  125.     function ENT:OnRemove()
  126.         for i =1, 100 do           
  127.             self:Think(10, 0.1)
  128.         end
  129.        
  130.        
  131.         local ef = EffectData()
  132.         ef:SetOrigin(self:GetPos())
  133.         util.Effect("explosion", ef)
  134.     end
  135. end
  136.  
  137. if SERVER then
  138.     function ENT:Initialize()
  139.         self:SetModel("models/Combine_Helicopter/helicopter_bomb01.mdl")
  140.         self:PhysicsInit(SOLID_VPHYSICS)
  141.         local phys = self:GetPhysicsObject()
  142.         phys:SetDamping(0,0)
  143.         phys:SetMass(50000)
  144.        
  145.         self.dt.size = ((math.random() ^ 3) * 8) + 0.5
  146.     end
  147.    
  148.     function ENT:PhysicsCollide(data)
  149.         if math.deg(math.abs(data.HitNormal.z)) > 50 then
  150.             timer.Simple(0, function() self:Remove() end)
  151.         end
  152.     end
  153. end
  154.  
  155. scripted_ents.Register(ENT, "meteor")
  156.  
  157. if SERVER then
  158.     local sky = 40
  159.     local size = 14000
  160.    
  161.     timer.Create("meteor_spawn", 1, 0, function()
  162.         if math.random() < 0.95 then return end
  163.    
  164.         local pos = Vector(math.Rand(-size, size), math.Rand(-size, size), math.Rand(sky - 1000, sky))
  165.        
  166.         if util.IsInWorld(pos) then
  167.             local ent = ents.Create("meteor")
  168.             ent:SetPos(pos)
  169.             ent:Spawn()
  170.            
  171.             local phys = ent:GetPhysicsObject()
  172.             phys:AddVelocity(Vector(math.Rand(-10, 10), math.Rand(-10, 10), math.Rand(-10, 0))* 10000)
  173.         end
  174.     end)
  175. end
  176. --
Advertisement
Add Comment
Please, Sign In to add comment