
include("shared.lua")
if CLIENT then
local jammat = Material( "models/shtormer/sania/jam.png" )
local flag1 = false

	function ENT:Think()
		if LocalPlayer():lvsGetVehicle():IsValid() then
			if LocalPlayer():lvsGetVehicle():GetNWEntity("UAVControl"):IsValid() then
				self:SetNWEntity("Jamming", LocalPlayer():lvsGetVehicle())
				jammer = ents.FindByClass( "sw_sania" )
				if jammer != nil then
					for i =1, #jammer do
						if jammer[i]:IsValid() then
							if LocalPlayer():lvsGetVehicle():GetPos():Distance(jammer[i]:GetPos()) < jammer[i].JamDistance then
								flag1 = true
							end
						end
					end
					if LocalPlayer():lvsGetVehicle():GetNWBool("Jammed") and !flag1 then
						LocalPlayer():lvsGetVehicle():SetNWBool("Jammed", false)
						flag1 = false
					elseif flag1 then
						LocalPlayer():lvsGetVehicle():SetNWBool("Jammed", true)
					end
				else
					flag1 = false
				end
			end 
			if LocalPlayer():lvsGetVehicle():GetNWBool("Jammed") and LocalPlayer():lvsGetVehicle():GetPos():Distance(self:GetPos()) < self.JamDistance and self:IsValid() and LocalPlayer():lvsGetVehicle():IsValid() and self != NULL then
				print(LocalPlayer():lvsGetVehicle():GetNWEntity("UAVControl"):IsValid())
				hook.Add( "HUDPaint", "uavjamsania", function()
					if self != NULL and LocalPlayer():lvsGetVehicle() != NULL then
						surface.SetDrawColor( 255, 255, 255, 255/(LocalPlayer():lvsGetVehicle():GetPos():Distance(self:GetPos())/self.FullJamDistance) ) -- Set the drawing color
						surface.SetMaterial( jammat ) -- Use our cached material
						surface.DrawTexturedRect( 0, 0, ScrW(), ScrH() ) -- Actually draw the rectangle
					end
				end )
			elseif !LocalPlayer():lvsGetVehicle():GetNWBool("Jammed") or !LocalPlayer():lvsGetVehicle():IsValid() or !self:IsValid() or self == NULL or LocalPlayer():lvsGetVehicle() == NULL or LocalPlayer():lvsGetVehicle():GetNWEntity("UAVControl"):IsValid() == NULL then
				hook.Remove( "HUDPaint", "uavjamsania" )
			end
		end
	end

	function ENT:Draw()
		self:DrawModel()
	end

end
