mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
refactor(server/player): saving last location into separate function
This commit is contained in:
@@ -145,16 +145,11 @@ local function createCharacterTable(info)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Unload and save character
|
--save last location
|
||||||
function self.unload()
|
function self.saveLastLocation()
|
||||||
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)
|
local ped = GetPlayerPed(self.source)
|
||||||
if ped then
|
if not ped or ped == 0 then return end
|
||||||
|
|
||||||
local coords = GetEntityCoords(ped)
|
local coords = GetEntityCoords(ped)
|
||||||
local heading = GetEntityHeading(ped)
|
local heading = GetEntityHeading(ped)
|
||||||
local saveLocation = true
|
local saveLocation = true
|
||||||
@@ -166,16 +161,27 @@ local function createCharacterTable(info)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if saveLocation then
|
if not saveLocation then return end
|
||||||
|
|
||||||
self.setMetadata("location", {
|
self.setMetadata("location", {
|
||||||
x = coords.x,
|
x = coords.x,
|
||||||
y = coords.y,
|
y = coords.y,
|
||||||
z = coords.z,
|
z = coords.z,
|
||||||
w = heading
|
w = heading
|
||||||
})
|
})
|
||||||
end
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
|
||||||
|
self.saveLastLocation()
|
||||||
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