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.
Quests are small tasks designed to give players objectives and rewards during their gameplay. They can involve many different actions, such as purchasing an item, entering a specific location, using a particular tool, or completing an activity like winning a match. These tasks encourage players to explore the server and interact with its systems while progressing through different challenges.
When a player successfully completes a quest, they receive a reward, which can include experience points (XP) or other benefits depending on how the system is configured. This section allows you to design and configure your own quests, giving you the tools to create engaging activities that motivate players and enhance the overall gameplay experience on your server.
Creating Missions in ESX
The quest system in qs-inventory lets 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.
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):
lua
RegisterNetEvent('esx:playerLoaded', function(id, data)
Wait(2000) -- Wait 2 seconds for character data to fully loadprint('Loaded player:', id)
CreateQuests(id) -- Give quests to the playerend)
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.
This function creates the quests you want for that specific player (id). It uses an export from qs-inventory to create each quest and assign it to the player. You must define this function yourself.
This function checks if qs-inventory is running, then uses the createQuest export to register one or more missions for the player. You can customize the quests as you wish.
lua
functionCreateQuests(source)ifnot GetResourceState('qs-inventory'):find('started') thenprint('qs-inventory not started, skipping quest creation.')
returnend-- 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)
end
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:
lua
CreateThread(function()for k, v inpairs(ESX.Players) doif v and v.source thenprint('Loading quests for player:', v.source)
CreateQuests(v.source)
endendend)
This makes sure no one is left without quests, even if they were online during a resource restart.
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.
lua
if GetResourceState('qs-inventory'):find('started') thenlocal 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"')
endend
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.
lua
-- 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 loadedprint('[Quests] Loaded player:', id)
CreateQuests(id) -- Assign questsend)
-- STEP 3: Reassign quests to all online players when the script starts (e.g., after restart)
CreateThread(function()for k, v inpairs(ESX.Players) doif v and v.source thenprint('[Quests] Reassigning quests to online player:', v.source)
CreateQuests(v.source)
endendend)
-- STEP 4: Function to create questsfunctionCreateQuests(source)-- Make sure the quest system is runningifnot GetResourceState('qs-inventory'):find('started') thenprint('[Quests] qs-inventorynot started. Skipping.')
returnend-- 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
ifnot GetResourceState('qs-inventory'):find('started') thenreturnend-- Add 20% progress every time a sandwich is eaten (5x = 100%)local success = exports['qs-inventory']:UpdateQuestProgress(src, 'eat_sandwich', 20)
if success thenprint('[Quests] Updated progress for "eat_sandwich" quest - player:', src)
elseprint('[Quests] Failed to update quest progress - player:', src)
endend)
Creating Missions in QB
The quest system in qs-inventory lets 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.
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):
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-core/shared/items.lua.
This function creates the quests you want for that specific player (id). It uses an export from qs-inventory to create each quest and assign it to the player. You must define this function yourself.
This function checks if qs-inventory is running, then uses the createQuest export to register one or more missions for the player. You can customize the quests as you wish.
lua
functionCreateQuests(source)ifnot GetResourceState('qs-inventory'):find('started') thenprint('qs-inventory not started, skipping quest creation.')
returnend-- 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)
end
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.
lua
if GetResourceState('qs-inventory'):find('started') thenlocal 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"')
endend
Assigns quests when the player joins (QBCore:Server:OnPlayerLoaded).
Reassigns quests to already-connected players if the resource restarts.
Adds a sample quest that completes when the player eats a sandwich.
lua
-- 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 loadedprint('[Quests] Loaded player:', id)
CreateQuests(id) -- Assign questsend)
-- STEP 3: Reassign quests to all online players when the script starts (e.g., after restart)
CreateThread(function()for k, v inpairs(QBCore.Functions.GetPlayers()) doif v thenprint('[Quests] Reassigning quests to online player:', v.source)
CreateQuests(v.source)
endendend)
-- STEP 4: Function to create questsfunctionCreateQuests(source)-- Make sure the quest system is runningifnot GetResourceState('qs-inventory'):find('started') thenprint('[Quests] qs-inventorynot started. Skipping.')
returnend-- 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
ifnot GetResourceState('qs-inventory'):find('started') thenreturnend-- Add 20% progress every time a sandwich is eaten (5x = 100%)local success = exports['qs-inventory']:UpdateQuestProgress(src, 'eat_sandwich', 20)
if success thenprint('[Quests] Updated progress for "eat_sandwich" quest - player:', src)
elseprint('[Quests] Failed to update quest progress - player:', src)
endend)