fix relog
This commit is contained in:
parent
c30708c702
commit
46c69947b3
3 changed files with 38 additions and 142 deletions
|
@ -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)")
|
||||
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
|
||||
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')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue