Hello, just wondering, what is the best way to get data from users by identifier no matter what type of identifier im using. (using oxmysql)
Lets use this example
MySQL.prepare.await('SELECT rose_coin FROM users WHERE identifier = ?', {id})
what is the best way to get the ID?
i am using
local src = source
local playerIdentifier = GetPlayerIdentifiers(src)
local id = playerIdentifier[1]
to get steam, however im planning on swaping to licence cos of ESX, so changing the table index to local id = playerIdentifier[2]
is the way for me now, but what if i would get rid of steam completly, so the index would move by -1 so licence would be on the first position, is there any better way?
This native returns a specific identifier: NetworkGetNetworkIdFromEntity - FiveM Natives @ Cfx.re Docs
If you want all of them in an easy to access table, this is similar to what I mostly use:
-- Return an array with all identifiers
function GetPlayerIdentifiersSorted(playerServerId)
local ids = {}
local identifiers = GetPlayerIdentifiers(playerServerId)
for _, identifier in pairs (identifiers) do
local i, j = identifier:find(":")
local idType = identifier:sub(1, i-1)
ids[idType] = identifier
end
return ids
end
-- usage
local playerIdentifiers = GetPlayerIdentifiersSorted(playerId)
local steamId = playerIdentifiers["steam"]
local license = playerIdentifiers["license"]
local discord = playerIdentifiers["discord"]
exactly the answer i’ve been looking for, ty