AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )


function ENT:SpawnFunction( ply, tr )

	if ( !tr.Hit ) then return end
	
	local SpawnPos = tr.HitPos + tr.HitNormal * 64
	
	local ent = ents.Create( "anom_electro" )
	ent:SetPos( SpawnPos )
	ent:SetAngles( Angle(0,0,-180) )
	ent:Spawn()
	ent:Activate()

	return ent
	
end

function MakeSprite( Entity, fx, color, spritePath, scale, transity)
local Sprite = ents.Create("env_sprite");
Sprite:SetPos( Entity:GetPos() );
Sprite:SetKeyValue( "renderfx", fx )
Sprite:SetKeyValue( "model", spritePath)
Sprite:SetKeyValue( "scale", scale)
Sprite:SetKeyValue( "spawnflags", "1")
Sprite:SetKeyValue( "angles", "0 0 0")
Sprite:SetKeyValue( "rendermode", "9")
Sprite:SetKeyValue( "renderamt", transity)
Sprite:SetKeyValue( "rendercolor", color )

Sprite:Spawn()
Sprite:Activate()
Sprite:SetParent( Entity )

end 

/*---------------------------------------------------------
   Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()
	
	self.Entity:SetModel( "models/props_borealis/bluebarrel001.mdl" )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
--	self.Entity:SetKeyValue("targetname", "electroshock" ) 
	 
	local phys = self.Entity:GetPhysicsObject()
	
		  if (phys:IsValid()) then
			phys:EnableMotion(false)
		  end
	self.Entity:SetKeyValue("rendercolor", "150 150 255") 
	self.Entity:SetKeyValue("renderamt", "0") 
	self.Entity:SetMaterial("models/props_combine/portalball001_sheet")
	MakeSprite( self.Entity, "15", "255 255 128", "sprites/glow1.vmt", "3", "255")
	MakeSprite( self.Entity, "32", "250 250 250", "sprites/glow1.vmt", "1", "150")
	distort(self.Entity, self.Entity:GetPos())
end

--function distort(ent, pos)
--local gas = ents.Create("env_smokestack")
--gas:SetPos(pos)
--gas:SetKeyValue("InitialState", "1")
--gas:SetKeyValue("BaseSpread", "1")
--gas:SetKeyValue("SpreadSpeed", "5")
--gas:SetKeyValue("Speed", "5")
--gas:SetKeyValue("StartSize", "100")
--gas:SetKeyValue("EndSize", "2500")
--gas:SetKeyValue("Rate", "5")
--gas:SetKeyValue("JetLength", "50")
--gas:SetKeyValue("SmokeMaterial", "sprites/heatwave.vmt")
--gas:Spawn()
--gas:SetParent(ent)
--gas:Fire("turnon", "", 0)
--end

/*---------------------------------------------------------
   Name: PhysicsCollide
---------------------------------------------------------*/

/*---------------------------------------------------------
   Name: OnTakeDamage
---------------------------------------------------------*/
function ENT:OnTakeDamage( dmginfo )

	// React physically when shot/getting blown
	self.Entity:TakePhysicsDamage( dmginfo )
	
end


/*---------------------------------------------------------
   Name: Use
---------------------------------------------------------*/
function ENT:Use( activator, caller )

	self.Entity:Remove()
	
	if ( activator:IsPlayer() ) then
	

	end

end

function ENT:Think( )
	
	earange = math.random( 64, 512 )
	local b = ents.Create( "point_hurt" )
	b:SetKeyValue("targetname", "fier" ) 
	b:SetKeyValue("DamageRadius", earange )
	b:SetKeyValue("Damage", "15" )
	b:SetKeyValue("DamageDelay", "10" )
	b:SetKeyValue("DamageType", "1024" )
	b:SetPos( self.Entity:GetPos() )
	b:Spawn()
	b:Fire("turnon", "", 0)
	b:Fire("turnoff", "", 1)
	b:Fire("kill", "", 1)
	
--	local tesla = ents.Create( "point_tesla" )
--	tesla:SetKeyValue("targetname", "eletcro" ) --m_
--	tesla:SetKeyValue("m_flRadius", earange )--m_
--	tesla:SetKeyValue("m_SoundName", "DoSpark" )--m_
--	tesla:SetKeyValue("m_Color", "255 255 128" )--m_
--	tesla:SetKeyValue("beamcount_min", "4" )
--	tesla:SetKeyValue("beamcount_max", "16" ) 
--	tesla:SetKeyValue("thick_min", "4" )
--	tesla:SetKeyValue("thick_max", "5" )
--	tesla:SetKeyValue("lifetime_min", "0.3" )
--	tesla:SetKeyValue("lifetime_max", "0.3" )
--	tesla:SetKeyValue("interval_min", "0.5" )
--	tesla:SetKeyValue("interval_max", "2" )
--	tesla:SetKeyValue("m_SourceEntityName", "electroshock" ) --m_
--	tesla:SetPos( self.Entity:GetPos() )
--	tesla:Spawn()
--	tesla:Fire("turnon", "", 0)
--	tesla:Fire("turnoff", "", 1)
--	tesla:Fire("kill", "", 1)
	
end


