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

include('shared.lua')

local MODEL = Model( "models/props_wasteland/prison_lamp001c.mdl" )

/*---------------------------------------------------------
   Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()

	self.Entity:SetModel( MODEL )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	
	local phys = self.Entity:GetPhysicsObject()
	
	if (phys:IsValid()) then
		phys:Wake()
	end
	
	self:Toggle()
	
end


/*---------------------------------------------------------
   Name: Sets the color of the light
---------------------------------------------------------*/
function ENT:SetLightColor( r, g, b )

	self.Entity:SetVar( "lightr", r )
	self.Entity:SetVar( "lightg", g )
	self.Entity:SetVar( "lightb", b )
	
	self.Entity:SetColor( r, g, b, 255 )

end

/*---------------------------------------------------------
   Name: OnTakeDamage
---------------------------------------------------------*/
function ENT:OnTakeDamage( dmginfo )
	self.Entity:TakePhysicsDamage( dmginfo )
end


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

end

/*---------------------------------------------------------
   Name: Toggle
---------------------------------------------------------*/
function ENT:Toggle()

	if ( self.flashlight ) then
	
		SafeRemoveEntity( self.flashlight )
		self.flashlight = nil
		self:SetOn( false )
		return
	
	end

	self:SetOn( true )
	
	self.flashlight = ents.Create("effect_flashlight")
		self.flashlight:SetPos( self.Entity:GetPos() )
		self.flashlight:SetAngles( self.Entity:GetAngles() )
		self.flashlight:SetParent( self.Entity )
		self.flashlight:SetColor( self.Entity:GetVar( "lightr", 255 ), self.Entity:GetVar( "lightg", 255 ), self.Entity:GetVar( "lightb", 255 ), 255 )
	self.flashlight:Spawn()

end


