

/*---------------------------------------------------------
   Initializes the effect. The data is a table of data 
   which was passed from the server.
---------------------------------------------------------*/
function EFFECT:Init( data )
	
	// HumanGibs is defined in gamemode shared 
	// (because we need to precache the models on the server before we can use the physics)
	local iCount = tablex.Count( HumanGibs )
	
	
	self.Entity:SetModel( HumanGibs[ math.random( iCount ) ] )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMaterial( "models/flesh" )
	
	// Only collide with world/static
	self.Entity:SetCollisionGroup( COLLISION_GROUP_DEBRIS )
	self.Entity:SetCollisionBounds( Vector( -128 -128, -128 ), Vector( 128, 128, 128 ) )
	
	local phys = self.Entity:GetPhysicsObject()
	if ( phys && phys:IsValid() ) then
	
		phys:Wake()
		phys:SetAngle( Angle( mathx.Rand(0,360), mathx.Rand(0,360), mathx.Rand(0,360) ) )
		phys:SetVelocity( data:GetNormal() * mathx.Rand( 100, 300 ) + VectorRand() * mathx.Rand( 10, 100 ) )
	
	end
	
	self.LifeTime = CurTime() + mathx.Rand( 10, 20 )
	
	
	local emitter = ParticleEmitter( data:GetOrigin() )
	
		local particle = emitter:Add( "effects/blood_core", data:GetOrigin() )
			particle:SetVelocity( data:GetNormal() * mathx.Rand( 5, 20 ) )
			particle:SetDieTime( mathx.Rand( 1.0, 2.0 ) )
			particle:SetStartAlpha( 255 )
			particle:SetStartSize( mathx.Rand( 8, 32 ) )
			particle:SetEndSize( mathx.Rand( 48, 64 ) )
			particle:SetRoll( mathx.Rand( 0, 360 ) )
			particle:SetColor( 40, 0, 0 )
				
	emitter:Finish()
	
end


/*---------------------------------------------------------
   THINK
   Returning false makes the entity die
---------------------------------------------------------*/
function EFFECT:Think( )

	return ( self.LifeTime > CurTime() ) 
	
end


/*---------------------------------------------------------
   Draw the effect
---------------------------------------------------------*/
function EFFECT:Render()

	self.Entity:DrawModel()

end



