Usage & Setup
How It Worksâ
The Job Time Tracker monitors player job changes and automatically:
- Tracks when a player switches to a tracked job
- Logs the session duration in the database
- Sends webhooks to Discord with player and time information
- Generates reports at configured times (daily/weekly)
Getting Startedâ
Step 1: Enable Debug Mode (Optional)â
While setting up, enable debug mode in shared/config.lua:
Config.Debug = true
This shows detailed console logs to help verify the system is working.
Step 2: Configure Your Jobsâ
Edit shared/config.lua and add the jobs you want to track:
Config.TrackedJobs = {
ambulance = "EMS",
police = "POLICE",
mechanic = "MECHANIC",
}
Make sure the keys match your database job names exactly (case-sensitive).
Step 3: Set Up Webhooksâ
For each tracked job, add webhook URLs in shared/webhook.lua:
Webhooks.join = {
ambulance = "https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN",
police = "https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN",
mechanic = "https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN",
}
Webhooks.daily = {
ambulance = "https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN",
police = "https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN",
mechanic = "https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN",
}
Step 4: Testâ
-
Restart the resource:
refreshstart cfx_job_time_tracker -
Check console for startup messages:
[Vice JobTime] ESX LOADED[JobTime] Config and Webhooks loaded -
In-game test:
- Have a test player change to a tracked job
- Check Discord for a join notification
- Have the player leave the job
- Verify the webhook is sent with the correct time
Webhook Messagesâ
Join/Leave Formatâ
When a player starts or stops working:
đĸ Started Work - Ambulance
Player: TestPlayer
Status: Started working
When stopping:
đ´ Ended Work - Ambulance
Player: TestPlayer
Work Time: 15 minutes 30 seconds
Daily Report Formatâ
At the configured daily time:
đ Daily Report - Ambulance
Period: 2024-01-15 â 2024-01-15
Player | Time
TestPlayer | 1 hour 30 minutes
OtherPlayer | 2 hours 15 minutes
Weekly Report Formatâ
At the configured weekly time:
đ Weekly Report - Ambulance
Period: 2024-01-08 â 2024-01-14
Player | Time
TestPlayer | 8 hours 30 minutes
OtherPlayer | 7 hours 45 minutes
AnotherPlayer | 5 hours 10 minutes
Features in Detailâ
Real-Time Trackingâ
The system tracks active jobs using framework events:
- ESX:
esx:playerLoaded,esx:setJob,esx:updateJob - QBCore:
QBCore:Client:OnPlayerLoaded,QBCore:Client:OnJobUpdate
Changes are detected within seconds.
A polling fallback also runs every 5 seconds to catch missed job changes.
State Persistenceâ
On resource restart, the system:
- Checks if the player is in a tracked job
- Restores tracking state without sending a webhook
- Continues normal operation
This prevents duplicate notifications on server restarts.
Network Resilienceâ
If a player disconnects:
- Tracking stops automatically
- Webhook is sent with final time
- Session is logged to database
If they reconnect:
- System detects the new job
- Tracking resumes normally
The system monitors network connection status continuously. If it detects a lost session, it cleans up automatically.
Language Supportâ
Switching Languagesâ
Change the language in shared/config.lua:
Config.Locale = "en" -- English
Config.Locale = "sl" -- Slovenian
Adding New Languagesâ
- Create a new file in
locales/folder (e.g.,de.luafor German) - Copy the structure from
locales/en.lua - Translate all strings
- Reference it in
fxmanifest.lua:
server_scripts {
'locales/en.lua',
'locales/sl.lua',
'locales/de.lua', -- Add your language
}
- Set it in config:
Config.Locale = "de"
Debugging Tipsâ
Enable Debug Modeâ
Config.Debug = true
Watch the console for messages like:
[JobTime DEBUG] Starting tracking for job: ambulance
[JobTime DEBUG] Stopping tracking for job: ambulance
[JobTime DEBUG] Job changed from: police to: ambulance
Check if Job is Trackedâ
Add this to debug output:
-- Job not being tracked?
-- Verify: Config.TrackedJobs contains the exact job name (case-sensitive)
-- Compare database job name with config
Verify Webhooksâ
- Make sure webhook URLs are correct and accessible
- Check Discord channel permissions (bot should have write access)
- In debug mode, webhooks will print status to console
- Test by manually changing jobs in-game
Database Issuesâ
If reports aren't generating:
- Verify
oxmysqlis running - Check database connection
- Ensure the job is in
Config.TrackedJobs - Look for SQL errors in console
If you need more help, enable Config.Debug = true and check the full console output. Most issues are configuration-related.
Common Issuesâ
"Job not being tracked"â
Solution: Verify the job name in Config.TrackedJobs matches your database exactly (including capitalization).
"Webhooks not sending"â
Solution:
- Check webhook URL format
- Verify Discord bot has permissions on the target channel
- Enable debug mode and check for error messages
- Test with a fresh job change
"Reports not generating at configured time"â
Solution:
- Verify
Config.ReportTimesis set correctly (24-hour format) - Check server is running at report time
- Verify at least one tracked job session exists for the period
- Check Discord webhook permissions
"State not syncing after restart"â
Solution: This is normal behavior. The system intentionally skips webhooks on restart to avoid duplicates. Check console with debug enabled to verify state was restored.
Performanceâ
The system is optimized for low resource usage:
- Minimal database queries (only on job changes)
- Efficient event handling (no polling unless necessary)
- Lightweight webhook processing
- Network-aware disconnection handling
Suitable for servers with hundreds of concurrent players.
You're all set! The Job Time Tracker is ready for production use.