forked from Simnation/Main
101 lines
3.1 KiB
Lua
101 lines
3.1 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
local savedLocation = nil
|
|
|
|
-- Relog-Befehl
|
|
RegisterCommand("relog", function()
|
|
local ped = PlayerPedId()
|
|
local coords = GetEntityCoords(ped)
|
|
local heading = GetEntityHeading(ped)
|
|
local playerData = QBCore.Functions.GetPlayerData()
|
|
|
|
if not playerData or not playerData.citizenid then
|
|
QBCore.Functions.Notify("Fehler beim Abrufen der Spielerdaten", "error")
|
|
return
|
|
end
|
|
|
|
-- Prüft, ob der Spieler in einem Fahrzeug ist
|
|
if IsPedInAnyVehicle(ped, false) then
|
|
QBCore.Functions.Notify("Du kannst nicht im Fahrzeug relogen", "error")
|
|
return
|
|
end
|
|
|
|
-- Speichert die Position vor dem Relog
|
|
TriggerServerEvent("qb-relogsave:server:saveLocation", playerData.citizenid, {
|
|
x = coords.x,
|
|
y = coords.y,
|
|
z = coords.z
|
|
}, heading)
|
|
|
|
QBCore.Functions.Notify("Position gespeichert. Leite zum Charaktermenü weiter...", "primary")
|
|
|
|
-- Kurze Verzögerung für die Benachrichtigung
|
|
Wait(1000)
|
|
|
|
-- DIREKTE WEITERLEITUNG ZUM MULTICHARACTER-MENÜ
|
|
-- Wir verwenden mehrere Methoden, um sicherzustellen, dass eine funktioniert
|
|
|
|
-- Methode 1: Standard um-multicharacter Event
|
|
TriggerEvent("um-multicharacter:client:chooseChar")
|
|
|
|
-- Methode 2: Alternative Events für um-multicharacter
|
|
Wait(100)
|
|
TriggerEvent("um-multicharacter:client:openUI")
|
|
|
|
-- Methode 3: Spieler vom Server trennen (ohne Kick)
|
|
Wait(100)
|
|
TriggerServerEvent("QBCore:Server:OnPlayerUnload")
|
|
|
|
-- Methode 4: Direkte Weiterleitung zum Multicharacter-Menü über Server
|
|
Wait(100)
|
|
TriggerServerEvent("qb-relogsave:server:redirectToMultichar")
|
|
end, false)
|
|
|
|
-- Empfängt die gespeicherte Position vom Server
|
|
RegisterNetEvent("qb-relogsave:client:restoreLocation", function(pos, heading)
|
|
if not pos or not pos.x or not pos.y or not pos.z then return end
|
|
|
|
savedLocation = {
|
|
pos = pos,
|
|
heading = heading
|
|
}
|
|
end)
|
|
|
|
-- Setzt die Position nach dem Spawn (QBCore Standard)
|
|
RegisterNetEvent("QBCore:Client:OnPlayerLoaded", function()
|
|
Wait(1000) -- Warte kurz, bis alles geladen ist
|
|
RestorePosition()
|
|
end)
|
|
|
|
-- Fallback für um-multicharacter
|
|
RegisterNetEvent("um-multicharacter:client:spawned", function()
|
|
Wait(1000)
|
|
RestorePosition()
|
|
end)
|
|
|
|
-- Alternative Events für um-multicharacter
|
|
RegisterNetEvent("um-multicharacter:client:playerSpawned", function()
|
|
Wait(1000)
|
|
RestorePosition()
|
|
end)
|
|
|
|
-- Funktion zum Wiederherstellen der Position
|
|
function RestorePosition()
|
|
if savedLocation then
|
|
-- Verzögerung für sicheres Teleportieren
|
|
Wait(500)
|
|
DoScreenFadeOut(500)
|
|
Wait(600)
|
|
|
|
-- Teleportiere den Spieler
|
|
SetEntityCoords(PlayerPedId(), savedLocation.pos.x, savedLocation.pos.y, savedLocation.pos.z)
|
|
SetEntityHeading(PlayerPedId(), savedLocation.heading)
|
|
|
|
Wait(500)
|
|
DoScreenFadeIn(500)
|
|
|
|
-- Löscht die gespeicherte Position
|
|
savedLocation = nil
|
|
|
|
QBCore.Functions.Notify("Position wiederhergestellt", "success")
|
|
end
|
|
end
|