functionQBCore.Functions.GetIdentifier(source,idtype)local idtype = idtype or QBConfig.IdentifierTypefor key, value inpairs(GetPlayerIdentifiers(source)) doifstring.find(value, idtype) thenreturn identifierendendreturnnilend-- Examplelocal identifier = QBCore.Functions.GetIdentifier(source, 'license')print(identifier)OR -- defaults to the identifier in the config of qb-corelocal identifier = QBCore.Functions.GetIdentifier(source)print(identifier)
QBCore.Functions.GetSource
Get a players source by identifer
functionQBCore.Functions.GetSource(identifier)for key, value inpairs(QBCore.Players) dolocal identifiers =GetPlayerIdentifiers(key)for _, id inpairs(identifiers) doif identifier == id thenreturn keyendendendreturn0end-- Examplelocal identifier = QBCore.Functions.GetIdentifier(source, 'license')local playerSource = QBCore.Functions.GetSource(identifier)print(playerSource)
QBCore.Functions.GetPlayer
Get a player by their source and access their data
functionQBCore.Functions.GetPlayer(source)local src = sourceiftype(src) =='number' thenreturn QBCore.Players[src]elsereturn QBCore.Players[QBCore.Functions.GetSource(src)]endend-- Examplelocal Player = QBCore.Functions.GetPlayer(source)print(QBCore.Debug(Player))OR -- access some player datalocal Player = QBCore.Functions.GetPlayer(source)print(Player.PlayerData.citizenid)
QBCore.Functions.GetPlayerByCitizenId
Get a player by their citizen id and access their data (must be online)
functionQBCore.Functions.GetPlayerByCitizenId(citizenid)for key, value inpairs(QBCore.Players) doif QBCore.Players[key].PlayerData.citizenid == citizenid thenreturn QBCore.Players[key]endendreturnnilend-- Examplelocal Player = QBCore.Functions.GetPlayerByCitizenId('ONZ55343')print(QBCore.Debug(Player))OR -- access some player datalocal Player = QBCore.Functions.GetPlayerByCitizenId('ONZ55343')print(Player.PlayerData.license)
QBCore.Functions.GetPlayerByPhone
Get a player by their phone number (must be online)
functionQBCore.Functions.GetPlayerByPhone(number)for key, value inpairs(QBCore.Players) doif QBCore.Players[key].PlayerData.charinfo.phone == number thenreturn QBCore.Players[key]endendreturnnilend-- Examplelocal Player = QBCore.Functions.GetPlayerByPhone('1264756087')print(QBCore.Debug(Player))OR -- access some player datalocal Player = QBCore.Functions.GetPlayerByPhone('1264756087')print(Player.PlayerData.license)
QBCore.Functions.GetPlayers
Get all player IDs in the server (deprecated method)
functionQBCore.Functions.GetPlayers()local sources = {}for key, value inpairs(QBCore.Players) do sources[#sources +1] = keyendreturn sourcesend-- Examplelocal Players = QBCore.Functions.GetPlayers()print(QBCore.Debug(Players))
QBCore.Functions.GetQBPlayers
Access the table of all active players on the server (preferred to above)
functionQBCore.Functions.CreateUseableItem(item,cb) QBCore.UseableItems[item] = cbend-- ExampleQBCore.Functions.CreateUseableItem('my_cool_item', function(source,item)local Player = QBCore.Functions.GetPlayer(source)ifnot Player.Functions.GetItemByName(item.name) thenreturnend-- Trigger code here for what item should doend)
QBCore.Functions.CanUseItem
Check if an item is registered as usable before attempting use
functionQBCore.Functions.HasPermission(source,permission)ifIsPlayerAceAllowed(source, permission) thenreturntrueendreturnfalseend-- Examplelocal hasPerms = QBCore.Functions.HasPermission(source, 'admin')print(hasPerms)OR -- using as a conditionlocal hasPerms = QBCore.Functions.HasPermission(source, 'admin')ifnot hasPerms thenreturnend-- Trigger code here
QBCore.Functions.GetPermission
Get a player's permission level
functionQBCore.Functions.GetPermission(source)local src = sourcelocal perms = {}for key, value inpairs (QBCore.Config.Server.Permissions) doifIsPlayerAceAllowed(src, value) then perms[value] =trueendendreturn permsend-- Examplelocal permissions = QBCore.Functions.GetPermission(source)print(QBCore.Debug(permissions))OR -- using as a conditionlocal permissions = QBCore.Functions.GetPermission(source)for key, value inpairs(permissions) doif value ==truethenprint(key)endend
QBCore.Functions.IsPlayerBanned
Check if a player is banned (used for connection)
functionQBCore.Functions.IsPlayerBanned(source)local plicense = QBCore.Functions.GetIdentifier(source, 'license')local result = MySQL.Sync.fetchSingle('SELECT * FROM bans WHERE license = ?', { plicense })ifnot result thenreturnfalseendifos.time() < result.expire thenlocal timeTable =os.date('*t', tonumber(result.expire))returntrue, 'You have been banned from the server:\n' .. result.reason ..'\nYour ban expires ' .. timeTable.day ..'/' .. timeTable.month ..'/' .. timeTable.year ..' ' .. timeTable.hour ..':' .. timeTable.min ..'\n'else MySQL.Async.execute('DELETE FROM bans WHERE id = ?', { result.id })endreturnfalseend-- Examplelocal isBanned = QBCore.Functions.IsPlayerBanned(source)print(isBanned)
QBCore.Functions.IsLicenseInUse
Prevent duplicate licenses on the server (used for connection)
functionQBCore.Functions.IsLicenseInUse(license)local players =GetPlayers()for key, value inpairs(players) dolocal identifiers =GetPlayerIdentifiers(value)for _, id inpairs(identifiers) doifstring.find(id, 'license') thenif id == license thenreturntrueendendendendreturnfalseend-- Examplelocal license = QBCore.Functions.GetIdentifier(source, 'license')local isUsed = QBCore.Functions.IsLicenseInUse(license)print(isUsed)