Common Tasks

A guide to common development tasks in QB-Core.

Creating a New Item

Creating a new item in QB-Core is a two-step process. First, you need to add the item to the `qb-core/shared/items.lua` file. Then, you need to add an image for the item to the `qb-inventory/html/images` directory.

Step 1: Add the Item to `items.lua`

Lua

-- In qb-core/shared/items.lua

['myitem'] = {
    name = 'myitem',
    label = 'My Item',
    weight = 100,
    type = 'item',
    image = 'myitem.png',
    unique = false,
    useable = true,
    shouldClose = true,
    combinable = nil,
    description = 'This is my cool new item.'
},
                        

Step 2: Add the Image

Save an image for your item in the `qb-inventory/html/images` directory. The image should be a PNG file and the name should match the item name (e.g., `myitem.png`).

Creating a New Command

Creating a new command in QB-Core is easy. You just need to use the `QBCore.Commands.Add` function in a server-side script.

Lua

-- In a server-side script

QBCore.Commands.Add('mycommand', 'This is my cool new command.', {}, false, function(source, args)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)

    -- Do something cool here
    TriggerClientEvent('QBCore:Notify', src, 'You just ran my cool new command!')
end)
                        

Creating a New Job

Creating a new job in QB-Core involves adding the job to the `qb-core/shared/jobs.lua` file and then adding the job to the `qb-jobs/config.lua` file.

Step 1: Add the Job to `jobs.lua`

Lua

-- In qb-core/shared/jobs.lua

['myjob'] = {
    label = 'My Job',
    defaultDuty = true,
    grades = {
        ['0'] = {
            name = 'Recruit',
            payment = 50
        },
    },
},
                        

Step 2: Add the Job to `qb-jobs/config.lua`

Lua

-- In qb-jobs/config.lua

Config.Jobs = {
    -- ... other jobs
    ['myjob'] = {
        label = 'My Job',
        defaultDuty = true,
        offDutyPay = false,
        grades = {
            ['0'] = {
                name = 'Recruit',
                payment = 50
            },
        },
    },
    -- ... other jobs
}
                        

Adding a Vehicle to the Dealership

To add a new vehicle to the dealership, you need to add it to the `qb-vehicles/config.lua` file.

Lua

-- In qb-vehicles/config.lua

Config.Vehicles['mycar'] = {
    name = 'My Car',
    model = 'mycar',
    price = 10000,
    category = 'sports',
    -- ... other options
}
                        

Conclusion

This guide has shown you how to perform some common development tasks in QB-Core. As you get more comfortable with the framework, you'll be able to create more complex scripts and features.