From 4f9d274c626146e8df35c38c1052badf471463aa Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Mon, 8 Sep 2025 19:12:43 +0200 Subject: [PATCH] feat: function to avoid saving last location on specifc locations --- server/player.lua | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/server/player.lua b/server/player.lua index bb578bd..3560591 100644 --- a/server/player.lua +++ b/server/player.lua @@ -1,3 +1,5 @@ +local avoidSavingLastLocations = {} + local function removeCharacterFunctions(character) local newData = {} for k, v in pairs(character) do @@ -145,24 +147,40 @@ local function createCharacterTable(info) -- Unload and save character function self.unload() if not NDCore.players[self.source] then return end + for name, _ in pairs(self.groups) do lib.removePrincipal(self.source, ("group.%s"):format(name)) end + local ped = GetPlayerPed(self.source) if ped then local coords = GetEntityCoords(ped) local heading = GetEntityHeading(ped) - self.setMetadata("location", { - x = coords.x, - y = coords.y, - z = coords.z, - w = heading - }) + local saveLocation = true + + for i=1, #avoidSavingLastLocations do + local loc = avoidSavingLastLocations[i] + if #(loc.coords-coords) < loc.dist then + saveLocation = false + end + end + + if saveLocation then + self.setMetadata("location", { + x = coords.x, + y = coords.y, + z = coords.z, + w = heading + }) + end end + self.triggerEvent("ND:characterUnloaded") TriggerEvent("ND:characterUnloaded", self.source, self) + local saved = self.save() NDCore.players[self.source] = nil + return saved end