|
1 | 1 | # Player Data |
2 | 2 |
|
3 | | -TODO |
| 3 | +> TL;DR |
| 4 | +> This resource assigns players a persistent User ID linked to player |
| 5 | +> identifiers, and provides Data IDs for data similar to characters or save |
| 6 | +> files. Use User IDs for identity, and Data IDs for gameplay state. |
| 7 | +
|
| 8 | +The main functionality of this resource is identifying players and assigning |
| 9 | +them persistent User and Data IDs. This document explains the purpose and |
| 10 | +behavior of these IDs. |
| 11 | + |
| 12 | +Please read the following links for more context: |
| 13 | +- [Identifier Types](https://docs.fivem.net/docs/scripting-reference/runtimes/lua/functions/GetPlayerIdentifiers/#identifier-types) |
| 14 | + |
| 15 | +## User IDs |
| 16 | + |
| 17 | +To save player data across logins and restarts, FiveM provides us with player |
| 18 | +identifiers. Most frameworks use a single identifier; typically `license2` or |
| 19 | +`license`, based on availability. This can pose a problem, however, as |
| 20 | +`license2` is not always available, and `license` is prone to changes. This can |
| 21 | +lead to some players losing access to their data, or not being able to join at |
| 22 | +all. The other identifiers aren't reliable either, as they might require players |
| 23 | +to play using a specific platform, or link an external account, locking out |
| 24 | +certain players. |
| 25 | + |
| 26 | +This resource solves this by using *all* available identifiers, except for `ip`, |
| 27 | +as it is not specific enough. These identifiers will be linked to a User ID. The |
| 28 | +User ID is an integer value assigned to players, intended for developers to use |
| 29 | +as a replacement for identifiers. This allows the resource to reliably identify |
| 30 | +the player, while your resources handle the rest. |
| 31 | + |
| 32 | +When a player joins the server, this resource collects their identifiers. If a |
| 33 | +linked User ID is found, then it is assigned to the player. If new and unlinked |
| 34 | +identifiers are found, they are also linked to the User ID. In the case that |
| 35 | +multiple User IDs are found, the oldest User ID is assigned. Existing identifier |
| 36 | +links are not modified, preventing accidental reassignment. If no linked User ID |
| 37 | +is found, a new one is created and linked to the identifiers. |
| 38 | + |
| 39 | +## Data IDs |
| 40 | + |
| 41 | +The Data ID is an integer value provided by this resource, similar to a |
| 42 | +character or a save file. One User ID can have multiple Data IDs, similar to |
| 43 | +having multiple characters or save files. This is intended for developers to use |
| 44 | +as a framework-agnostic solution to save player data, replacing |
| 45 | +framework-dependent character IDs. It is recommended to almost always use Data |
| 46 | +IDs to save data. Use User IDs only for data that should persist across all Data |
| 47 | +IDs. |
| 48 | + |
| 49 | +By default, when a player joins, this resource automatically assigns the first |
| 50 | +Data ID linked to the player's User ID, or creates one if none exist. Other |
| 51 | +resources can disable this functionality to implement their own Data ID |
| 52 | +assignments, such as a character selection screen. |
0 commit comments