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.UseItem(source,item) QBCore.UseableItems[item.name](source, item)end-- Examplelocal Player = QBCore.Functions.GetPlayer(source)ifnot Player.Functions.GetItemByName('my_cool_item') thenreturnendQBCore.Functions.UseItem(source, 'my_cool_item')
QBCore.Functions.Kick
Kick a player from the server
functionQBCore.Functions.Kick(source,reason,setKickReason,deferrals)local src = source reason ='\n'..reason..'\nđ¸ Check our Discord for further information: '..QBCore.Config.Server.discordif setKickReason then setKickReason(reason)end CreateThread(function()if deferrals then deferrals.update(reason) Wait(2500)endif src then DropPlayer(src, reason)endlocal i =0while (i <=4) do i = i +1whiletruedoif src thenif(GetPlayerPing(src) >=0) thenbreakend Wait(100) CreateThread(function() DropPlayer(src, reason)end)endend Wait(5000)endend)end-- ExampleQBCore.Functions.Kick(playerId, 'You messed up', true, true)
QBCore.Functions.AddPermission
Give a player a specific permission level (per session only)