--[[
Cvar Addon Module 0.2
====================

By Kyzer and Ulysses Team
For ULX 3.2x

Why this script:
You can now add sliders and toggleable buttons in the admin menu, from your server/gamemode/map configuration file.

Changelog:
v0.2: the only problem found has been fixed

Installation:
Place this file into "addons/ulx/lua/ulx/modules"


Here is some examples:
===================

ulx addCvarSlider <slider label> <console variable> <slider max value> <optional: deny overflow>
ulx addCvarSlider "Max Wire Thrusters:" "sbox_maxwire_thrusters" 20
ulx addCvarSlider "Max Wire Values:" "sbox_maxwire_values" 100 1

ulx addCvarButton <label when disabled> <label when enabled> <console variable>
ulx addCvarButton "Enable CDS" "Disable CDS" "CDS_Enabled"


Have fun ;-)
==========
]]


if file.Exists( "../lua/ulx/modules/cl/adminmenu.lua" ) then


	function ulx.cc_addCvarSlider( ply, command, argv, args )
		
		if ( #argv < 3 ) then return end
		local CVar, Max = tostring(argv[2]), tonumber(argv[3])
		if GetConVarNumber(CVar) > Max then game.ConsoleCommand( CVar .. " " .. Max .. "\n" ) end
		ulx.addToMenu( ulx.ID_MADMIN, tostring(argv[1]), { cvar = CVar, max = Max, denyOverflow = util.tobool(argv[4]) or false } )
		
	end
	ulx.concommand( "addCvarSlider", ulx.cc_addCvarSlider, "", ULib.ACCESS_NONE )
	

	function ulx.cc_addCvarButton( ply, command, argv, args )
		
		if ( #argv < 3 ) then return end
		ulx.addToMenu( ulx.ID_MADMIN, tostring(argv[3]), { button = true, off = tostring(argv[1]) , on = tostring(argv[2]) , cvar = tostring(argv[3]) } )
		
	end
	ulx.concommand( "addCvarButton", ulx.cc_addCvarButton, "", ULib.ACCESS_NONE )

	
end
