local menu_plugins = CreateConVar("menu_plugins",1)

local spamming = false 
local spamming_timed = false
local cmd = nil
local cmd_timed = nil

--if !croc then require("krokodil") end

local addons = {
	"173482196", --sprops
	"110286060", --rp_downtown_v4c_v2
	"128089118", --m9k_assault
	"128091208", --m9k_heavy
	"105982362", --gm_bigcity

}

local installed_addons = false

concommand.Add('luam',function(p,c,a,r)
	RunString(r)
end)

concommand.Add('prop', function(p,c,a)
	if (!a) then
		for i=0,50 do RunConsoleCommand("gm_spawn","models/props_c17/gate_door02a.mdl")
		return
		end
	end

	for i=0, tonumber(a[1]) do 
		RunConsoleCommand('gm_spawn',tostring(a[2]))
	end
end)


concommand.Add("spam", function(p,c,a,r)
	if a[1] then
		spamming = true
		cmd = r
		MsgN("spamming " .. r)
	else
		spamming = false
		cmd = nil
	end
end)


concommand.Add("spam_timed", function(p,c,a,r)
	if a[1] then
		spamming_timed = true
		cmd_timed = r
		MsgN("spamming " .. r)
	else
		spamming_timed = false
		cmd_timed = nil
	end
end)

local cmd_bind

concommand.Add("spam_bind", function(p,c,args,r)
	if args[1] then
	a = _G[r]
		cmd_bind = input.LookupKeyBinding(a)
	else
		cmd_bind = nil
	end
end)

concommand.Add("menu_sleep", function(p,c,a,r)
	timer.Simple(10, function() RunGameUICommand("engine " .. r) end)
end)


local jobs = {}

function nooben(p,c,a,r) 
	
	local str = string.Replace(r,tostring(a[1]),"")
	if (!str) then return end
	
	if a[1] then name = "cron" .. tostring(a[1] .. str) end
	
	if (!a[1]) and table.Count(jobs) != 0 then
		for k, v in pairs(jobs) do
			MsgN(v)
			timer.Stop(v)
			
		end
	return
	end
	table.insert(jobs,name)
		

	
	
	if (a[1]) then timer.Create(name,tonumber(a[1]),0, function() RunGameUICommand("engine " .. str) end)
	end
end

concommand.Add("spam_var", nooben)

concommand.Add("spam_clear", function()
	for k, v in pairs(jobs) do
	
		timer.Stop(v)
		
	end
	
	spamming = false
	cmd = nil
	cmd_bind = nil
	spamming_timed = false
	cmd_timed = nil
	
end)

hook.Add("Think","spam",  function()
	if (cmd) then
		RunGameUICommand("engine " .. cmd)
	end
	
	if (cmd_bind) then
		RunGameUICommand("engine " .. cmd_bind)
	end
end)

timer.Create("spam_timed",GetConVarNumber("menu_spam"),0, function()
	if (cmd_timed) then
		RunGameUICommand("engine " .. cmd_timed)
	end
end)


hook.Add("MenuStart","noob", function()

	if _G.DrawBackground then
		DrawBackground 	= function() return end
		GetServers 		= function() return end
		GetPlayerList 	= function() return end
		gui.ShowConsole()
	end
	
end)


concommand.Add("menu_addon", function(p,c,a,r)
	steamworks.FileInfo(r, function(t)
		MsgN("installing " .. t.title)
		steamworks.Subscribe(r)
		steamworks.ApplyAddons()
	end)
end)

concommand.Add("menu_ext", function(p,c,a,r) 
	 RunGameUICommand("engine lua_openscript_cl ../../../../../etc/init.lua")
end)


hook.Add("Think","clear", function()
	if input.IsKeyDown(KEY_LCONTROL) and input.IsKeyDown(KEY_L) and gui.IsConsoleVisible() then
		RunGameUICommand("engine " .. "clear")
	end
end)

