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("QBCore:Client:OnPlayerLoaded", function()
Wait(1000)
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("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)

View file

@ -1,9 +1,9 @@
fx_version 'cerulean'
game 'gta5'
description 'relog system'
description 'Easy Relog // um-multi. ist erforderlich
author 'Duck'
version '1.0.1'
version '1.0.0'
client_script 'client.lua'
server_script 'server.lua'

View file

@ -2,29 +2,15 @@ local savedLocations = {}
local QBCore = exports['qb-core']:GetCoreObject()
local function DebugPrint(msg)
print("^2[RELOG-DEBUG] ^7" .. msg)
end
RegisterNetEvent("qb-relogsave:server:saveLocation", function(cid, coords, heading)
local src = source
local playerName = GetPlayerName(src) or "Unbekannt"
if not cid or not coords then
DebugPrint("Fehler: Ungültige Daten von " .. playerName .. " (ID: " .. src .. ")")
return
end
if not cid or not coords then return end
savedLocations[cid] = {
pos = coords,
heading = heading,
timestamp = os.time(),
playerName = playerName
heading = heading
}
DebugPrint("Position für " .. playerName .. " (CID: " .. cid .. ") gespeichert: X=" ..
coords.x .. ", Y=" .. coords.y .. ", Z=" .. coords.z)
print("[Relog] Position für " .. cid .. " gespeichert")
end)
@ -32,68 +18,23 @@ RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then
DebugPrint("Fehler: Spieler nicht gefunden (ID: " .. src .. ")")
return
end
if not Player then return end
local cid = Player.PlayerData.citizenid
DebugPrint("Spieler geladen: " .. Player.PlayerData.name .. " (CID: " .. cid .. ")")
if savedLocations[cid] then
local pos = savedLocations[cid].pos
local heading = savedLocations[cid].heading
local timestamp = savedLocations[cid].timestamp
local timeAgo = os.time() - timestamp
DebugPrint("Gespeicherte Position gefunden für " .. cid .. " (vor " .. timeAgo .. " Sekunden)")
if pos and pos.x and pos.y and pos.z then
DebugPrint("Position wird wiederhergestellt: X=" .. pos.x .. ", Y=" .. pos.y .. ", Z=" .. pos.z)
TriggerClientEvent("qb-relogsave:client:restoreLocation", src, pos, heading)
else
DebugPrint("Ungültige Position für " .. cid)
end
TriggerClientEvent("qb-relogsave:client:restoreLocation", src, pos, heading)
print("[Relog] Position für " .. cid .. " wiederhergestellt")
savedLocations[cid] = nil
else
DebugPrint("Keine gespeicherte Position für " .. cid .. " gefunden")
end
end)
RegisterNetEvent('um-multicharacter:server:CharacterLoaded', function()
RegisterNetEvent("qb-relogsave:server:kickForRelog", function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local cid = Player.PlayerData.citizenid
DebugPrint("um-multicharacter: Charakter geladen für " .. cid)
if savedLocations[cid] then
TriggerClientEvent("qb-relogsave:client:restoreLocation", src, savedLocations[cid].pos, savedLocations[cid].heading)
savedLocations[cid] = nil
end
DropPlayer(src, "Relog wird durchgeführt... Bitte erneut verbinden.")
end)
QBCore.Commands.Add('relogpositions', 'Zeigt alle gespeicherten Relog-Positionen', {}, false, function(source)
local count = 0
for cid, data in pairs(savedLocations) do
count = count + 1
local timeAgo = os.time() - (data.timestamp or 0)
TriggerClientEvent('QBCore:Notify', source, cid .. ": " ..
"X=" .. math.floor(data.pos.x) ..
" Y=" .. math.floor(data.pos.y) ..
" Z=" .. math.floor(data.pos.z) ..
" (vor " .. timeAgo .. "s)")
end
if count == 0 then
TriggerClientEvent('QBCore:Notify', source, "Keine gespeicherten Positionen")
end
end, 'admin')