How to create Missions
If you don't have the skills to develop basic code, we recommend that you contact a trusted developer.
The quest system in qs-advancedinventory lets you create small missions for your players, such as buying items, using objects, visiting places, or interacting with systems. You can reward them with money, XP, or anything else. Here’s how it works, step-by-step.
What Are Quests?
Quests are small tasks that players can complete to earn rewards. For example:
Buying an item
Entering a location
Using a tool
Winning a match
When a player finishes a quest, they receive a reward like XP. Delve into this section to create amazing quests for your players.
Creating Missions on ESX
The quest system in qs-inventorylets you create small missions for your players, such as buying items, using objects, visiting places, or interacting with systems. You can reward XP. Here’s how it works, step-by-step. These events and exports are ONLY for server-side.
Assign Quests When the Player Joins
You must wait a few seconds before giving quests to make sure the character is fully loaded. This avoids problems where the player doesn’t receive the quests due to timing.
You want every player to receive their quests as soon as they connect to your server and their character is fully loaded. Example (inside server/main.lua):
RegisterNetEvent('esx:playerLoaded', function(id, data)
Wait(2000) -- Wait 2 seconds for character data to fully load
print('Loaded player:', id)
CreateQuests(id) -- Give quests to the player
end)In this configuration we will place whether or not we want to use this system and below the name of the item that will be the money, in this case it is cash. This item must be added in your qs-inventory/shared/items.lua.
Why Do We Use CreateQuests(id)?
This function creates the quests you want for that specific player (id). It uses an export from qs-inventoryto create each quest and assign it to the player.
You must define this function yourself.
How To Write the CreateQuests Function
This function checks if qs-inventoryis running, then uses the createQuest export to register one or more missions for the player.
You can customize the quests as you wish.
✅ Example:
function CreateQuests(source)
if not GetResourceState('qs-inventory'):find('started') then
print('qs-inventory not started, skipping quest creation.')
return
end
-- Example Quest: Use a radio
exports['qs-inventory']:createQuest(source, {
name = 'use_radio',
title = 'Stay Tuned',
description = 'Use your radio for 10 times.',
reward = 150,
requiredLevel = 0,
})
-- Example Quest: Visit the hospital
exports['qs-inventory']:createQuest(source, {
name = 'visit_hospital',
title = 'Health Check',
description = 'Visit the hospital at least once.',
reward = 200,
requiredLevel = 1,
})
print('Quests assigned to player:', source)
endAssigning Quests to Already Connected Players
If your script restarts while players are already online, you need to reassign their quests. You can do this with a loop that runs on server start:
✅ Example:
CreateThread(function()
for k, v in pairs(ESX.Players) do
if v and v.source then
print('Loading quests for player:', v.source)
CreateQuests(v.source)
end
end
end)This makes sure no one is left without quests, even if they were online during a resource restart.
How To Update Quest Progress
Now that your player has quests, you can make progress happen by calling:
Copy
exports['qs-inventory']:UpdateQuestProgress(source, questName, amount)You can call this any time the player does something related to a quest. You can increase progress slowly, or complete the quest instantly.
✅ A quest is considered completed once it reaches 100 progress.
✅ Example:
if GetResourceState('qs-inventory'):find('started') then
local success = exports['qs-inventory']:UpdateQuestProgress(source, 'use_radio', 10)
if success then
Debug('Quest "use_radio" progress updated')
else
Debug('Failed to update quest "use_radio"')
end
endSafety Check – Only Run if the System is Started
Always wrap your quest-related code with this check to make sure qs-inventory is actually loaded:
if not GetResourceState('qs-inventory'):find('started') then return endThis avoids errors if the resource hasn't started yet or crashed.
Example of a mini-script with Missions
Loads the ESX framework.
Assigns quests when the player joins (
esx:playerLoaded).Reassigns quests to already-connected players if the resource restarts.
Adds a sample quest that completes when the player eats a
sandwich.
-- STEP 1: Load the ESX framework
ESX = exports['es_extended']:getSharedObject()
-- STEP 2: Create quests when a player joins the server
RegisterNetEvent('esx:playerLoaded', function(id, data)
Wait(2000) -- Wait 2 seconds to make sure the character is fully loaded
print('[Quests] Loaded player:', id)
CreateQuests(id) -- Assign quests
end)
-- STEP 3: Reassign quests to all online players when the script starts (e.g., after restart)
CreateThread(function()
for k, v in pairs(ESX.Players) do
if v and v.source then
print('[Quests] Reassigning quests to online player:', v.source)
CreateQuests(v.source)
end
end
end)
-- STEP 4: Function to create quests
function CreateQuests(source)
-- Make sure the quest system is running
if not GetResourceState('qs-inventory'):find('started') then
print('[Quests] qs-inventorynot started. Skipping.')
return
end
-- Example quest: Eat 5 sandwiches
exports['qs-inventory']:createQuest(source, {
name = 'eat_sandwich',
title = 'A Tasty Start',
description = 'Eat 5 sandwiches to prove your survival instincts.',
reward = 200,
requiredLevel = 0,
})
print('[Quests] Assigned quest "eat_sandwich" to player:', source)
end
-- STEP 5: Track progress when the sandwich is used
-- This should be triggered from your item system when a player uses a sandwich
RegisterNetEvent('qs:useItem:sandwich', function()
local src = source
if not GetResourceState('qs-inventory'):find('started') then return end
-- Add 20% progress every time a sandwich is eaten (5x = 100%)
local success = exports['qs-inventory']:UpdateQuestProgress(src, 'eat_sandwich', 20)
if success then
print('[Quests] Updated progress for "eat_sandwich" quest - player:', src)
else
print('[Quests] Failed to update quest progress - player:', src)
end
end)Creating Missions on QBCORE
The quest system in qs-inventorylets you create small missions for your players, such as buying items, using objects, visiting places, or interacting with systems. You can reward XP. Here’s how it works, step-by-step. These events and exports are ONLY for server-side.
Assign Quests When the Player Joins
You must wait a few seconds before giving quests to make sure the character is fully loaded. This avoids problems where the player doesn’t receive the quests due to timing.
You want every player to receive their quests as soon as they connect to your server and their character is fully loaded. Example (inside server/main.lua):
RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
local src = source
print('Loaded player:', src)
CreateQuests(src)
end)In this configuration we will place whether or not we want to use this system and below the name of the item that will be the money, in this case it is cash. This item must be added in your qs-inventory/shared/items.lua.
Why Do We Use CreateQuests(id)?
This function creates the quests you want for that specific player (id). It uses an export from qs-inventoryto create each quest and assign it to the player.
You must define this function yourself.
How To Write the CreateQuests Function
This function checks if qs-inventoryis running, then uses the createQuest export to register one or more missions for the player.
You can customize the quests as you wish.
✅ Example:
function CreateQuests(source)
if not GetResourceState('qs-inventory'):find('started') then
print('qs-inventory not started, skipping quest creation.')
return
end
-- Example Quest: Use a radio
exports['qs-inventory']:createQuest(source, {
name = 'use_radio',
title = 'Stay Tuned',
description = 'Use your radio for 10 times.',
reward = 150,
requiredLevel = 0,
})
-- Example Quest: Visit the hospital
exports['qs-inventory']:createQuest(source, {
name = 'visit_hospital',
title = 'Health Check',
description = 'Visit the hospital at least once.',
reward = 200,
requiredLevel = 1,
})
print('Quests assigned to player:', source)
endAssigning Quests to Already Connected Players
If your script restarts while players are already online, you need to reassign their quests. You can do this with a loop that runs on server start:
✅ Example:
CreateThread(function()
for k, v in pairs(QBCore.Functions.GetPlayers()) do
if v then
print('Loaded player:', v)
CreateQuests(v)
end
end
end)This makes sure no one is left without quests, even if they were online during a resource restart.
How To Update Quest Progress
Now that your player has quests, you can make progress happen by calling:
Copy
exports['qs-inventory']:UpdateQuestProgress(source, questName, amount)You can call this any time the player does something related to a quest. You can increase progress slowly, or complete the quest instantly.
✅ A quest is considered completed once it reaches 100 progress.
✅ Example:
if GetResourceState('qs-inventory'):find('started') then
local success = exports['qs-inventory']:UpdateQuestProgress(source, 'use_radio', 10)
if success then
Debug('Quest "use_radio" progress updated')
else
Debug('Failed to update quest "use_radio"')
end
endSafety Check – Only Run if the System is Started
Always wrap your quest-related code with this check to make sure qs-inventory is actually loaded:
if not GetResourceState('qs-inventory'):find('started') then return endThis avoids errors if the resource hasn't started yet or crashed.
Example of a mini-script with Missions
Loads the ESX framework.
Assigns quests when the player joins (
esx:playerLoaded).Reassigns quests to already-connected players if the resource restarts.
Adds a sample quest that completes when the player eats a
sandwich.
-- STEP 1: Load the QB framework
QBCore = exports['qb-core']:GetCoreObject()
-- STEP 2: Create quests when a player joins the server
RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
local src = source
Wait(2000) -- Wait 2 seconds to make sure the character is fully loaded
print('[Quests] Loaded player:', id)
CreateQuests(id) -- Assign quests
end)
-- STEP 3: Reassign quests to all online players when the script starts (e.g., after restart)
CreateThread(function()
for k, v in pairs(QBCore.Functions.GetPlayers()) do
if v then
print('[Quests] Reassigning quests to online player:', v.source)
CreateQuests(v.source)
end
end
end)
-- STEP 4: Function to create quests
function CreateQuests(source)
-- Make sure the quest system is running
if not GetResourceState('qs-inventory'):find('started') then
print('[Quests] qs-inventorynot started. Skipping.')
return
end
-- Example quest: Eat 5 sandwiches
exports['qs-inventory']:createQuest(source, {
name = 'eat_sandwich',
title = 'A Tasty Start',
description = 'Eat 5 sandwiches to prove your survival instincts.',
reward = 200,
requiredLevel = 0,
})
print('[Quests] Assigned quest "eat_sandwich" to player:', source)
end
-- STEP 5: Track progress when the sandwich is used
-- This should be triggered from your item system when a player uses a sandwich
RegisterNetEvent('qs:useItem:sandwich', function()
local src = source
if not GetResourceState('qs-inventory'):find('started') then return end
-- Add 20% progress every time a sandwich is eaten (5x = 100%)
local success = exports['qs-inventory']:UpdateQuestProgress(src, 'eat_sandwich', 20)
if success then
print('[Quests] Updated progress for "eat_sandwich" quest - player:', src)
else
print('[Quests] Failed to update quest progress - player:', src)
end
end)