Skip to main content

Setting Up Player Identifiers

info

If you do not have player citizen id's, blood types, or fingerprints accessible either in PlayerData or via a callback/export, you can skip this section and proceed to the SQL step which will set up your ev_identifier database!

Originally built out from and integrated with qb-core, r14-evidence uses several player identifiers not found natively in ESX or potentially in other Standalone Frameworks, meaning we are required to either supply this information through the configurable PlayerData fu nctions or intentionally leave it blank and set up a database table for r14-evidence so that it can generate them for players. If you have modified your version of ESX or it's PlayerData functions, you may simply need to update the config so that r14-evidence can pull them. If not, don't worry, a simple SQL statement is all that stands between you and evidence running properly.

Modifying Our Config

There are two primary functions in the config file that handle how PlayerData is fetched for the script to function. In both ESX and QBCore, we can use the GetPlayerData() function on the client-side and either the GetPlayer() or GetPlayerFromId() functions on the server-side. You can see how these functions are handled by default, and see that r14-evidence does not attempt to fetch any data for the human-readable citizenid, blood type, or fingerprint or fingerprint fields when using the default implementation for ESX. However, for qb-core, because this data is stored in the PlayerData for each character, it simply pulls the information and does not attempt to generate it on its own.

Server-side Player Data Function
    PlayerDataServer = function(source) -- gets player data on server
if Config.Framework.ESX then
local PlyData = ESX.GetPlayerFromId(source)

local PlayerData = {
identifier = PlyData.identifier,
citizenid = nil,
bloodtype = nil,
fingerprint = nil,
firstname = PlyData.variables.firstName,
lastname = PlyData.variables.lastName,
job = PlyData.job.name,
jobgrade = PlyData.job.grade,
}

return PlayerData
elseif Config.Framework.QB then
local PlyData = QBCore.Functions.GetPlayer(source).PlayerData

local PlayerData = {
identifier = PlyData.citizenid,
citizenid = PlyData.citizenid,
bloodtype = PlyData.metadata.bloodtype,
fingerprint = PlyData.metadata.fingerprint,
firstname = PlyData.charinfo.firstname,
lastname = PlyData.charinfo.lastname,
job = PlyData.job.name,
jobgrade = tostring(PlyData.job.grade.level),
jobtype = PlyData.job.type,
}

return PlayerData
elseif Config.Framework.Standalone then
-- there is nothing here, you must write it
end
end,
Server-side Player Data Function
    PlayerDataClient = function()
if Config.Framework.ESX then
local PlyData = ESX.GetPlayerData()

local PlayerData = {
identifier = PlyData.identifier,
citizenid = nil, -- the script will generate a unique citizen id for each character based on the unique character identifier
bloodtype = nil, -- the script will assign a bloodtype for each character based on the unique character identifier
fingerprint = nil, -- the script will generate a unique fingerprint for each character based on the unique character identifier
firstname = PlyData.firstName,
lastname = PlyData.lastName,
job = PlyData.job?.name,
jobgrade = PlyData.job?.grade,
}

return PlayerData
elseif Config.Framework.QB then
local PlyData = QBCore.Functions.GetPlayerData()

local PlayerData = {
identifier = PlyData.citizenid,
citizenid = PlyData.citizenid,
bloodtype = PlyData.metadata.bloodtype,
fingerprint = PlyData.metadata.fingerprint,
firstname = PlyData.charinfo.firstname,
lastname = PlyData.charinfo.lastname,
job = PlyData.job.name,
jobgrade = tostring(PlyData.job.grade.level),
jobtype = PlyData.job.type,
}

return PlayerData
elseif Config.Framework.Standalone then
-- there is nothing here, you must write it
end
end,

If you have made a modification to your framework, and store these values somewhere that you would like the script to use, it's a simple matter of simply creating a way to fetch this information in the config.

Server-side Player Data Function
    PlayerDataClient = function()
if Config.Framework.ESX then
local PlyData = ESX.GetPlayerData()
local fingerprintCallback = nil

ESX.TriggerServerCallback('fake-fingerprint-script:getFingerprint', function(result)
fingerprintCallback = result or 'not found'
end, PlyData.identifier)

while not fingerprintCallback do
Wait(100)
end


local PlayerData = {
identifier = PlyData.identifier,
citizenid = exports['fake-citizen-id-script']:getPlayerCitizenId(),
bloodtype = PlyData.custombloodtype, -- lets say we have modified our playerdata to keep track of bloodtype
fingerprint = fingerprintCallback, -- use the fingerprint we fetched from the callback
firstname = PlyData.firstName,
lastname = PlyData.lastName,
job = PlyData.job?.name,
jobgrade = PlyData.job?.grade,
}

return PlayerData
elseif Config.Framework.QB then
-- temporarily removed
elseif Config.Framework.Standalone then
-- there is nothing here, you must write it
end
end,

As you can see above, we have now modified our Config.Functions.PlayerDataClient() function to now pull our custom identifiers from other scripts or places in our code using callbacks, exports, or our custom playerdata we have set up in our specific hypothetical server. As long as all of these are properly returned and not nil, the script will not attempt to generate them now. If they do not work and come back nil, or you simply don't have a way to access them, we can proceedt to the SQL step of our install which will direct us how to set up our evidence identifiers database.