From 868600197dfde3772407552403040ea84d629ae8 Mon Sep 17 00:00:00 2001 From: EinS4ckZwiebeln <66690565+EinS4ckZwiebeln@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:56:32 +0100 Subject: [PATCH] Optimizations --- client/functions.lua | 19 ++++++++----------- server/functions.lua | 2 +- server/player.lua | 12 ++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 8073e9a..1dc191c 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -265,15 +265,13 @@ end function QBCore.Functions.GetPeds(ignoreList) local pedPool = GetGamePool('CPed') local peds = {} + local ignoreTable = {} ignoreList = ignoreList or {} - for i = 1, #pedPool, 1 do - local found = false - for j = 1, #ignoreList, 1 do - if ignoreList[j] == pedPool[i] then - found = true - end - end - if not found then + for i = 1, #ignoreList do + ignoreTable[ignoreList[i]] = true + end + for i = 1, #pedPool do + if not ignoreTable[pedPool[i]] then peds[#peds + 1] = pedPool[i] end end @@ -353,9 +351,8 @@ function QBCore.Functions.GetPlayersFromCoords(coords, distance) end distance = distance or 5 local closePlayers = {} - for _, player in pairs(players) do - local target = GetPlayerPed(player) - local targetCoords = GetEntityCoords(target) + for _, player in ipairs(players) do + local targetCoords = GetEntityCoords(GetPlayerPed(player)) local targetdistance = #(targetCoords - coords) if targetdistance <= distance then closePlayers[#closePlayers + 1] = player diff --git a/server/functions.lua b/server/functions.lua index a068e6b..b85d70b 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -522,7 +522,7 @@ end ---@return boolean, string? function QBCore.Functions.IsPlayerBanned(source) local plicense = QBCore.Functions.GetIdentifier(source, 'license') - local result = MySQL.single.await('SELECT * FROM bans WHERE license = ?', { plicense }) + local result = MySQL.single.await('SELECT id, reason, expire FROM bans WHERE license = ?', { plicense }) if not result then return false end if os.time() < result.expire then local timeTable = os.date('*t', tonumber(result.expire)) diff --git a/server/player.lua b/server/player.lua index b8c846b..17e2e6d 100644 --- a/server/player.lua +++ b/server/player.lua @@ -59,6 +59,18 @@ function QBCore.Player.GetOfflinePlayer(citizenid) end function QBCore.Player.GetPlayerByLicense(license) + if license then + local source = QBCore.Functions.GetSource(license) + if source > 0 then + return QBCore.Players[source] + else + return QBCore.Player.GetOfflinePlayerByLicense(license) + end + end + return nil +end + +function QBCore.Player.GetOfflinePlayerByLicense(license) if license then local PlayerData = MySQL.prepare.await('SELECT * FROM players where license = ?', { license }) if PlayerData then