As you said, you have to check if the mouse button is clicked out of the inventory.

Code:
if ( !mouse_panel )
{
	if ( inv_is_floating() )
	{
		if ( mouse_left )
		{
			var item_id = inv_get_floating_icon_item ();
			switch ( item_id )
			{
				case SNIPERGUN:   ent_create ( "snipergun.mdl",  nullvector, NULL );  break;
				case SHOTGUN:     ent_create ( "shotgun.mdl",    nullvector, NULL );  break;
				case MACHINEGUN:  ent_create ( "machinegun.mdl", nullvector, NULL );  break;
			}
		}
	}
}