1
0
Fork 0
forked from Simnation/Main

fix relog

This commit is contained in:
Max 2025-06-27 10:14:00 +02:00
parent c30708c702
commit 46c69947b3
3 changed files with 38 additions and 142 deletions

View file

@ -2,11 +2,6 @@ local QBCore = exports['qb-core']:GetCoreObject()
local savedLocation = nil
local function DebugPrint(msg)
print("^3[RELOG-CLIENT] ^7" .. msg)
end
RegisterCommand("relog", function()
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
@ -15,13 +10,9 @@ RegisterCommand("relog", function()
if not playerData or not playerData.citizenid then
QBCore.Functions.Notify("Fehler beim Abrufen der Spielerdaten", "error")
DebugPrint("Fehler: Keine Spielerdaten verfügbar")
return
end
local cid = playerData.citizenid
DebugPrint("Relog gestartet für CID: " .. cid)
if IsPedInAnyVehicle(ped, false) then
QBCore.Functions.Notify("Du kannst nicht im Fahrzeug relogen", "error")
@ -29,31 +20,30 @@ RegisterCommand("relog", function()
end
local posData = {
TriggerServerEvent("qb-relogsave:server:saveLocation", playerData.citizenid, {
x = coords.x,
y = coords.y,
z = coords.z
}
}, heading)
DebugPrint("Position wird gespeichert: X=" .. posData.x .. ", Y=" .. posData.y .. ", Z=" .. posData.z)
TriggerServerEvent("qb-relogsave:server:saveLocation", cid, posData, heading)
QBCore.Functions.Notify("Position gespeichert. Du wirst in 2 Sekunden zum Charaktermenü weitergeleitet...", "primary")
Wait(2000)
TriggerEvent("um-multicharacter:client:chooseChar")
Wait(500)
DebugPrint("Trigger um-multicharacter:client:chooseChar")
TriggerEvent("um-multicharacter:client:chooseChar")
TriggerServerEvent("qb-relogsave:server:kickForRelog")
end, false)
RegisterNetEvent("qb-relogsave:client:restoreLocation", function(pos, heading)
if not pos or not pos.x or not pos.y or not pos.z then
DebugPrint("Ungültige Position empfangen")
return
end
if not pos or not pos.x or not pos.y or not pos.z then return end
DebugPrint("Position empfangen: X=" .. pos.x .. ", Y=" .. pos.y .. ", Z=" .. pos.z)
savedLocation = {
pos = pos,
heading = heading
@ -61,71 +51,36 @@ RegisterNetEvent("qb-relogsave:client:restoreLocation", function(pos, heading)
end)
local function CheckEvents()
RegisterNetEvent("um-multicharacter:client:spawned", function()
DebugPrint("Event 'um-multicharacter:client:spawned' ausgelöst")
RestorePosition()
end)
RegisterNetEvent("um-multicharacter:client:playerSpawned", function()
DebugPrint("Event 'um-multicharacter:client:playerSpawned' ausgelöst")
RestorePosition()
end)
RegisterNetEvent("QBCore:Client:OnPlayerLoaded", function()
DebugPrint("Event 'QBCore:Client:OnPlayerLoaded' ausgelöst")
Wait(1000)
RestorePosition()
end)
RegisterNetEvent("playerSpawned", function()
DebugPrint("Event 'playerSpawned' ausgelöst")
RestorePosition()
end)
end
RegisterNetEvent("QBCore:Client:OnPlayerLoaded", function()
Wait(1000)
RestorePosition()
end)
RegisterNetEvent("um-multicharacter:client:spawned", function()
Wait(1000)
RestorePosition()
end)
function RestorePosition()
if savedLocation then
DebugPrint("Versuche Position wiederherzustellen...")
Wait(1000)
Wait(500)
DoScreenFadeOut(500)
Wait(600)
if savedLocation.pos and savedLocation.pos.x and savedLocation.pos.y and savedLocation.pos.z then
DebugPrint("Teleportiere zu X=" .. savedLocation.pos.x .. ", Y=" .. savedLocation.pos.y .. ", Z=" .. savedLocation.pos.z)
SetEntityCoords(PlayerPedId(), savedLocation.pos.x, savedLocation.pos.y, savedLocation.pos.z)
SetEntityHeading(PlayerPedId(), savedLocation.heading)
local ground, groundZ = GetGroundZFor_3dCoord(savedLocation.pos.x, savedLocation.pos.y, savedLocation.pos.z)
if ground then
SetEntityCoordsNoOffset(PlayerPedId(), savedLocation.pos.x, savedLocation.pos.y, groundZ + 1.0, false, false, false)
end
else
DebugPrint("Fehler: Ungültige Position beim Wiederherstellen")
end
SetEntityCoords(PlayerPedId(), savedLocation.pos.x, savedLocation.pos.y, savedLocation.pos.z)
SetEntityHeading(PlayerPedId(), savedLocation.heading)
Wait(500)
DoScreenFadeIn(500)
savedLocation = nil
DebugPrint("Position wiederhergestellt und gelöscht")
else
DebugPrint("Keine gespeicherte Position zum Wiederherstellen")
QBCore.Functions.Notify("Position wiederhergestellt", "success")
end
end
Citizen.CreateThread(function()
DebugPrint("Relog-System initialisiert")
CheckEvents()
end)