Fix / erweiterung

This commit is contained in:
Max 2025-06-27 10:01:34 +02:00
parent 74a2529594
commit c30708c702
2 changed files with 178 additions and 20 deletions

View file

@ -1,38 +1,131 @@
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)
local heading = GetEntityHeading(ped)
local cid = QBCore.Functions.GetPlayerData().citizenid
-- Speicher Ort vor Relog
TriggerServerEvent("qb-relogsave:server:saveLocation", cid, {
local playerData = QBCore.Functions.GetPlayerData()
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")
return
end
local posData = {
x = coords.x,
y = coords.y,
z = coords.z
}, heading)
TriggerEvent("qb-multicharacter:client:chooseChar")
}
DebugPrint("Position wird gespeichert: X=" .. posData.x .. ", Y=" .. posData.y .. ", Z=" .. posData.z)
TriggerServerEvent("qb-relogsave:server:saveLocation", cid, posData, heading)
Wait(500)
DebugPrint("Trigger um-multicharacter:client:chooseChar")
TriggerEvent("um-multicharacter:client:chooseChar")
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
DebugPrint("Position empfangen: X=" .. pos.x .. ", Y=" .. pos.y .. ", Z=" .. pos.z)
savedLocation = {
pos = pos,
heading = heading
}
end)
RegisterNetEvent("qb-spawn:client:spawned", function()
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
function RestorePosition()
if savedLocation then
DebugPrint("Versuche Position wiederherzustellen...")
Wait(1000)
DoScreenFadeOut(500)
Wait(500)
SetEntityCoords(PlayerPedId(), savedLocation.pos.x, savedLocation.pos.y, savedLocation.pos.z)
SetEntityHeading(PlayerPedId(), savedLocation.heading)
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
Wait(500)
DoScreenFadeIn(500)
savedLocation = nil
DebugPrint("Position wiederhergestellt und gelöscht")
else
DebugPrint("Keine gespeicherte Position zum Wiederherstellen")
end
end
Citizen.CreateThread(function()
DebugPrint("Relog-System initialisiert")
CheckEvents()
end)