Script
Automatize user time tracking
The TimeCord script tracks time automatically from your game server, so players do not have to press a button in Discord. When a player comes on duty their linked Discord account is clocked in, and when they go off duty it is clocked out.
The current script is written in Lua for FiveM and supports the ESX framework.
Are you a good qbcore scripter and want to help us translate the script to qbcore? Get in touch on our Discord.
How it works
The script listens for the ESX esx:playerLoaded and esx:playerDropped events. When one fires, it reads the player's ESX job, looks up the API key you configured for that job, and sends an HTTP request to TimeCord, which handles the rest. TimeCord matches the player to their Discord account and clocks them in or out. In short: coming on duty clocks in, leaving clocks out.
Download
Get the script here: github.com/DanielLogisch/timecord_esx_script
Requirements
You need the Node.js runtime on the game server to install the script's dependencies.
Windows: download the installer from nodejs.org and run it.
Linux: follow this guide.
Installation
Windows
Go to your FXServer
resourcesfolder and unzip the script as a new folder.Run
windows_setup.batto install the needed dependencies automatically.Enable autostart by adding this to your
server.cfg:
Linux
Go to your FXServer
resourcesfolder, create a new folder, and paste the script source there.Go to the script path.
Make the setup script executable:
chmod +x linux_setup.shRun it:
./linux_setup.shUpdate your
server.cfgto enable autostart.
Importing the ESX object
Newer ESX versions import the shared object differently. If you are on a newer version, update the script accordingly:
Configuration
TimeCord ties an API key to each job. Map job names to keys in the script config:
The key is the exact job name as it appears in your database, so the script can check whether a player has that job. The value is the API key for the server your bot runs on. Generate keys in the dashboard under Settings -> Script. You can add as many jobs as you like, and only the jobs you list here are tracked.
In the dashboard's script settings, make sure the IP address of your game server is configured, otherwise requests are rejected. And never share your API key.
Custom duty event
If your server has an on/off-duty system where players toggle duty without leaving the server, use the custom event to clock them in or out. Pass true to clock in and false to clock out.
Troubleshooting
esx:playerDroppednot firing. Some servers report this event misbehaving, which can leave a session open. It may be overwritten by your ESX setup or another resource. Work around it by removingonNet('esx:playerDropped')from the script and replacing it with your own custom event, or by using the FiveMplayerDroppedevent instead.A job is not being tracked. Confirm the job name in the config exactly matches the ESX job name, and that the API key for it is valid in your dashboard.
Forgotten sessions. If a clock-out is ever missed, TimeCord's automatic clock-out closes sessions that stay open too long (see Statistics & Time).
Need help writing or extending a script? Open a ticket on our Discord.
Last updated