TdPlaytime
Grab player playtimes from txAdmin data and store for use ingame
Install / Use
/learn @TradieKM/TdPlaytimeREADME
txAdmin Playtime Merger
This standalone FiveM playtime tracker connects to a MySQL database and logs player playtime from PlayersDB.json (TxData). It’s packaged as an executable with no dependencies required - just configure the config.json to start tracking and storing playtime.
I have packaged an exe version for simplicity, and included all open-source code for this merging tool.
For the executable version, please follow the instructions provided below. If you prefer to use the open-source version, ensure you have Node.js installed and correctly configure the config.json file.
Why use this script? Traditional resources often encounter issues when trying to access the playersdb.json file outside of the resources folder. This script offers a solution making it easier to work with. Use it if you face similar challenges.
Table of Contents
Features
- Formats and tracks player playtime data using a MySQL database and pre-defined target PlayersDB file.
- Automatically creates a table if it doesn't exist.
- Easy configuration through a
config.jsonfile. - Self-contained executable with no additional dependencies required.
Requirements
- Windows 10/11 (not tested on older versions).
- MySQL Server installed and running.
- A correctly configured
config.jsonfile (see below).
## -----------------------------------------------------------------------------------------------------------------------------------------------
## ███████ ███████ ████████ ██ ██ ██████
## ██ ██ ██ ██ ██ ██ ██
## ███████ █████ ██ ██ ██ ██████
## ██ ██ ██ ██ ██ ██
## ███████ ███████ ██ ██████ ██
Step 1: Install/Run MySQL
Step 2: Configure the config.json
- Open the
config.jsonfile, and keep it in the same directory/folder asstorePlaytime.exe. - Update the
dataFilePathanddatabasefields to match your environment:
Your config.json should look similar to this (without the explanatory comments):
```json
{
"dataFilePath": "D:/KMRP/localhost-server/txData/default/data/playersDB.json", //PlayersDB.json location
"database": {
"host": "localhost", //locahost or host name
"user": "root", //user or root
"password": "", //password or empty
"database": "qbcoreframework_0caee9" //database name
}
}
```
## -----------------------------------------------------------------------------------------------------------------------------------------------
## ██████ ██████ ███ ██ ███████
## ██ ██ ██ ██ ████ ██ ██
## ██ ██ ██ ██ ██ ██ ██ █████
## ██ ██ ██ ██ ██ ██ ██ ██
## ██████ ██████ ██ ████ ███████
Running and storing Playtimes
-
Run
storePlaytime.exe. -
The application will automatically:
- Connect to the MySQL database using the
config.jsonsettings. - Create the
player_playtimestable if it doesn’t already exist. - Read player data from the specified
dataFilePath. - Insert or update playtime records in the database if they are new or they exist.
- The console will show detailed logs, such as database connections, read operations, and any errors encountered, it wil lthen exit once complete.
- Connect to the MySQL database using the
Great! Your playtimes should now be in the pre-defined SQL table!
Step 3: Enabling the Player Command
- Run either my paid or free FiveM playtime resource (
td-playtime) on your server. Links: (Completely free, but i offer a paid version) Free [Link - Tebex] Paid [Link - Tebex] - The script will automatically detect several notification resources and core frameworks, and print the detection results in the server console on startup, if none are detected no worries, it will default to chat output.
- Jump in-game and type
/playtimeto check your current playtime! 😊
Detected notification resources: okokNotify, mythic_notify, QBCore, esx_notify
## -----------------------------------------------------------------------------------------------------------------------------------------------
## ██ ███ ███ ██████ ██████ ██████ ████████ █████ ███ ██ ████████
## ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
## ██ ██ ████ ██ ██████ ██ ██ ██████ ██ ███████ ██ ██ ██ ██
## ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
## ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ████ ██
You must run the exe storePlaytime.exe each time you want to update playtime, its recommended to add it to the windows startup apps
Troubleshooting -- FOR EXE
I did not run into any of these but here you go
-
Error:
ER_ACCESS_DENIED_ERROR- This error occurs if the MySQL user or password is incorrect.
- Solution: Double-check the
userandpasswordfields inconfig.jsonand ensure they match the MySQL server.
-
Error:
ENOTFOUNDorECONNREFUSED- This means the script is unable to connect to the MySQL server.
- Solution: Ensure MySQL is running and the
hostinconfig.jsonis set to the correct IP address or hostname.
-
Missing
config.jsonFile- The executable won’t run without a valid
config.json. - Solution: Make sure
config.jsonis in the same directory as the executable and has the correct settings.
- The executable won’t run without a valid
-
No Playtime Data Processed
- If no data is processed, the
playersDB.jsonfile may be empty or not in the correct format. - Solution: Ensure the
dataFilePathpoints to a valid JSON file with player data.
- If no data is processed, the
FAQ
-
Can I run this on a different operating system?
- Currently, the executable is built for Windows. If you need a Linux or macOS version, sorry..
-
Does the executable support remote MySQL servers?
- Yes, you can use a remote MySQL server by updating the
hostfield inconfig.jsonto the server’s IP address.
- Yes, you can use a remote MySQL server by updating the
-
Is the source code available?
- This executable is distributed as a standalone file, and the source code is not included.
