About dynamically adding a Job In game!

Hello! I hope you all are doing well. I just installed FiveM and started a local QBCore Server and tried to develop some new features. Furthermore, I tried to add an Input Menu that retrieve informations for a job and adds it to the existing ones using exports[‘qb-core’]:AddJob and/or QBCore.Functions.AddJob

It gives me an error "No Such Export AddJob in resource QBCore or in the case of using it as a Function it says "Attempt to call a nil value (field ‘addJob’)

What may cause this?

This is just from me reading docs and stuff so its to the best of my knowledge. :slight_smile:


At the stop of your script make sure to ALWAYS add.

local QBCore = exports['qb-core']:GetCoreObject()

These might some problems that could cause it though.

exports['qb-core']:AddJob(jobName, job)

Server

boolean, string

--[[ Accepts an job name and job object will add new entry to QBCore.Shared.Jobs]]

This function is expected to be defined on the server side.
If wanting to use on client, pass the args through to server side.


QBCore.Functions.AddJob

Make sure to have AddJob as the right capitalization.


ensure qb-core

Make sure to ensure qb-core before your script.


You can also use this to guide you.

This is a quick example!

local QBCore = exports['qb-core']:GetCoreObject()

QBCore.Functions.AddJob('hotdog', { --[[Job you want]]
    label = 'HotDoggy',
    defaultDuty = true,
    offDutyPay = false,
    grades = {
        ['0'] = {
            name = 'Glizzy',
            payment = 10
        }
    }
})


Event Usage Example

Server script

local QBCore = exports['qb-core']:GetCoreObject()

-- Command registration
RegisterCommand("addjob", function(source, args, rawCommand)
    TriggerServerEvent('testy')
end, false)

-- Server event
RegisterNetEvent('testy', function()
    QBCore.Functions.AddJob('hotdog', {
        label = 'HotDoggy',
        defaultDuty = true,
        offDutyPay = false,
        grades = {
            ['0'] = {
                name = 'Glizzy',
                payment = 10
            }
        }
    })
end)

Hope this helps as I know you probably have tried this. :frowning:

(The code I showed may or may not work as I DID NOT test it. :stuck_out_tongue: )

I tried adding the last code in the qb-adminmenu server file and it gives me the attempt to call a nil value error once again. I switched by placing it in the client file and adding a notify function after the trigger well I get the notification and no errors but I can’t seem to find the new job in the Shared/Jobs file.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.