Script

Automatize user time tracking

Using the FiveM Lua Script

Prerequesites

For now the script is only working on ESX. Please contact us if you are a good qbcore scripter and can help us translating the script.

Installing

Download here

To setup the script you will need to install NodeJS Runtime. It will be necessary to install important dependicies. For Windows just download the exe here and run it. How to install on Linux you can find here

Windows

Goto your FXServer Ressources, and unzip the script as a new folder.

Run windows_setup.bat to automatically install needed dependecies.

Dont forget to autostart the script by updating your server cfg ensure timecord_esx_script-master

Linux

Goto your FXServer Ressources, create a new folder and paste the script source there.

  1. Goto Script path

  2. Run chmod +x linux_setup.sh

  3. After that run ./linux_setup.sh

Dont forget to update your server cfg to enable autostart.

Using ESX

Basic Function

The script works with the esx:playerLoaded and esx:playerDropped event. Once the event is fired, we send a http request to our server. Our server then handles everything else.

Using getSharedObject()

In the newer versions esx uses a differnt function to import the esx object. If you have a newer esx version please update the script like that.

// Old esx object import
let ESX;
emitNet('esx:getSharedObject', (obj) => { ESX = obj })

// New esx object import
const ESX = exports["es_extended"].getSharedObject();

Configuration

// BASIC EXAMPLE
"api": {
        "police": "2c76b58e-fa2c-4a84-b9a9-fa79cd305864",
        "ambulance": "1c76258e-fa2c-4a84-b9a9-fa79cd305841"
},

In this table, our key is the exact name of the job how it is in the database. Based on that the script checks if the user has the specified job. The value of this pair is our API Key from the server where our bot is on. You can obtain your Key in the Settings -> Script Tab

Notice: You can add multiple keys if you want. Ensure that within the server settings (dashboard), the IP address of your server has been properly configured under the script settings. Also dont give your API Key away!

Using the custom event

If you have any custom on/offy dutys, where your users can stop or start working without leaving the server u can use the custom event to trigger stamping in or out.

-- Note that this is a server / client event. 
-- Protect that event so players cant spam it or you will get an API Ban

// LUA CLIENT
TriggerServerEvent('timecord:dutyTrigger', playerId, true) -- To trigger the stamped in event
TriggerServerEvent('timecord:dutyTrigger', playerId, false) -- To trigger the stamped out event

// LUA SERVER
TriggerEvent('timecord:dutyTrigger', playerId, true) -- To trigger the stamped in event
TriggerEvent('timecord:dutyTrigger', playerId, false) -- To trigger the stamped out event

// JS CLIENT
emitNet('timecord:dutyTrigger', playerId, true) -- To trigger the stamped in event
emitNet('timecord:dutyTrigger', playerId, false) -- To trigger the stamped out event

// JS SERVER
emit('timecord:dutyTrigger', playerId, true) -- To trigger the stamped in event
emit('timecord:dutyTrigger', playerId, false) -- To trigger the stamped out event

Error handling

We experienced that some servers experience that their esx:playerDropped dont work properly. For now we dont know why this error occurs. Maybe you changed it in your esx script or you have an other event that is rewriting it. You can update our script if you have an custom Event by removing the onNet('esx:playerDropped') from our script and replacing it with your own custom event. An optional Workaround may be to use the FiveM Playerjoined Event :)

Last updated