🖥
Server Function Reference
Learn about and how to use common core server functions!
- Get the coords of a passed entity
function QBCore.Functions.GetCoords(entity)
local coords = GetEntityCoords(entity, false)
local heading = GetEntityHeading(entity)
return vector4(coords.x, coords.y, coords.z, heading)
end
-- Example
local ped = GetPlayerPed(source)
local coords = QBCore.Functions.GetCoords(ped)
print(coords)
- Get a specific identifier of a player
function QBCore.Functions.GetIdentifier(source, idtype)
local idtype = idtype or QBConfig.IdentifierType
for key, value in pairs(GetPlayerIdentifiers(source)) do
if string.find(value, idtype) then
return identifier
end
end
return nil
end
-- Example
local identifier = QBCore.Functions.GetIdentifier(source, 'license')
print(identifier)
OR -- defaults to the identifier in the config of qb-core
local identifier = QBCore.Functions.GetIdentifier(source)
print(identifier)
- Get a players source by identifer
function QBCore.Functions.GetSource(identifier)
for key, value in pairs(QBCore.Players) do
local identifiers = GetPlayerIdentifiers(key)
for _, id in pairs(identifiers) do
if identifier == id then
return key
end
end
end
return 0
end
-- Example
local identifier = QBCore.Functions.GetIdentifier(source, 'license')
local playerSource = QBCore.Functions.GetSource(identifier)
print(playerSource)
- Get a player by their source and access their data
function QBCore.Functions.GetPlayer(source)
local src = source
if type(src) == 'number' then
return QBCore.Players[src]
else
return QBCore.Players[QBCore.Functions.GetSource(src)]
end
end
-- Example
local Player = QBCore.Functions.GetPlayer(source)
print(QBCore.Debug(Player))
OR -- access some player data
local Player = QBCore.Functions.GetPlayer(source)
print(Player.PlayerData.citizenid)
- Get a player by their citizen id and access their data (must be online)
function QBCore.Functions.GetPlayerByCitizenId(citizenid)
for key, value in pairs(QBCore.Players) do
if QBCore.Players[key].PlayerData.citizenid == citizenid then
return QBCore.Players[key]
end
end
return nil
end
-- Example
local Player = QBCore.Functions.GetPlayerByCitizenId('ONZ55343')
print(QBCore.Debug(Player))
OR -- access some player data
local Player = QBCore.Functions.GetPlayerByCitizenId('ONZ55343')
print(Player.PlayerData.license)
- Get a player by their phone number (must be online)
function QBCore.Functions.GetPlayerByPhone(number)
for key, value in pairs(QBCore.Players) do
if QBCore.Players[key].PlayerData.charinfo.phone == number then
return QBCore.Players[key]
end
end
return nil
end
-- Example