A practical guide to how to add a trucking job to your qbcore fivem server, with implementation decisions, validation steps, and security considerations for a production-minded project.
Overview
This guide shows how to add a robust, secure trucking job to a QBCore FiveM server. It focuses on architecture, server-side validation, practical implementation choices, testing, deployment, and maintenance. The goal is a production-ready job that resists cheating, supports administration, and integrates cleanly with common libraries such as ox_lib and targeting resources. If you want to prototype quickly and iterate, consider using cloud-based planning tools such as Stellar AI App to sketch mission flows and state machines before implementation.
High-level architecture and components
A trucking job typically has these components:
- Server-side job manager: authoritative state, route generation, reward calculation, logging.
- Client-side interactions: waypoint presentation, job UI, progress bars, vehicle interactions. The client must only render and request actions; never make authoritative decisions.
- Database persistence: store job history, player cooldowns, and job configuration.
- Optional utilities: targeting (qb-target/ox_target), progress displays (ox_lib), and anti-cheat hooks.
Recommended separation of responsibilities
Keep as much logic as possible on the server. The server validates job completion, calculates payments, updates inventories, and stores records. The client requests "start job" and "complete waypoint" actions, but the server must verify each request before applying rewards or state changes.
Data model and persistence
Minimal data you will persist:
- Active job records: player identifier, route seed, start timestamp, job state.
- Completed job records: player identifier, route, payout, timestamp, suspicious flags.
- Player cooldowns and daily caps to limit abuse.
Use your existing MySQL/oxmysql schema to add a table such as truck_jobs. Keep sensitive logic (reward calculation, anti-cheat thresholds) in Lua server code and avoid storing values that would let clients fabricate legitimate-looking responses.
Server-side validation and security
Security is the most important part. For FiveM/QBCore: never trust client input. Always validate:
- Player identity: use the server
sourcevalue and QBCore.Functions.GetPlayer to confirm the actor. - Vehicle legitimacy: confirm the player is using the expected vehicle model and plate stored when the job started.
- Position and distance: verify the server-side distance between recorded route waypoints and the player's reported position. Use server-calculated checks rather than raw client-reported completion flags.
- Timing and speed: detect impossible completion times that indicate teleportation or speed hacks.
- Item or cargo possession: if cargo is represented as an item, verify inventory possession server-side. If cargo is vehicle-based, validate the correct entity exists on the server.
Example server-side skeleton for completion handling:
-- server.lua
local QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('qb-trucking:server:completeDelivery', function(deliveryId)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local job = GetActiveJobForPlayer(Player.PlayerData.citizenid, deliveryId)
if not job then
return -- no active job registered; ignore
end
-- validate vehicle plate & model server-side
local veh = GetVehicleFromNetworkId(job.vehicleNetId)
if not veh or GetVehicleNumberPlateText(veh) ~= job.plate then
-- suspicious or wrong vehicle
FlagSuspicious(Player.PlayerData.citizenid, 'vehicle_mismatch')
return
end
-- check server-side distance to waypoint coordinates
local playerPos = GetEntityCoords(GetPlayerPed(src))
local dist = #(playerPos - vector3(job.target.x, job.target.y, job.target.z))
if dist > job.allowedRadius then
-- too far; reject
return
end
-- final reward and logging
local payout = CalculatePayout(job)
Player.Functions.AddMoney('bank', payout, 'trucking-complete')
MarkJobComplete(Player.PlayerData.citizenid, deliveryId)
end)
The above demonstrates receiving only a simple identifier from the client and relying on server-side state to validate. Avoid using any client-sent coordinates or payment numbers for authoritative decisions.
Implementation choices and integrations
Choose integrations to improve UX while maintaining server control:
- Targeting: qb-target or ox_target for pickup/drop interactions. Use them to trigger client requests, but always forward server events for validation.
- Progress and notifications: prefer ox_lib or native UI for progress bars, but do not tie completion to client-side timers.
- Inventory and items: use QBCore inventory functions for cargo items; never assume client-side inventory is authoritative.
If you need a quick visual planner and environment to document job flows and state transitions, you can use Stellar AI App to capture your scenario diagrams. For architecture or blog-style explanations, reference an article on the topic at Stellar AI Blog.
Practical implementation: files and responsibilities
Below is a concise table mapping recommended files to responsibilities for a QBCore trucking resource.
| File | Responsibility |
|---|---|
| fxmanifest.lua | Resource manifest, dependency declarations (qb-core, ox_lib, qb-target). |
| server/main.lua | Authoritative job logic: route generation, validation, payments, DB writes. |
| client/main.lua | UI, target interactions, waypoint rendering, sends minimal requests to server. |
| config.lua | Configurable values: payout base, allowed radius, vehicle models, cooldowns. |
| sql/schema.sql | Database table definitions for job persistence and logs. |
Testing and QA
Adopt layered testing:
- Unit tests for server-side logic where possible (e.g., payout calculation, distance validation functions).
- Integration tests on a staging server with sample players to simulate legitimate and cheating scenarios.
- Load tests to see how job logging and DB writes cope under concurrent players; use sane batching for writes where possible.
Test cases to include:
- Correct vehicle, correct route, normal timing — should pay out.
- Wrong vehicle plate — should be rejected and flagged.
- Fast teleport to endpoint — should be rejected and logged.
- Network failure mid-job — server should allow resumptions or clean cancellations based on saved state.
Deployment and maintenance
Deployment checklist:
- Deploy to a staging server first and run the test suite.
- Monitor server logs for suspicious flags and false positives for one week.
- Roll out to production during low-traffic hours and keep a rollback plan.
Maintenance notes:
- Rotate and backup the job database regularly. Ensure DB migrations are repeatable.
- Record suspicious activity and expose an admin tool to review job logs. Logs should include citizenid, timestamps, vehicle plate, and route seed.
- Keep configuration tunable without redeploying code by using a global config table and a simple database-backed settings table if needed.
Roblox considerations (if porting concepts)
If you apply similar job mechanics in Roblox, follow platform-specific authority rules:
- Server authority: all job state must be tracked on the server (ServerScripts) and validated before rewards are granted.
- RemoteEvents/RemoteFunctions: clients may request actions, but the server verifies eligibility and rate-limits requests. Do not allow RemoteFunctions to perform sensitive calculations purely client-side.
- DataStore handling: wrap DataStore calls in
pcall, implement exponential backoff on transient failures, and design for idempotency so duplicate or retried deliveries do not pay twice.
Troubleshooting common problems
Common issues and how to address them:
- Players claim no payment: verify server logs and DB writes; ensure AddMoney calls use the correct player identifier and account (cash/bank).
- False cheating flags: tune allowedRadius and minimal time thresholds, and provide an admin override after review.
- Database bottleneck: batch log inserts, use async writes if supported by your MySQL driver, and index tables on citizenid and timestamps.
Practical checklist before launch
Use this short checklist to confirm readiness:
| Step | Done | Notes |
|---|---|---|
| Server-side validation implemented for all client events | [ ] | Ensure vehicle, plate, distance, and timing checks |
| Database schema deployed and backups configured | [ ] | Test restore on staging |
| Admin logging and review tools available | [ ] | Include suspicious flags |
| Integration with target/progress libraries tested | [ ] | Confirm client-only features do not control rewards |
| Staged rollout plan documented | [ ] | Define rollback criteria |
Monitoring and analytics
Monitor job usage and fraud indicators: job completion rates, average duration, and flagged incidents. Do not rely on client timestamps; log server timestamped events. Keep privacy and data minimization in mind when logging player activity.