⚙ī¸Integration

Information about how to integrate our tablet system with your server's resources.

📂 Tablet opening

1ī¸âƒŖ Opening with an item

The resource configuration is pre-set for the tablet to open with an item by default. To make this feature work, you also need to create an item in your inventory with the ID of app_tablet.

Add this section to ox_inventory/data/items.lua

['app_tablet'] = {
    label = 'Tablet',
    weight = 0,
    description = 'You can install different applications onto this.',
    stack = false,
    client = {
        export = 'rahe-tablet.tablet'
    }
}

Add the following image file as ox_inventory/web/images/app_tablet.png

https://media.rahe.dev/img/app_tablet.png

If you didn't name the item app_tablet, adjust the itemId in resource config accordingly.


2ī¸âƒŖ Opening with a command

If you don't wish the tablet to be an item, then in resource/config/shared.lua, change the openMethod option from inventory to command. Use the command /tablet in-game to open the application tablet.

📑 Enabling application installs

By default, application installations are disabled, meaning all applications are visible on the tablet. However, you have the option to enable them:

  • Navigate to /resource/config/shared.lua and set installEnabled to true.

  • In config/client.lua set requireInstall to true for applications you want to require installation.

If you wish to configure options for RAHE resources, then head to /resource/client/integrations.lua. In the default resource, all of our applications have requireInstall set to true, meaning they will need to be installed if you enable installations.

đŸ’ŋ Application installation

To install applications, you need to trigger the following server-side export:

exports['rahe-tablet']:installApplication(playerId, appId, slot)

This export will mark the application as installed, indicated by a progress circle. For example, to install our boosting application for player ID 1, who has a tablet in his inventory slot 4, you would use:

exports['rahe-tablet']:installApplication(1, 'rahe-boosting', 4)

You might wonder about the purpose of the slot variable. This variable is necessary only when you've configured the appInstallTarget in /resource/config/shared.lua to metadata (which is only applicable when using ox_inventory!). In this case, the slot variable is used retrieve the item in that specific slot and save the installed application ID into the metadata of that item.

Code example for ox_inventory

To install the application rahe-racing from a USB stick, follow these steps:

  1. Add the installation USB item to ox_inventory/data/items.lua:

['usb_racing'] = {
    label = 'USB stick',
    weight = 50,
    description = 'An USB stick with a racing program installed onto it.',
    stack = false,
    client = {
       export = 'rahe-tablet.usb_install'
    }
},
  1. Add the usb_install export to a client-side file in rahe-tablet, such as the end of /resource/client/integrations.lua:

exports('usb_install', function(data, slot)
    local metadata = {}
    if data.name == 'usb_racing' then
        metadata = {
            appId = 'rahe-racing',
            appName = 'Racing'
        }
    elseif data.name == 'usb_boosting' then
        metadata = {
            appId = 'rahe-boosting',
            appName = 'Boosting'
        }    
    elseif data.name == 'usb_drifting' then
        metadata = {
            appId = 'rahe-drifting',
            appName = 'Drifting'
        }
    elseif data.name == 'usb_trucking' then
        metadata = {
            appId = 'kub_trucking',
            appName = 'Trucking'
        }
    end

    slot.metadata = metadata
    TriggerServerEvent('rahe-tablet:server:installApp', slot, false)
end)
  1. Create the server-side event to handle installation. Register the event as follows at the end of /resource/server/installation.lua:

RegisterNetEvent('rahe-tablet:server:installApp', function(slot, useMetadata)
    local src = source
    if not slot or not slot.slot or not slot.metadata.appId then
        return
    end

    local tabletSlots = exports.ox_inventory:Search(src, 'slots', shConfig.itemId)
    if not next(tabletSlots) then
        lib.notify(src, { 
            title = ("You don't have a tablet to install the application '%s' onto."):format(slot.metadata.appName), 
            type = 'error' 
        })
        return
    end

    local canInstall = canStartInstallation(src, slot.metadata.appId, tabletSlots[1].slot)
    if canInstall ~= true then
        lib.notify(src, { title = canInstall, type = 'error' })
        return
    end

    if not exports.ox_inventory:RemoveItem(src, slot.name, 1, useMetadata and slot.metadata or nil, slot.slot) then
        return
    end

    installApplication(src, slot.metadata.appId, tabletSlots[1].slot)
    lib.notify(src, { 
        title = ("You have installed the application '%s' onto your tablet."):format(slot.metadata.appName), 
        type = 'success' 
    })
end)

(it's in the same file as the export function, so we are using the installApplication function directly)

Last updated