local glow_mat = Material("trails/physbeam") glow_mat:SetMaterialInt( "$spriterendermode", RENDERMODE_GLOW ) local orig_ball_size = 35 orig_ball_size = orig_ball_size / 2 function EFFECT:Init( data ) self.plane = data:GetEntity() if !ValidEntity(self.plane) then return end self.emitter = ParticleEmitter( self.plane:GetPos()) self:SetRenderBounds( Vector(-1000,-1000,-1000), Vector(1000,1000,1000)) self.start = CurTime() self.roller = ClientsideModel("models/Roller.mdl", RENDERGROUP_OPAQUE) self.roller:SetPos(self.plane:GetPos()) self:SetModel("models/props/sphere.mdl") //self:SetAngles(Angle(-90,0,0)) self:SetMaterial("models/props_combine/portalball001_sheet") self:SetColor(200,100,255,255) self.die = false self.scale = 0 self:SetPos(self.plane:GetPos()) //self:SetParent(self.plane) end function EFFECT:Think() --[[ if not ValidEntity(self.plane) then return false end]] local x = (CurTime() - self.start) if !self.die and x > WEP_EMP_CHARGE_TIME then self.scale = math.Approach(self.scale, WEP_EMP_RANGE / orig_ball_size, 10) elseif x > 5 + WEP_EMP_CHARGE_TIME then self.scale = self.scale - 5 if self.scale <= 0 then self.roller:Remove() return false end end if x < WEP_EMP_CHARGE_TIME then self.scale = self.scale + 0.02 end if (self.scale * orig_ball_size) >= WEP_EMP_RANGE then self.die = true end self:SetModelScale(Vector(self.scale,self.scale,self.scale)) if x > WEP_EMP_CHARGE_TIME and x < 5 and math.random(1,2) == 1 then local p_pos = Vector(math.sin(math.Rand(-4,4)),math.cos(math.Rand(-4,4)), math.sin(math.Rand(-4,4))) p_pos = p_pos * math.random(1, self.scale * orig_ball_size * 0.8) local p = self.emitter:Add("sprites/light_glow02_add", self:GetPos() + p_pos) if p then local vel = VectorRand() * 2 p:SetVelocity( vel ) p:SetDieTime(5+WEP_EMP_CHARGE_TIME-x + math.Rand(-1,0.5)) p:SetGravity( VectorRand() * 5 ) p:SetStartSize(math.random(500,520)) p:SetEndSize(math.random(780,800)) p:SetStartAlpha( math.Rand( 200, 255 ) ) p:SetAirResistance( 50 ) p:SetEndAlpha( 0 ) p:SetRoll(math.random(-30,30)) local col = math.random(210,230) p:SetColor(col,col,255,math.random(180,250)) end end return true end function EFFECT:DoSparks() local start = self:GetPos() local endpos = start + (Vector(math.sin(math.Rand(-4,4)), math.cos(math.Rand(-4,4)), math.sin(math.Rand(-4,4))) * self.scale * orig_ball_size * 0.8) local dist = start:Distance(endpos) local resolution = math.ceil(dist / 10) local dir = (start - endpos):Normalize() render.SetMaterial(glow_mat) render.StartBeam(math.floor(dist / resolution)) for i=0, dist, resolution do local pos = start + (dir * -i) if i != 1 and i != dist then pos = pos + (VectorRand() * 3) end render.AddBeam( pos, // Start position math.random(6,9), // Width CurTime(), // Texture coordinate Color( 255, 255, 255, 255 ) // Color ) end render.EndBeam() end function EFFECT:Render() for i=1, 20 do //draw inside an outside! self:DrawModel() local scale = self:GetModelScale() self:SetModelScale(scale * -1) end local scale = math.abs(self:GetModelScale().x) self:SetModelScale(Vector(scale,scale,scale)) if self.scale > 0.2 and (CurTime() - self.start) < WEP_EMP_CHARGE_TIME then for i=1,3 do self:DoSparks() end end end