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

View file

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

View file

@ -2,29 +2,15 @@ local savedLocations = {}
local QBCore = exports['qb-core']:GetCoreObject() 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) RegisterNetEvent("qb-relogsave:server:saveLocation", function(cid, coords, heading)
local src = source if not cid or not coords then return end
local playerName = GetPlayerName(src) or "Unbekannt"
if not cid or not coords then
DebugPrint("Fehler: Ungültige Daten von " .. playerName .. " (ID: " .. src .. ")")
return
end
savedLocations[cid] = { savedLocations[cid] = {
pos = coords, pos = coords,
heading = heading, heading = heading
timestamp = os.time(),
playerName = playerName
} }
DebugPrint("Position für " .. playerName .. " (CID: " .. cid .. ") gespeichert: X=" .. print("[Relog] Position für " .. cid .. " gespeichert")
coords.x .. ", Y=" .. coords.y .. ", Z=" .. coords.z)
end) end)
@ -32,68 +18,23 @@ RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
local src = source local src = source
local Player = QBCore.Functions.GetPlayer(src) local Player = QBCore.Functions.GetPlayer(src)
if not Player then if not Player then return end
DebugPrint("Fehler: Spieler nicht gefunden (ID: " .. src .. ")")
return
end
local cid = Player.PlayerData.citizenid local cid = Player.PlayerData.citizenid
DebugPrint("Spieler geladen: " .. Player.PlayerData.name .. " (CID: " .. cid .. ")")
if savedLocations[cid] then if savedLocations[cid] then
local pos = savedLocations[cid].pos local pos = savedLocations[cid].pos
local heading = savedLocations[cid].heading 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)") TriggerClientEvent("qb-relogsave:client:restoreLocation", src, pos, heading)
print("[Relog] Position für " .. cid .. " wiederhergestellt")
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
savedLocations[cid] = nil savedLocations[cid] = nil
else
DebugPrint("Keine gespeicherte Position für " .. cid .. " gefunden")
end end
end) end)
RegisterNetEvent('um-multicharacter:server:CharacterLoaded', function() RegisterNetEvent("qb-relogsave:server:kickForRelog", function()
local src = source local src = source
local Player = QBCore.Functions.GetPlayer(src) DropPlayer(src, "Relog wird durchgeführt... Bitte erneut verbinden.")
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
end) 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')