forked from Simnation/Main
Update server.lua
This commit is contained in:
parent
957126dddf
commit
002d47a43f
1 changed files with 146 additions and 17 deletions
|
@ -14,11 +14,15 @@ RegisterNetEvent('tdm:createGame', function(gameName, fieldId, gameType, passwor
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if not Player then return end
|
if not Player then
|
||||||
|
debugPrint("Spielerstellung fehlgeschlagen - Spieler nicht gefunden: " .. src)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Prüfen ob Spielfeld bereits belegt
|
-- Prüfen ob Spielfeld bereits belegt
|
||||||
for gameId, gameData in pairs(activeGames) do
|
for gameId, gameData in pairs(activeGames) do
|
||||||
if gameData.fieldId == fieldId then
|
if gameData.fieldId == fieldId then
|
||||||
|
debugPrint("Spielerstellung abgelehnt - Feld bereits belegt: " .. fieldId)
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Dieses Spielfeld ist bereits belegt!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Dieses Spielfeld ist bereits belegt!', 'error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -50,11 +54,12 @@ RegisterNetEvent('tdm:createGame', function(gameName, fieldId, gameType, passwor
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Dein ' .. typeText .. ' Spiel "' .. gameName .. '" wurde erstellt!', 'success')
|
TriggerClientEvent('QBCore:Notify', src, 'Dein ' .. typeText .. ' Spiel "' .. gameName .. '" wurde erstellt!', 'success')
|
||||||
|
|
||||||
updateGamesListForAll()
|
updateGamesListForAll()
|
||||||
debugPrint("Spiel erstellt: " .. gameId .. " von " .. Player.PlayerData.name)
|
debugPrint("Spiel erstellt: " .. gameId .. " von " .. Player.PlayerData.name .. " (Feld: " .. fieldId .. ")")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('tdm:requestGamesList', function()
|
RegisterNetEvent('tdm:requestGamesList', function()
|
||||||
local src = source
|
local src = source
|
||||||
|
debugPrint("Spiele-Liste angefordert von: " .. src)
|
||||||
TriggerClientEvent('tdm:updateGamesList', src, activeGames)
|
TriggerClientEvent('tdm:updateGamesList', src, activeGames)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -62,13 +67,19 @@ RegisterNetEvent('tdm:requestJoinGame', function(gameId, password)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if not Player or not activeGames[gameId] then return end
|
if not Player or not activeGames[gameId] then
|
||||||
|
debugPrint("Spielbeitritt fehlgeschlagen - Spieler oder Spiel nicht gefunden: " .. src .. ", " .. gameId)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local game = activeGames[gameId]
|
local game = activeGames[gameId]
|
||||||
local playerName = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
|
local playerName = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
|
||||||
|
|
||||||
|
debugPrint("Beitrittsanfrage von " .. playerName .. " (ID: " .. src .. ") für Spiel " .. gameId)
|
||||||
|
|
||||||
-- Passwort prüfen falls vorhanden
|
-- Passwort prüfen falls vorhanden
|
||||||
if game.hasPassword and game.password ~= password then
|
if game.hasPassword and game.password ~= password then
|
||||||
|
debugPrint("Beitritt abgelehnt - Falsches Passwort")
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Falsches Passwort!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Falsches Passwort!', 'error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -76,12 +87,14 @@ RegisterNetEvent('tdm:requestJoinGame', function(gameId, password)
|
||||||
-- Spieler bereits im Spiel?
|
-- Spieler bereits im Spiel?
|
||||||
for _, playerId in ipairs(game.team1) do
|
for _, playerId in ipairs(game.team1) do
|
||||||
if playerId == src then
|
if playerId == src then
|
||||||
|
debugPrint("Beitritt abgelehnt - Spieler bereits in Team 1")
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Du bist bereits in diesem Spiel!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Du bist bereits in diesem Spiel!', 'error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _, playerId in ipairs(game.team2) do
|
for _, playerId in ipairs(game.team2) do
|
||||||
if playerId == src then
|
if playerId == src then
|
||||||
|
debugPrint("Beitritt abgelehnt - Spieler bereits in Team 2")
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Du bist bereits in diesem Spiel!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Du bist bereits in diesem Spiel!', 'error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -92,6 +105,7 @@ RegisterNetEvent('tdm:requestJoinGame', function(gameId, password)
|
||||||
local maxPlayers = Config.gameFields[game.fieldId].maxPlayers
|
local maxPlayers = Config.gameFields[game.fieldId].maxPlayers
|
||||||
|
|
||||||
if currentPlayers >= maxPlayers then
|
if currentPlayers >= maxPlayers then
|
||||||
|
debugPrint("Beitritt abgelehnt - Spiel ist voll")
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Spiel ist voll!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Spiel ist voll!', 'error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -100,6 +114,7 @@ RegisterNetEvent('tdm:requestJoinGame', function(gameId, password)
|
||||||
if game.gameType == 'private' then
|
if game.gameType == 'private' then
|
||||||
local AdminPlayer = QBCore.Functions.GetPlayer(game.admin)
|
local AdminPlayer = QBCore.Functions.GetPlayer(game.admin)
|
||||||
if not AdminPlayer then
|
if not AdminPlayer then
|
||||||
|
debugPrint("Beitritt abgelehnt - Admin nicht online")
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Der Spiel-Admin ist nicht online!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Der Spiel-Admin ist nicht online!', 'error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -107,9 +122,11 @@ RegisterNetEvent('tdm:requestJoinGame', function(gameId, password)
|
||||||
|
|
||||||
-- Join Logic basierend auf Spiel Typ
|
-- Join Logic basierend auf Spiel Typ
|
||||||
if game.gameType == 'public' then
|
if game.gameType == 'public' then
|
||||||
|
debugPrint("Öffentliches Spiel - Direkter Beitritt")
|
||||||
joinPlayerToGame(src, gameId)
|
joinPlayerToGame(src, gameId)
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Du bist dem öffentlichen Spiel beigetreten!', 'success')
|
TriggerClientEvent('QBCore:Notify', src, 'Du bist dem öffentlichen Spiel beigetreten!', 'success')
|
||||||
else
|
else
|
||||||
|
debugPrint("Privates Spiel - Sende Anfrage an Admin")
|
||||||
TriggerClientEvent('tdm:joinRequest', game.admin, gameId, playerName, src)
|
TriggerClientEvent('tdm:joinRequest', game.admin, gameId, playerName, src)
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Join-Anfrage gesendet an ' .. game.adminName, 'info')
|
TriggerClientEvent('QBCore:Notify', src, 'Join-Anfrage gesendet an ' .. game.adminName, 'info')
|
||||||
end
|
end
|
||||||
|
@ -119,18 +136,24 @@ RegisterNetEvent('tdm:approveJoinRequest', function(gameId, playerId, approved)
|
||||||
local src = source
|
local src = source
|
||||||
local game = activeGames[gameId]
|
local game = activeGames[gameId]
|
||||||
|
|
||||||
if not game or game.admin ~= src then return end
|
if not game or game.admin ~= src then
|
||||||
|
debugPrint("Join-Anfrage Bearbeitung fehlgeschlagen - Ungültiges Spiel oder nicht Admin")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if approved then
|
if approved then
|
||||||
|
debugPrint("Join-Anfrage genehmigt für Spieler " .. playerId .. " in Spiel " .. gameId)
|
||||||
joinPlayerToGame(playerId, gameId)
|
joinPlayerToGame(playerId, gameId)
|
||||||
TriggerClientEvent('tdm:joinRequestResult', playerId, true, game.name)
|
TriggerClientEvent('tdm:joinRequestResult', playerId, true, game.name)
|
||||||
else
|
else
|
||||||
|
debugPrint("Join-Anfrage abgelehnt für Spieler " .. playerId .. " in Spiel " .. gameId)
|
||||||
TriggerClientEvent('tdm:joinRequestResult', playerId, false, game.name)
|
TriggerClientEvent('tdm:joinRequestResult', playerId, false, game.name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('tdm:leaveGame', function()
|
RegisterNetEvent('tdm:leaveGame', function()
|
||||||
local src = source
|
local src = source
|
||||||
|
debugPrint("Spieler " .. src .. " möchte alle Spiele verlassen")
|
||||||
|
|
||||||
for gameId, game in pairs(activeGames) do
|
for gameId, game in pairs(activeGames) do
|
||||||
removePlayerFromGame(src, gameId)
|
removePlayerFromGame(src, gameId)
|
||||||
|
@ -149,6 +172,8 @@ RegisterNetEvent('tdm:playerWasHit', function(gameId, victimTeam, attackerId)
|
||||||
|
|
||||||
local game = activeGames[gameId]
|
local game = activeGames[gameId]
|
||||||
|
|
||||||
|
debugPrint("Hit registriert - Opfer: " .. victim .. " (Team: " .. victimTeam .. "), Angreifer: " .. (attackerId or "Unbekannt"))
|
||||||
|
|
||||||
-- Spieler Stats initialisieren falls nicht vorhanden
|
-- Spieler Stats initialisieren falls nicht vorhanden
|
||||||
if not game.playerStats then
|
if not game.playerStats then
|
||||||
game.playerStats = {}
|
game.playerStats = {}
|
||||||
|
@ -168,16 +193,18 @@ RegisterNetEvent('tdm:playerWasHit', function(gameId, victimTeam, attackerId)
|
||||||
if attackerId then
|
if attackerId then
|
||||||
game.playerStats[attackerId].hits = (game.playerStats[attackerId].hits or 0) + 1
|
game.playerStats[attackerId].hits = (game.playerStats[attackerId].hits or 0) + 1
|
||||||
TriggerClientEvent('tdm:hitRegistered', attackerId)
|
TriggerClientEvent('tdm:hitRegistered', attackerId)
|
||||||
debugPrint("Treffer von " .. attackerId .. " gegen " .. victim)
|
debugPrint("Treffer von " .. attackerId .. " gegen " .. victim .. " registriert")
|
||||||
else
|
else
|
||||||
debugPrint("Treffer gegen " .. victim .. " von unbekanntem Angreifer")
|
debugPrint("Treffer gegen " .. victim .. " von unbekanntem Angreifer registriert")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Team Score erhöhen
|
-- Team Score erhöhen
|
||||||
if victimTeam == 'team1' then
|
if victimTeam == 'team1' then
|
||||||
game.score.team2 = game.score.team2 + 1
|
game.score.team2 = game.score.team2 + 1
|
||||||
|
debugPrint("Punkt für Team 2 - Neuer Score: " .. game.score.team2)
|
||||||
else
|
else
|
||||||
game.score.team1 = game.score.team1 + 1
|
game.score.team1 = game.score.team1 + 1
|
||||||
|
debugPrint("Punkt für Team 1 - Neuer Score: " .. game.score.team1)
|
||||||
end
|
end
|
||||||
|
|
||||||
TriggerClientEvent('tdm:deathRegistered', victim)
|
TriggerClientEvent('tdm:deathRegistered', victim)
|
||||||
|
@ -188,12 +215,14 @@ RegisterNetEvent('tdm:playerWasHit', function(gameId, victimTeam, attackerId)
|
||||||
-- Spiel beenden prüfen
|
-- Spiel beenden prüfen
|
||||||
if game.score.team1 >= game.maxHits or game.score.team2 >= game.maxHits then
|
if game.score.team1 >= game.maxHits or game.score.team2 >= game.maxHits then
|
||||||
local winnerTeam = game.score.team1 >= game.maxHits and 'team1' or 'team2'
|
local winnerTeam = game.score.team1 >= game.maxHits and 'team1' or 'team2'
|
||||||
|
debugPrint("Max Punkte erreicht - Beende Spiel. Gewinner: " .. winnerTeam)
|
||||||
endGame(gameId, winnerTeam)
|
endGame(gameId, winnerTeam)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('tdm:playerDied', function(gameId)
|
RegisterNetEvent('tdm:playerDied', function(gameId)
|
||||||
local src = source
|
local src = source
|
||||||
|
debugPrint("Spieler " .. src .. " ist gestorben in Spiel " .. gameId)
|
||||||
removePlayerFromGame(src, gameId)
|
removePlayerFromGame(src, gameId)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -201,7 +230,10 @@ RegisterNetEvent('tdm:requestScoreUpdate', function(gameId)
|
||||||
local src = source
|
local src = source
|
||||||
|
|
||||||
if activeGames[gameId] then
|
if activeGames[gameId] then
|
||||||
|
debugPrint("Score-Update angefordert von " .. src .. " für Spiel " .. gameId)
|
||||||
updateScoreForGame(gameId)
|
updateScoreForGame(gameId)
|
||||||
|
else
|
||||||
|
debugPrint("Score-Update fehlgeschlagen - Spiel " .. gameId .. " nicht gefunden")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -209,18 +241,21 @@ RegisterNetEvent('tdm:debugPlayerStats', function(gameId)
|
||||||
local src = source
|
local src = source
|
||||||
if activeGames[gameId] and activeGames[gameId].playerStats and activeGames[gameId].playerStats[src] then
|
if activeGames[gameId] and activeGames[gameId].playerStats and activeGames[gameId].playerStats[src] then
|
||||||
local stats = activeGames[gameId].playerStats[src]
|
local stats = activeGames[gameId].playerStats[src]
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Server Stats - Hits: ' .. (stats.hits or 0) .. ', Deaths: ' .. (stats.deaths or 0), 'info')
|
|
||||||
debugPrint("Stats für Spieler " .. src .. ": Hits=" .. (stats.hits or 0) .. ", Deaths=" .. (stats.deaths or 0))
|
debugPrint("Stats für Spieler " .. src .. ": Hits=" .. (stats.hits or 0) .. ", Deaths=" .. (stats.deaths or 0))
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, 'Server Stats - Hits: ' .. (stats.hits or 0) .. ', Deaths: ' .. (stats.deaths or 0), 'info')
|
||||||
else
|
else
|
||||||
|
debugPrint("Keine Stats gefunden für Spieler " .. src .. " in Spiel " .. gameId)
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Keine Stats gefunden!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Keine Stats gefunden!', 'error')
|
||||||
debugPrint("Keine Stats für Spieler " .. src .. " in Spiel " .. gameId)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Funktionen
|
-- Funktionen
|
||||||
function joinPlayerToGame(playerId, gameId)
|
function joinPlayerToGame(playerId, gameId)
|
||||||
local game = activeGames[gameId]
|
local game = activeGames[gameId]
|
||||||
if not game then return end
|
if not game then
|
||||||
|
debugPrint("Spielbeitritt fehlgeschlagen - Spiel nicht gefunden: " .. gameId)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Team mit weniger Spielern wählen
|
-- Team mit weniger Spielern wählen
|
||||||
local team = #game.team1 <= #game.team2 and 'team1' or 'team2'
|
local team = #game.team1 <= #game.team2 and 'team1' or 'team2'
|
||||||
|
@ -238,6 +273,7 @@ function joinPlayerToGame(playerId, gameId)
|
||||||
if #game.team1 + #game.team2 >= 2 and game.status == 'waiting' then
|
if #game.team1 + #game.team2 >= 2 and game.status == 'waiting' then
|
||||||
game.status = 'active'
|
game.status = 'active'
|
||||||
game.startTime = os.time()
|
game.startTime = os.time()
|
||||||
|
debugPrint("Spiel " .. gameId .. " gestartet - Mindestens 2 Spieler erreicht")
|
||||||
|
|
||||||
-- Game Timer starten
|
-- Game Timer starten
|
||||||
startGameTimer(gameId)
|
startGameTimer(gameId)
|
||||||
|
@ -255,24 +291,36 @@ function removePlayerFromGame(playerId, gameId)
|
||||||
if not game then return end
|
if not game then return end
|
||||||
|
|
||||||
-- Spieler aus Teams entfernen
|
-- Spieler aus Teams entfernen
|
||||||
|
local removed = false
|
||||||
|
|
||||||
for i, id in ipairs(game.team1) do
|
for i, id in ipairs(game.team1) do
|
||||||
if id == playerId then
|
if id == playerId then
|
||||||
table.remove(game.team1, i)
|
table.remove(game.team1, i)
|
||||||
debugPrint("Spieler " .. playerId .. " aus Team 1 entfernt")
|
debugPrint("Spieler " .. playerId .. " aus Team 1 entfernt")
|
||||||
|
removed = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not removed then
|
||||||
for i, id in ipairs(game.team2) do
|
for i, id in ipairs(game.team2) do
|
||||||
if id == playerId then
|
if id == playerId then
|
||||||
table.remove(game.team2, i)
|
table.remove(game.team2, i)
|
||||||
debugPrint("Spieler " .. playerId .. " aus Team 2 entfernt")
|
debugPrint("Spieler " .. playerId .. " aus Team 2 entfernt")
|
||||||
|
removed = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not removed then
|
||||||
|
debugPrint("Spieler " .. playerId .. " nicht in Spiel " .. gameId .. " gefunden")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Wenn Admin das Spiel verlässt, Spiel beenden
|
-- Wenn Admin das Spiel verlässt, Spiel beenden
|
||||||
if game.admin == playerId then
|
if game.admin == playerId then
|
||||||
|
debugPrint("Admin hat das Spiel verlassen - Beende Spiel " .. gameId)
|
||||||
endGame(gameId, nil, 'Admin hat das Spiel verlassen')
|
endGame(gameId, nil, 'Admin hat das Spiel verlassen')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -283,7 +331,10 @@ end
|
||||||
|
|
||||||
function endGame(gameId, winnerTeam, reason)
|
function endGame(gameId, winnerTeam, reason)
|
||||||
local game = activeGames[gameId]
|
local game = activeGames[gameId]
|
||||||
if not game then return end
|
if not game then
|
||||||
|
debugPrint("Spielende fehlgeschlagen - Spiel nicht gefunden: " .. gameId)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
game.status = 'finished'
|
game.status = 'finished'
|
||||||
|
|
||||||
|
@ -297,6 +348,7 @@ function endGame(gameId, winnerTeam, reason)
|
||||||
|
|
||||||
-- Game End Event an alle Spieler
|
-- Game End Event an alle Spieler
|
||||||
for _, playerId in ipairs(allPlayers) do
|
for _, playerId in ipairs(allPlayers) do
|
||||||
|
debugPrint("Sende Spielende-Event an Spieler " .. playerId)
|
||||||
TriggerClientEvent('tdm:gameEnded', playerId, winnerTeam, game.score.team1, game.score.team2)
|
TriggerClientEvent('tdm:gameEnded', playerId, winnerTeam, game.score.team1, game.score.team2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -304,6 +356,7 @@ function endGame(gameId, winnerTeam, reason)
|
||||||
SetTimeout(10000, function()
|
SetTimeout(10000, function()
|
||||||
activeGames[gameId] = nil
|
activeGames[gameId] = nil
|
||||||
updateGamesListForAll()
|
updateGamesListForAll()
|
||||||
|
debugPrint("Spiel " .. gameId .. " aus der Liste entfernt")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if reason then
|
if reason then
|
||||||
|
@ -337,6 +390,7 @@ function startGameTimer(gameId)
|
||||||
if game and game.status == 'active' then
|
if game and game.status == 'active' then
|
||||||
local winnerTeam = game.score.team1 > game.score.team2 and 'team1' or
|
local winnerTeam = game.score.team1 > game.score.team2 and 'team1' or
|
||||||
game.score.team2 > game.score.team1 and 'team2' or nil
|
game.score.team2 > game.score.team1 and 'team2' or nil
|
||||||
|
debugPrint("Spielzeit abgelaufen - Beende Spiel " .. gameId)
|
||||||
endGame(gameId, winnerTeam, 'Zeit abgelaufen')
|
endGame(gameId, winnerTeam, 'Zeit abgelaufen')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -349,6 +403,7 @@ function checkGameEnd(gameId)
|
||||||
local totalPlayers = #game.team1 + #game.team2
|
local totalPlayers = #game.team1 + #game.team2
|
||||||
|
|
||||||
if totalPlayers < 2 and game.status == 'active' then
|
if totalPlayers < 2 and game.status == 'active' then
|
||||||
|
debugPrint("Zu wenig Spieler - Beende Spiel " .. gameId)
|
||||||
endGame(gameId, nil, 'Zu wenig Spieler')
|
endGame(gameId, nil, 'Zu wenig Spieler')
|
||||||
elseif totalPlayers == 0 then
|
elseif totalPlayers == 0 then
|
||||||
activeGames[gameId] = nil
|
activeGames[gameId] = nil
|
||||||
|
@ -359,16 +414,23 @@ end
|
||||||
|
|
||||||
function updateScoreForGame(gameId)
|
function updateScoreForGame(gameId)
|
||||||
local game = activeGames[gameId]
|
local game = activeGames[gameId]
|
||||||
if not game then return end
|
if not game then
|
||||||
|
debugPrint("Score-Update fehlgeschlagen - Spiel nicht gefunden: " .. gameId)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
debugPrint("Score Update für Spiel " .. gameId .. ": Team1=" .. game.score.team1 .. ", Team2=" .. game.score.team2)
|
debugPrint("Score Update für Spiel " .. gameId .. ": Team1=" .. game.score.team1 .. ", Team2=" .. game.score.team2)
|
||||||
|
|
||||||
|
for _, playerId in ipairs(game.team1) do
|
||||||
|
local playerStats = game.playerStats[playerId] or {hits = 0, deaths = 0}
|
||||||
|
TriggerClientEvent('tdm:updateScore', playerId, game.score.team1,
|
||||||
for _, playerId in ipairs(game.team1) do
|
for _, playerId in ipairs(game.team1) do
|
||||||
local playerStats = game.playerStats[playerId] or {hits = 0, deaths = 0}
|
local playerStats = game.playerStats[playerId] or {hits = 0, deaths = 0}
|
||||||
TriggerClientEvent('tdm:updateScore', playerId, game.score.team1, game.score.team2, {
|
TriggerClientEvent('tdm:updateScore', playerId, game.score.team1, game.score.team2, {
|
||||||
hits = playerStats.hits or 0,
|
hits = playerStats.hits or 0,
|
||||||
deaths = playerStats.deaths or 0
|
deaths = playerStats.deaths or 0
|
||||||
})
|
})
|
||||||
|
debugPrint("Score-Update an Team 1 Spieler " .. playerId .. " gesendet")
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, playerId in ipairs(game.team2) do
|
for _, playerId in ipairs(game.team2) do
|
||||||
|
@ -377,11 +439,14 @@ function updateScoreForGame(gameId)
|
||||||
hits = playerStats.hits or 0,
|
hits = playerStats.hits or 0,
|
||||||
deaths = playerStats.deaths or 0
|
deaths = playerStats.deaths or 0
|
||||||
})
|
})
|
||||||
|
debugPrint("Score-Update an Team 2 Spieler " .. playerId .. " gesendet")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateGamesListForAll()
|
function updateGamesListForAll()
|
||||||
local players = QBCore.Functions.GetPlayers()
|
local players = QBCore.Functions.GetPlayers()
|
||||||
|
debugPrint("Aktualisiere Spieleliste für alle Spieler - Aktive Spiele: " .. #activeGames)
|
||||||
|
|
||||||
for _, playerId in pairs(players) do
|
for _, playerId in pairs(players) do
|
||||||
TriggerClientEvent('tdm:updateGamesList', playerId, activeGames)
|
TriggerClientEvent('tdm:updateGamesList', playerId, activeGames)
|
||||||
end
|
end
|
||||||
|
@ -403,7 +468,7 @@ AddEventHandler('onResourceStart', function(resourceName)
|
||||||
if GetCurrentResourceName() == resourceName then
|
if GetCurrentResourceName() == resourceName then
|
||||||
activeGames = {}
|
activeGames = {}
|
||||||
gameIdCounter = 1
|
gameIdCounter = 1
|
||||||
debugPrint("TeamDeathmatch System gestartet!")
|
debugPrint("TeamDeathmatch System gestartet! Version 1.0.1")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -420,6 +485,7 @@ AddEventHandler('onResourceStop', function(resourceName)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, playerId in ipairs(allPlayers) do
|
for _, playerId in ipairs(allPlayers) do
|
||||||
|
debugPrint("Resource wird gestoppt - Entferne Spieler " .. playerId .. " aus Spiel " .. gameId)
|
||||||
TriggerClientEvent('tdm:leaveGame', playerId)
|
TriggerClientEvent('tdm:leaveGame', playerId)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -428,3 +494,66 @@ AddEventHandler('onResourceStop', function(resourceName)
|
||||||
debugPrint("TeamDeathmatch System gestoppt!")
|
debugPrint("TeamDeathmatch System gestoppt!")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Neuer Debug-Command für Server
|
||||||
|
RegisterCommand('tdmserverdebug', function(source, args)
|
||||||
|
local src = source
|
||||||
|
if src > 0 then -- Spieler
|
||||||
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
if not Player or not Player.PlayerData.job or Player.PlayerData.job.name ~= 'admin' then
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, 'Du hast keine Berechtigung!', 'error')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
debugPrint("=== TDM SERVER DEBUG ===")
|
||||||
|
debugPrint("Aktive Spiele: " .. #activeGames)
|
||||||
|
|
||||||
|
for gameId, game in pairs(activeGames) do
|
||||||
|
debugPrint("Spiel: " .. gameId .. " - " .. game.name)
|
||||||
|
debugPrint(" Status: " .. game.status)
|
||||||
|
debugPrint(" Feld: " .. game.fieldId)
|
||||||
|
debugPrint(" Team 1: " .. #game.team1 .. " Spieler, Score: " .. game.score.team1)
|
||||||
|
debugPrint(" Team 2: " .. #game.team2 .. " Spieler, Score: " .. game.score.team2)
|
||||||
|
|
||||||
|
if src > 0 then
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, 'Debug-Info in Server-Konsole', 'info')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end, true)
|
||||||
|
|
||||||
|
-- Neuer Command zum Zurücksetzen aller Spiele (nur für Admins)
|
||||||
|
RegisterCommand('tdmreset', function(source, args)
|
||||||
|
local src = source
|
||||||
|
if src > 0 then -- Spieler
|
||||||
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
if not Player or not Player.PlayerData.job or Player.PlayerData.job.name ~= 'admin' then
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, 'Du hast keine Berechtigung!', 'error')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Alle Spieler aus TDM entfernen
|
||||||
|
for gameId, game in pairs(activeGames) do
|
||||||
|
local allPlayers = {}
|
||||||
|
for _, playerId in ipairs(game.team1) do
|
||||||
|
table.insert(allPlayers, playerId)
|
||||||
|
end
|
||||||
|
for _, playerId in ipairs(game.team2) do
|
||||||
|
table.insert(allPlayers, playerId)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, playerId in ipairs(allPlayers) do
|
||||||
|
TriggerClientEvent('tdm:leaveGame', playerId)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
activeGames = {}
|
||||||
|
gameIdCounter = 1
|
||||||
|
|
||||||
|
debugPrint("TeamDeathmatch System zurückgesetzt!")
|
||||||
|
|
||||||
|
if src > 0 then
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, 'TDM System zurückgesetzt!', 'success')
|
||||||
|
end
|
||||||
|
end, true)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue