AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "ghostentity.lua" )
AddCSLuaFile( "object.lua" )
AddCSLuaFile( "stool.lua" )
AddCSLuaFile( "cl_viewscreen.lua" )
AddCSLuaFile( "stool_cl.lua" )


SWEP.Weight			= 5
SWEP.AutoSwitchTo		= false
SWEP.AutoSwitchFrom		= false

/*---------------------------------------------------------
   Desc: Convenience function to check object limits
---------------------------------------------------------*/
function SWEP:CheckLimit( str ) 

	// No limits in single player
	if (SinglePlayer()) then return true end

	local ply = self.Weapon:GetOwner()
	local c = server_settings.Int( "sbox_max"..str, 0 )
	if ( ply:GetCount( str ) > c-1 ) then ply:LimitHit( str ) return false end
	
	return true

end

/*---------------------------------------------------------
   Name: CC_GMOD_Tool
   Desc: Console Command to switch weapon/toolmode
---------------------------------------------------------*/
function CC_GMOD_Tool( player, command, arguments )

	if ( arguments[1] == nil ) then return end
	if ( GetConVarNumber( "toolmode_allow_"..arguments[1] ) != 1 ) then return end
	
	player:ConCommand( "gmod_toolmode "..arguments[1] )
	
	local activeWep = player:GetActiveWeapon()
	local isTool = (activeWep && activeWep:IsValid() && activeWep:GetClass() == "gmod_tool")
	
	// Switch weapons
	player:SelectWeapon( "gmod_tool")

	// Get the weapon and send a fake deploy command
	local wep = player:GetWeapon("gmod_tool")
	if (wep:IsValid()) then
		if (not isTool) then
			wep:GetTable().wheelModel = nil
		end
		wep:GetTable():Deploy()
		wep:GetTable().Mode = arguments[1]
	end
	
end

concommand.Add( "gmod_tool", CC_GMOD_Tool )
concommand.Add( "dynamite_explode", construct.CC_Dynamite_Explode )

include('shared.lua')