1
0
Fork 0
forked from Simnation/Main

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
local playerData = QBCore.Functions.GetPlayerData()
-- Speicher Ort vor Relog
TriggerServerEvent("qb-relogsave:server:saveLocation", cid, {
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)
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)

View file

@ -1,34 +1,99 @@
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)
if not cid or not coords then return end
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
savedLocations[cid] = {
pos = coords,
heading = heading,
timestamp = os.time()
timestamp = os.time(),
playerName = playerName
}
print("Position für " .. cid .. " gespeichert: " .. json.encode(coords))
DebugPrint("Position für " .. playerName .. " (CID: " .. cid .. ") gespeichert: X=" ..
coords.x .. ", Y=" .. coords.y .. ", Z=" .. coords.z)
end)
AddEventHandler('QBCore:Server:PlayerLoaded', function(Player)
if not Player or not Player.PlayerData then return end
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
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
TriggerClientEvent("qb-relogsave:client:restoreLocation", Player.PlayerData.source, pos, heading)
print("Position für " .. cid .. " wiederhergestellt")
DebugPrint("Position wird wiederhergestellt: X=" .. pos.x .. ", Y=" .. pos.y .. ", Z=" .. pos.z)
TriggerClientEvent("qb-relogsave:client:restoreLocation", src, pos, heading)
else
print("Ungültige Position für " .. cid .. " gefunden")
DebugPrint("Ungültige Position für " .. cid)
end
savedLocations[cid] = nil
else
DebugPrint("Keine gespeicherte Position für " .. cid .. " gefunden")
end
end)
RegisterNetEvent('um-multicharacter:server:CharacterLoaded', 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
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')