From 2ab26fe51dffe2cdd9120cbbc7b61dc135a469ae Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Mon, 16 Mar 2026 05:43:18 +0100 Subject: [PATCH] refactor(server/player): saving last location into separate function --- server/player.lua | 52 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/server/player.lua b/server/player.lua index 97f2795..2d6d1de 100644 --- a/server/player.lua +++ b/server/player.lua @@ -144,6 +144,34 @@ local function createCharacterTable(info) end return result end + + --save last location + function self.saveLastLocation() + local ped = GetPlayerPed(self.source) + if not ped or ped == 0 then return end + + local coords = GetEntityCoords(ped) + local heading = GetEntityHeading(ped) + local saveLocation = true + + for i=1, #avoidSavingLastLocations do + local loc = avoidSavingLastLocations[i] + if #(loc.coords-coords) < loc.dist then + saveLocation = false + end + end + + if not saveLocation then return end + + self.setMetadata("location", { + x = coords.x, + y = coords.y, + z = coords.z, + w = heading + }) + + return true + end -- Unload and save character function self.unload() @@ -153,29 +181,7 @@ local function createCharacterTable(info) 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) - 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.saveLastLocation() self.triggerEvent("ND:characterUnloaded") TriggerEvent("ND:characterUnloaded", self.source, self)