Developer

2 min readUpdated 2 weeks ago

Overview

ML Autocapture exposes server helpers for opening the studio and resolving generated images, and a client function that captures an existing entity.

Server exports

Open the studio

  • OpenStudio(source): Opens the full studio for a real player source. Returns true when the request is accepted or false when the resource is locked or the source is invalid. It does not check permissions, so check access in the calling resource.
lua
1local opened = exports['ml_autocapture']:OpenStudio(source)

Resolve generated images

  • getImage(key): Returns a nui:// URL for the first matching PNG, JPG or WebP in the self-contained output and then ox_inventory. Returns nil when no image exists.
  • getImages(keys): Resolves an array of keys and returns a table keyed by the original values.
lua
1local url = exports['ml_autocapture']:getImage('model_windowway_metal')
2local urls = exports['ml_autocapture']:getImages({ 'adder', 'sultan', 'model_windowway_metal' })

Client exports

Admin menu integration

  • MLAdminPanel(): Returns the admin-menu label and icon when the command is enabled.
  • MLAdminOpen(): Executes the configured studio command.
lua
1local entry = exports['ml_autocapture']:MLAdminPanel()
2exports['ml_autocapture']:MLAdminOpen()

Capture an existing entity

  • CaptureEntity(entity, key, options?): Moves an existing vehicle or ped into the studio, creates a transparent image in the self-contained output, restores the entity and returns its nui:// URL, or the image data with returnData = true. Returns nil if the studio is busy, the entity is invalid or capture fails.
lua
1local url = exports['ml_autocapture']:CaptureEntity(entity, 'preview_vehicle', {
2    width = 512,
3    height = 512,
4    format = 'png',
5    quality = 92,
6    yaw = 35.0,
7    pitch = -8.0,
8    fov = 40.0,
9    margin = 1.25,
10    returnData = false,
11})

Supported options are width, height, format, quality, yaw, pitch, fov, margin and returnData. height defaults to width, and keys are cut to 64 characters.

Commands

  • autocapture_cancel: cancels the running batch. Bound to Backspace by default

Client event

  • ml_autocapture:entityCaptured: Fires locally after CaptureEntity completes. Parameters are the sanitized key and the resulting URL or nil.
lua
1AddEventHandler('ml_autocapture:entityCaptured', function(key, url)
2    if not url then return end
3    print(key, url)
4end)

File naming

Capture keys are converted to lowercase, stripped to letters, digits, underscores and dashes, and cut to 64 characters. Prop batches use each entry's item value as the key and use model only for spawning the object.