diff --git a/resources/[qb]/Duck_relogextra/client.lua b/resources/[qb]/Duck_relogextra/client.lua index 8d2e0b2b3..aa28c631d 100644 --- a/resources/[qb]/Duck_relogextra/client.lua +++ b/resources/[qb]/Duck_relogextra/client.lua @@ -1,38 +1,38 @@ -local QBCore = exports['qb-core']:GetCoreObject() -local savedLocation = nil - -RegisterCommand("relog", function() - local ped = PlayerPedId() - local coords = GetEntityCoords(ped) - local heading = GetEntityHeading(ped) - local cid = QBCore.Functions.GetPlayerData().citizenid - - -- Speicher Ort vor Relog - TriggerServerEvent("qb-relogsave:server:saveLocation", cid, { - x = coords.x, - y = coords.y, - z = coords.z - }, heading) - - TriggerEvent("qb-multicharacter:client:chooseChar") -end, false) - -RegisterNetEvent("qb-relogsave:client:restoreLocation", function(pos, heading) - savedLocation = { - pos = pos, - heading = heading - } -end) - -RegisterNetEvent("qb-spawn:client:spawned", function() - if savedLocation then - DoScreenFadeOut(500) - Wait(500) - SetEntityCoords(PlayerPedId(), savedLocation.pos.x, savedLocation.pos.y, savedLocation.pos.z) - SetEntityHeading(PlayerPedId(), savedLocation.heading) - Wait(500) - DoScreenFadeIn(500) - - savedLocation = nil - end -end) +local QBCore = exports['qb-core']:GetCoreObject() +local savedLocation = nil + +RegisterCommand("relog", function() + local ped = PlayerPedId() + local coords = GetEntityCoords(ped) + local heading = GetEntityHeading(ped) + local cid = QBCore.Functions.GetPlayerData().citizenid + + -- Speicher Ort vor Relog + TriggerServerEvent("qb-relogsave:server:saveLocation", cid, { + x = coords.x, + y = coords.y, + z = coords.z + }, heading) + + TriggerEvent("qb-multicharacter:client:chooseChar") +end, false) + +RegisterNetEvent("qb-relogsave:client:restoreLocation", function(pos, heading) + savedLocation = { + pos = pos, + heading = heading + } +end) + +RegisterNetEvent("qb-spawn:client:spawned", function() + if savedLocation then + DoScreenFadeOut(500) + Wait(500) + SetEntityCoords(PlayerPedId(), savedLocation.pos.x, savedLocation.pos.y, savedLocation.pos.z) + SetEntityHeading(PlayerPedId(), savedLocation.heading) + Wait(500) + DoScreenFadeIn(500) + + savedLocation = nil + end +end) diff --git a/resources/[qb]/Duck_relogextra/fxmanifest.lua b/resources/[qb]/Duck_relogextra/fxmanifest.lua index 0440d1343..c252376b4 100644 --- a/resources/[qb]/Duck_relogextra/fxmanifest.lua +++ b/resources/[qb]/Duck_relogextra/fxmanifest.lua @@ -1,12 +1,13 @@ -fx_version 'cerulean' -game 'gta5' - -description 'relog system' -author 'Duck' -version '1.0.0' - -client_script 'client.lua' -server_script 'server.lua' - -shared_script '@qb-core/shared/locale.lua' -dependency 'qb-core' +fx_version 'cerulean' +game 'gta5' + +description 'relog system' +author 'Duck' +version '1.0.1' + +client_script 'client.lua' +server_script 'server.lua' + +shared_script '@qb-core/shared/locale.lua' +dependency 'qb-core' +dependency 'um-multicharacter' diff --git a/resources/[qb]/Duck_relogextra/server.lua b/resources/[qb]/Duck_relogextra/server.lua index ca460d5fa..04c578ed4 100644 --- a/resources/[qb]/Duck_relogextra/server.lua +++ b/resources/[qb]/Duck_relogextra/server.lua @@ -1,23 +1,34 @@ -local savedLocations = {} - -local QBCore = exports['qb-core']:GetCoreObject() - -RegisterNetEvent("qb-relogsave:server:saveLocation", function(cid, coords, heading) - savedLocations[cid] = { - pos = coords, - heading = heading - } -end) - -AddEventHandler('QBCore:Server:PlayerLoaded', function(Player) - local cid = Player.PlayerData.citizenid - - if savedLocations[cid] then - local pos = savedLocations[cid].pos - local heading = savedLocations[cid].heading - - TriggerClientEvent("qb-relogsave:client:restoreLocation", Player.PlayerData.source, pos, heading) - - savedLocations[cid] = nil - end -end) +local savedLocations = {} +local QBCore = exports['qb-core']:GetCoreObject() + +RegisterNetEvent("qb-relogsave:server:saveLocation", function(cid, coords, heading) + if not cid or not coords then return end + + savedLocations[cid] = { + pos = coords, + heading = heading, + timestamp = os.time() + } + + print("Position für " .. cid .. " gespeichert: " .. json.encode(coords)) +end) + +AddEventHandler('QBCore:Server:PlayerLoaded', function(Player) + if not Player or not Player.PlayerData then return end + + local cid = Player.PlayerData.citizenid + + if savedLocations[cid] then + local pos = savedLocations[cid].pos + local heading = savedLocations[cid].heading + + if pos and pos.x and pos.y and pos.z then + TriggerClientEvent("qb-relogsave:client:restoreLocation", Player.PlayerData.source, pos, heading) + print("Position für " .. cid .. " wiederhergestellt") + else + print("Ungültige Position für " .. cid .. " gefunden") + end + + savedLocations[cid] = nil + end +end)