mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-18 22:36:03 +01:00
refactor(server/player): saving last location into separate function
This commit is contained in:
@@ -144,6 +144,34 @@ local function createCharacterTable(info)
|
|||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
end
|
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
|
-- Unload and save character
|
||||||
function self.unload()
|
function self.unload()
|
||||||
@@ -153,29 +181,7 @@ local function createCharacterTable(info)
|
|||||||
lib.removePrincipal(self.source, ("group.%s"):format(name))
|
lib.removePrincipal(self.source, ("group.%s"):format(name))
|
||||||
end
|
end
|
||||||
|
|
||||||
local ped = GetPlayerPed(self.source)
|
self.saveLastLocation()
|
||||||
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.triggerEvent("ND:characterUnloaded")
|
self.triggerEvent("ND:characterUnloaded")
|
||||||
TriggerEvent("ND:characterUnloaded", self.source, self)
|
TriggerEvent("ND:characterUnloaded", self.source, self)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user