Crafting System in FiveM — Create weapons and items from Raw Materials.
Crafting System in FiveM
Crafting system adds a new dimension to gameplay. Players must find raw materials, process them, and assemble them into finished products.
Design Principles
- Several steps — raw → processed → final product
- Risk/Reward — The rarer it is, the more you can get.
- Skill Progression — The more you do, the faster/more you get.
- Location-based — crafting must be done in a specific location.
Config Recipes
Config.Recipes = {
['pistol'] = {
label = 'Handgun',
requiredJob = nil, -- anyone can do it.
requiredItems = {
{ item = 'steel', amount = 3 },
{ item = 'rubber', amount = 1 },
{ item = 'spring', amount = 2 }
},
result = { item = 'weapon_pistol', amount = 1 },
time = 10000, -- 10 seconds
successRate = 80, -- 80% chance of success
xp = 50
},
['lockpick'] = {
label = 'Password',
requiredJob = nil,
requiredItems = {
{ item = 'plastic', amount = 2 },
{ item = 'steel', amount = 1 }
},
result = { item = 'lockpick', amount = 3 },
time = 5000,
successRate = 95,
xp = 20
},
['meth'] = {
label = 'amphetamine',
requiredJob = nil,
requiredItems = {
{ item = 'chemicals', amount = 5 },
{ item = 'acetone', amount = 3 }
},
result = { item = 'meth', amount = 2 },
time = 30000,
successRate = 70,
xp = 100,
requiredLocation = 'meth_lab' -- Must be done at the lab only.
}
}
Config.Locations = {
meth_lab = vector3(-1089.7, -1600.2, 4.4),
workshop = vector3(616.7, 2759.7, 42.1),
kitchen = vector3(-75.0, -820.0, 326.0)
}
Server Logic
-- server.lua
ESX.RegisterServerCallback('crafting:craft', function(source, cb, recipe)
local xPlayer = ESX.GetPlayerFromId(source)
local recipeData = Config.Recipes[recipe]
if not recipeData then cb(false, 'Recipe is not valid') return end
-- Check items
for _, required in ipairs(recipeData.requiredItems) do
local item = xPlayer.getInventoryItem(required.item)
if item.count < required.amount then
cb(false, 'Missing: ' .. required.item)
return
end
end
-- Delete materials
for _, required in ipairs(recipeData.requiredItems) do
xPlayer.removeInventoryItem(required.item, required.amount)
end
-- Calculate success
local roll = math.random(1, 100)
if roll > recipeData.successRate then
cb(false, 'crafting_fail') -- failed, materials are gone.
return
end
-- gives results
xPlayer.addInventoryItem(recipeData.result.item, recipeData.result.amount)
-- Save XP
local currentXP = xPlayer.getMeta('crafting_xp') or 0
xPlayer.setMeta('crafting_xp', currentXP + recipeData.xp)
cb(true, recipeData.result)
end)
Client — Progress + UI
-- client.lua
local function StartCrafting(recipe)
local recipeData = Config.Recipes[recipe]
-- Progress bar while crafting
exports['M2.Progress']:Progress({
name = 'crafting_' .. recipe,
duration = recipeData.time,
label = 'Crafting: ' .. recipeData.label,
canCancel = true,
disable = { move = true, car = true, combat = true },
anim = {
dict = 'anim@amb@backstage@hub@short_0@male@',
clip = 'idle_a'
}
}, function(cancelled)
if canceled then
exports['M2.Notify']:Notify('warning', 'Cancel crafting', 2000)
return
end
ESX.TriggerServerCallback('crafting:craft', function(success, data)
if success then
exports['M2.Notify']:Notify('success',
'Success! received '.. data.item, 4000)
else
if data == 'crafting_fail' then
exports['M2.Notify']:Notify('error',
'Fail! lost materials', 4000)
else
exports['M2.Notify']:Notify('error', data, 3000)
end
end
end, recipe)
end)
end
Skill Progression
-- Server: Calculate crafting speed bonus from XP.
local function GetCraftingBonus(identifier)
local xp = MySQL.scalar.await(
'SELECT crafting_xp FROM character_meta WHERE identifier = ?',
{ identifier }
) or 0
-- Every 500 XP = 5% time reduction
local bonus = math.floor(xp / 500) * 0.05
return math.min(bonus, 0.5) -- up to 50% bonus
end
Summary
A good crafting system has balanced recipes, clear risk/reward, and a progression that makes players feel like they're getting better as they play. Start with simple recipes and gradually increase in complexity.
Related Articles
Breaking: GTA Online อัพเดท "Money Fronts" — FiveM Server Owners ต้องทำอะไร?
Rockstar ปล่อย GTA Online อัพเดท Money Fronts มีผลกระทบต่อ FiveM servers บางส่วน นี่คือสิ่งที่ต้องทำทันทีหลังอัพเดท
Community Spotlight: Script และ Projects ที่น่าสนใจจาก FiveM Community
รวม scripts, tools และ projects ที่โดดเด่นจาก FiveM community ในช่วงที่ผ่านมา ตั้งแต่ free resources ถึง open-source projects
txAdmin อัพเดทใหม่ — Dashboard, Diagnostics และ Ban System ที่ดีขึ้น
txAdmin ซึ่งตอนนี้เป็นส่วนหนึ่งของ Cfx.re อย่างเป็นทางการ ได้รับการอัพเดทครั้งใหญ่ มี features ใหม่ที่ทำให้ Server Management ง่ายขึ้นมาก