diff --git a/config.lua b/config.lua index 68632d4..f0dbf8d 100644 --- a/config.lua +++ b/config.lua @@ -72,19 +72,10 @@ QBConfig.Player.PlayerDefaults = { jailitems = {}, status = {}, phone = {}, - fitbit = {}, - bloodtype = function() return QBConfig.Player.Bloodtypes[math.random(1, #QBConfig.Player.Bloodtypes)] end, - dealerrep = 0, - craftingrep = 0, - attachmentcraftingrep = 0, + rep = {}, currentapartment = nil, - jobrep = { - tow = 0, - trucker = 0, - taxi = 0, - hotdog = 0 - }, callsign = 'NO CALLSIGN', + bloodtype = function() return QBConfig.Player.Bloodtypes[math.random(1, #QBConfig.Player.Bloodtypes)] end, fingerprint = function() return QBCore.Player.CreateFingerId() end, walletid = function() return QBCore.Player.CreateWalletId() end, criminalrecord = { diff --git a/server/functions.lua b/server/functions.lua index b85d70b..95bb8d9 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -165,6 +165,33 @@ function QBCore.Functions.GetDutyCount(job) return count end +function QBCore.Functions.GetClosestPlayer(source, coords) + local ped = GetPlayerPed(source) + if coords then + coords = type(coords) == 'table' and vector3(coords.x, coords.y, coords.z) or coords + else + coords = GetEntityCoords(ped) + end + + local closestDistance = -1 + local closestPlayer = -1 + + for _, playerId in ipairs(GetPlayers()) do + local playerPed = GetPlayerPed(playerId) + if playerPed ~= ped then + local playerCoords = GetEntityCoords(playerPed) + local distance = #(playerCoords - coords) + + if closestDistance == -1 or distance < closestDistance then + closestPlayer = playerId + closestDistance = distance + end + end + end + + return closestPlayer, closestDistance +end + -- Routing buckets (Only touch if you know what you are doing) ---Returns the objects related to buckets, first returned value is the player buckets, second one is entity buckets diff --git a/server/player.lua b/server/player.lua index ff26889..ace4e8f 100644 --- a/server/player.lua +++ b/server/player.lua @@ -236,13 +236,31 @@ function QBCore.Player.CreatePlayer(PlayerData, Offline) return self.PlayerData.metadata[meta] end - function self.Functions.AddJobReputation(amount) - if not amount then return end - amount = tonumber(amount) - self.PlayerData.metadata['jobrep'][self.PlayerData.job.name] = self.PlayerData.metadata['jobrep'][self.PlayerData.job.name] + amount + function self.Functions.AddRep(rep, amount) + if not rep or not amount then return end + local addAmount = tonumber(amount) + local currentRep = self.PlayerData.metadata['rep'][rep] or 0 + self.PlayerData.metadata['rep'][rep] = currentRep + addAmount self.Functions.UpdatePlayerData() end + function self.Functions.RemoveRep(rep, amount) + if not rep or not amount then return end + local removeAmount = tonumber(amount) + local currentRep = self.PlayerData.metadata['rep'][rep] or 0 + if currentRep - removeAmount < 0 then + self.PlayerData.metadata['rep'][rep] = 0 + else + self.PlayerData.metadata['rep'][rep] = currentRep - removeAmount + end + self.Functions.UpdatePlayerData() + end + + function self.Functions.GetRep(rep) + if not rep then return end + return self.PlayerData.metadata['rep'][rep] or 0 + end + function self.Functions.AddMoney(moneytype, amount, reason) reason = reason or 'unknown' moneytype = moneytype:lower()