feat: function to avoid saving last location on specifc locations

This commit is contained in:
Andyyy7666
2025-09-08 19:12:43 +02:00
parent 73f38c12f6
commit 4f9d274c62

View File

@@ -1,3 +1,5 @@
local avoidSavingLastLocations = {}
local function removeCharacterFunctions(character) local function removeCharacterFunctions(character)
local newData = {} local newData = {}
for k, v in pairs(character) do for k, v in pairs(character) do
@@ -145,24 +147,40 @@ local function createCharacterTable(info)
-- Unload and save character -- Unload and save character
function self.unload() function self.unload()
if not NDCore.players[self.source] then return end if not NDCore.players[self.source] then return end
for name, _ in pairs(self.groups) do for name, _ in pairs(self.groups) do
lib.removePrincipal(self.source, ("group.%s"):format(name)) lib.removePrincipal(self.source, ("group.%s"):format(name))
end end
local ped = GetPlayerPed(self.source) local ped = GetPlayerPed(self.source)
if ped then if ped then
local coords = GetEntityCoords(ped) local coords = GetEntityCoords(ped)
local heading = GetEntityHeading(ped) local heading = GetEntityHeading(ped)
self.setMetadata("location", { local saveLocation = true
x = coords.x,
y = coords.y, for i=1, #avoidSavingLastLocations do
z = coords.z, local loc = avoidSavingLastLocations[i]
w = heading 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 end
self.triggerEvent("ND:characterUnloaded") self.triggerEvent("ND:characterUnloaded")
TriggerEvent("ND:characterUnloaded", self.source, self) TriggerEvent("ND:characterUnloaded", self.source, self)
local saved = self.save() local saved = self.save()
NDCore.players[self.source] = nil NDCore.players[self.source] = nil
return saved return saved
end end