🆔Unique ID

This script facilitates the setup of a unique ID for each player. The unique ID can be smoothly integrated into other scripts using the provided exports.

Features

  • Unique Player ID: Automatically assigns a unique ID to each player.

  • Easy Integration: Use exports to include the player ID in other scripts without hassle.

How to Use

  1. Include the Script: Ensure the script is included in your project.

  2. Use Exports: Utilize available exports to access player IDs within different scripts.

Exports

Both exports can be used from server and client side:

// Get UID from player ID
exports.cdx-uid:GetUIDfromID()
// Get ID from player UID
exports.cdx-uid:GetIDfromUID()

Example on setjob command for QBCore

QBCore.Commands.Add('setjob', Lang:t('command.setjob.help'), {
    { name = Lang:t('command.setjob.params.uid.name'), help = Lang:t('command.setjob.params.uid.help') },
    { name = Lang:t('command.setjob.params.job.name'), help = Lang:t('command.setjob.params.job.help') },
    { name = Lang:t('command.setjob.params.grade.name'), help = Lang:t('command.setjob.params.grade.help') }
}, true, function(source, args)
    local uid = tonumber(args[1])
    local targetId = exports.cdx:GetIDfromUID(uid)

    if targetId then
        local Player = QBCore.Functions.GetPlayer(targetId)
        if Player then
            Player.Functions.SetJob(tostring(args[2]), tonumber(args[3]))
            TriggerClientEvent('QBCore:Notify', source, Lang:t('success.job_set'), 'success')
        else
            TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
        end
    else
        TriggerClientEvent('QBCore:Notify', source, Lang:t('error.invalid_uid'), 'error')
    end
end, 'admin')

This setup ensures that each player is easily identifiable across scripts.

Last updated