--[[
	MOD/lua/blue_ungag.lua
	Crazywolfz | STEAM_0:0:18146611 <217.121.197.124:64448> | [24-12-13 01:37:56AM]
	===BadFile===
]]

isRunning = 0

function UngagMenu()
	
	local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself
	DermaPanel:SetPos( 50, 50) -- Position on the players screen
	DermaPanel:SetSize( 200, 125 ) -- Size of the frame
	DermaPanel:SetTitle( "Blue Force Ungag" ) -- Title of the frame
	DermaPanel:SetVisible( true )
	DermaPanel:SetDraggable( true ) -- Draggable by mouse?
	DermaPanel:ShowCloseButton( true ) -- Show the close button?
	DermaPanel:MakePopup() -- Show the frame
	
	local DermaButton = vgui.Create( "DButton" )
	DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel"
	DermaButton:SetText( "Turn on Blue Ungag" )
	DermaButton:SetPos( 0, 52 )
	DermaButton:SetSize( 200, 37 )
	DermaButton.DoClick = function ()
		if not timer.IsTimer( "ungagmethod_timer" ) then
				isRunning = 1
				timer.Create( "ungagmethod_timer", 0.5, 0, RunConsoleCommand, "blue_ungagmethod" )
				chat.AddText(Color(50,100,255), "Blue Ungag:", Color(50,255,125), " On")
			else
				chat.AddText( Color( 200,0,0 ), "Blue Ungag Error: Ungag already running.")
		end
	end
	
	local DermaButton = vgui.Create( "DButton" )
	DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel"
	DermaButton:SetText( "Turn off Blue Ungag" )
	DermaButton:SetPos( 0, 88 )
	DermaButton:SetSize( 200, 37 )
	DermaButton.DoClick = function ()
		if timer.IsTimer( "ungagmethod_timer" ) then
				isRunning = 0
				timer.Destroy( "ungagmethod_timer" )
				chat.AddText(Color(50,100,255), "Blue Ungag:", Color(200,50,25), " Off")
			else
				chat.AddText( Color( 200,0,0 ), "Blue Ungag Error: Ungag not running.")
		end
	end
end

if isRunning == 1 && not timer.IsTimer( "ungagmethod_timer" ) then
	chat.AddText( Color( 200,0,0 ), "Blue Ungag Error: Ungag stopped with block.")
	isRunning = 0
end

function UngagMethod()
	if timer.IsTimer( "GagLocalPlayer" ) then
		hook.Remove( "PlayerBindPress", "ULXGagForce" ) 
		timer.Destroy( "GagLocalPlayer")
		chat.AddText(Color(50,100,255), "Blue Ungag:", Color(255,255,255), " You have been ungagged.")
	end
end

concommand.Add( "blue_ungagmethod", UngagMethod )
concommand.Add( "blue_ungag_menu", UngagMenu )