From f93c31fa54d9658e82c01c3e69647ae901af46b2 Mon Sep 17 00:00:00 2001 From: Swellington Soares <138418902+xSwellington@users.noreply.github.com> Date: Wed, 20 Sep 2023 17:02:43 -0300 Subject: [PATCH] Update functions.lua Added functions to Get players by account and added functions by char info passing the key property and value to check if exists. --- server/functions.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/server/functions.lua b/server/functions.lua index 8b9e106..da20289 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -88,6 +88,33 @@ function QBCore.Functions.GetPlayerByPhone(number) return nil end +---Get player by account id +---@param account string +---@return table? +function QBCore.Functions.GetPlayerByAccount(account) + for src in pairs(QBCore.Players) do + if QBCore.Players[src].PlayerData.charinfo.account == account then + return QBCore.Players[src] + end + end + return nil +end + +---Get player passing property and value to check exists +---@param property string +---@param value string +---@return table? +function QBCore.Functions.GetPlayerByCharInfo(property, value) + for src in pairs(QBCore.Players) do + local charinfo = QBCore.Players[src].PlayerData.charinfo + if charinfo[property] ~= nil and charinfo[property] == value then + return QBCore.Players[src] + end + end + return nil +end + + ---Get all players. Returns the server ids of all players. ---@return table function QBCore.Functions.GetPlayers()