1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-26 23:28:00 +02:00
parent 761af3afdf
commit bc2a683f6f
2 changed files with 121 additions and 167 deletions

View file

@ -24,13 +24,11 @@ end
-- Events -- Events
RegisterNetEvent('tdm:updateGamesList', function(games) RegisterNetEvent('tdm:updateGamesList', function(games)
debugPrint("Spiele-Liste aktualisiert - Anzahl: " .. (games and #games or "0"))
activeGames = games activeGames = games
debugPrint("Spieleliste aktualisiert: " .. (games and table.count(games) or 0) .. " aktive Spiele")
end) end)
RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId) RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId)
debugPrint("Join Game Event empfangen: GameID=" .. gameId .. ", Team=" .. team .. ", FieldID=" .. fieldId)
currentGameId = gameId currentGameId = gameId
currentTeam = team currentTeam = team
currentField = fieldId currentField = fieldId
@ -43,21 +41,11 @@ RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId)
playerStats.gamesPlayed = playerStats.gamesPlayed + 1 playerStats.gamesPlayed = playerStats.gamesPlayed + 1
local fieldConfig = Config.gameFields[fieldId] local fieldConfig = Config.gameFields[fieldId]
if not fieldConfig then
debugPrint("FEHLER: Feldkonfiguration nicht gefunden für ID " .. fieldId)
return
end
-- Teleport zu Team Spawn -- Teleport zu Team Spawn
local spawnPoints = fieldConfig.teamSpawns[team] local spawnPoints = fieldConfig.teamSpawns[team]
if not spawnPoints or #spawnPoints == 0 then
debugPrint("FEHLER: Keine Spawn-Punkte für Team " .. team)
return
end
local randomSpawn = spawnPoints[math.random(#spawnPoints)] local randomSpawn = spawnPoints[math.random(#spawnPoints)]
debugPrint("Teleportiere zu: " .. randomSpawn.x .. ", " .. randomSpawn.y .. ", " .. randomSpawn.z)
SetEntityCoords(PlayerPedId(), randomSpawn.x, randomSpawn.y, randomSpawn.z) SetEntityCoords(PlayerPedId(), randomSpawn.x, randomSpawn.y, randomSpawn.z)
-- Team Maske setzen -- Team Maske setzen
@ -76,8 +64,6 @@ RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId)
end) end)
RegisterNetEvent('tdm:leaveGame', function() RegisterNetEvent('tdm:leaveGame', function()
debugPrint("Leave Game Event empfangen")
inTDM = false inTDM = false
local previousField = currentField local previousField = currentField
currentTeam = nil currentTeam = nil
@ -91,18 +77,14 @@ RegisterNetEvent('tdm:leaveGame', function()
-- Versuche zuerst die vorherige Feld-Lobby -- Versuche zuerst die vorherige Feld-Lobby
if previousField and Config.gameFields[previousField] and Config.gameFields[previousField].lobby then if previousField and Config.gameFields[previousField] and Config.gameFields[previousField].lobby then
lobbyPos = Config.gameFields[previousField].lobby.pos lobbyPos = Config.gameFields[previousField].lobby.pos
debugPrint("Verwende vorherige Feld-Lobby für Teleport")
-- Dann die aktuelle Lobby-Feld -- Dann die aktuelle Lobby-Feld
elseif currentLobbyField and Config.gameFields[currentLobbyField] and Config.gameFields[currentLobbyField].lobby then elseif currentLobbyField and Config.gameFields[currentLobbyField] and Config.gameFields[currentLobbyField].lobby then
lobbyPos = Config.gameFields[currentLobbyField].lobby.pos lobbyPos = Config.gameFields[currentLobbyField].lobby.pos
debugPrint("Verwende aktuelle Lobby-Feld für Teleport")
-- Fallback zur ersten verfügbaren Lobby -- Fallback zur ersten verfügbaren Lobby
else else
debugPrint("Suche nach verfügbarer Lobby für Teleport")
for fieldId, fieldData in pairs(Config.gameFields) do for fieldId, fieldData in pairs(Config.gameFields) do
if fieldData.lobby and fieldData.lobby.pos then if fieldData.lobby and fieldData.lobby.pos then
lobbyPos = fieldData.lobby.pos lobbyPos = fieldData.lobby.pos
debugPrint("Fallback-Lobby gefunden: " .. fieldId)
break break
end end
end end
@ -110,17 +92,15 @@ RegisterNetEvent('tdm:leaveGame', function()
-- Teleport zur Lobby (mit Fallback-Position) -- Teleport zur Lobby (mit Fallback-Position)
if lobbyPos then if lobbyPos then
debugPrint("Teleportiere zur Lobby: " .. lobbyPos.x .. ", " .. lobbyPos.y .. ", " .. lobbyPos.z)
SetEntityCoords(PlayerPedId(), lobbyPos.x, lobbyPos.y, lobbyPos.z) SetEntityCoords(PlayerPedId(), lobbyPos.x, lobbyPos.y, lobbyPos.z)
else else
-- Notfall-Fallback Position -- Notfall-Fallback Position (anpassen an deine Map)
debugPrint("WARNUNG: Keine Lobby gefunden, verwende Fallback-Position")
SetEntityCoords(PlayerPedId(), -1042.4, -2745.8, 21.4) SetEntityCoords(PlayerPedId(), -1042.4, -2745.8, 21.4)
debugPrint("WARNUNG: Keine Lobby gefunden, Fallback-Position verwendet!")
end end
-- Maske entfernen -- Maske entfernen
SetPedComponentVariation(PlayerPedId(), 1, 0, 0, 0) SetPedComponentVariation(PlayerPedId(), 1, 0, 0, 0)
debugPrint("Maske entfernt")
-- Zone Blips entfernen -- Zone Blips entfernen
removeTeamZoneBlips() removeTeamZoneBlips()
@ -133,12 +113,10 @@ RegisterNetEvent('tdm:leaveGame', function()
type = 'error' type = 'error'
}) })
debugPrint("Spiel verlassen - Cleanup abgeschlossen") debugPrint("Spiel verlassen")
end) end)
RegisterNetEvent('tdm:joinRequest', function(gameId, playerName, playerId) RegisterNetEvent('tdm:joinRequest', function(gameId, playerName, playerId)
debugPrint("Join-Anfrage erhalten von: " .. playerName .. " (ID: " .. playerId .. ") für Spiel " .. gameId)
local alert = lib.alertDialog({ local alert = lib.alertDialog({
header = 'Join Anfrage', header = 'Join Anfrage',
content = playerName .. ' möchte deinem Spiel beitreten.\n\nErlauben?', content = playerName .. ' möchte deinem Spiel beitreten.\n\nErlauben?',
@ -151,24 +129,20 @@ RegisterNetEvent('tdm:joinRequest', function(gameId, playerName, playerId)
}) })
if alert == 'confirm' then if alert == 'confirm' then
debugPrint("Join-Anfrage von " .. playerName .. " akzeptiert")
TriggerServerEvent('tdm:approveJoinRequest', gameId, playerId, true) TriggerServerEvent('tdm:approveJoinRequest', gameId, playerId, true)
else else
debugPrint("Join-Anfrage von " .. playerName .. " abgelehnt")
TriggerServerEvent('tdm:approveJoinRequest', gameId, playerId, false) TriggerServerEvent('tdm:approveJoinRequest', gameId, playerId, false)
end end
end) end)
RegisterNetEvent('tdm:joinRequestResult', function(approved, gameName) RegisterNetEvent('tdm:joinRequestResult', function(approved, gameName)
if approved then if approved then
debugPrint("Join-Anfrage für Spiel '" .. gameName .. "' wurde akzeptiert")
lib.notify({ lib.notify({
title = 'TeamDeathmatch', title = 'TeamDeathmatch',
description = 'Deine Anfrage wurde angenommen!', description = 'Deine Anfrage wurde angenommen!',
type = 'success' type = 'success'
}) })
else else
debugPrint("Join-Anfrage für Spiel '" .. gameName .. "' wurde abgelehnt")
lib.notify({ lib.notify({
title = 'TeamDeathmatch', title = 'TeamDeathmatch',
description = 'Deine Anfrage für "' .. gameName .. '" wurde abgelehnt!', description = 'Deine Anfrage für "' .. gameName .. '" wurde abgelehnt!',
@ -255,6 +229,7 @@ RegisterNetEvent('tdm:playerHit', function()
end) end)
RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score, gameStats) RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score, gameStats)
-- Debug-Ausgabe
debugPrint("Score Update empfangen: Team1=" .. team1Score .. ", Team2=" .. team2Score) debugPrint("Score Update empfangen: Team1=" .. team1Score .. ", Team2=" .. team2Score)
if gameStats then if gameStats then
debugPrint("GameStats: Hits=" .. (gameStats.hits or "nil") .. ", Deaths=" .. (gameStats.deaths or "nil")) debugPrint("GameStats: Hits=" .. (gameStats.hits or "nil") .. ", Deaths=" .. (gameStats.deaths or "nil"))
@ -279,7 +254,6 @@ RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score, gameStats)
end) end)
RegisterNetEvent('tdm:hitRegistered', function() RegisterNetEvent('tdm:hitRegistered', function()
debugPrint("Treffer registriert! Aktualisiere lokale Stats")
playerStats.hits = playerStats.hits + 1 playerStats.hits = playerStats.hits + 1
lib.notify({ lib.notify({
@ -296,7 +270,6 @@ RegisterNetEvent('tdm:hitRegistered', function()
-- Score sofort aktualisieren -- Score sofort aktualisieren
if currentGameId then if currentGameId then
debugPrint("Fordere Score-Update an für Spiel " .. currentGameId)
TriggerServerEvent('tdm:requestScoreUpdate', currentGameId) TriggerServerEvent('tdm:requestScoreUpdate', currentGameId)
end end
@ -304,12 +277,10 @@ RegisterNetEvent('tdm:hitRegistered', function()
end) end)
RegisterNetEvent('tdm:deathRegistered', function() RegisterNetEvent('tdm:deathRegistered', function()
debugPrint("Tod registriert! Aktualisiere lokale Stats")
playerStats.deaths = playerStats.deaths + 1 playerStats.deaths = playerStats.deaths + 1
-- Score sofort aktualisieren -- Score sofort aktualisieren
if currentGameId then if currentGameId then
debugPrint("Fordere Score-Update an für Spiel " .. currentGameId)
TriggerServerEvent('tdm:requestScoreUpdate', currentGameId) TriggerServerEvent('tdm:requestScoreUpdate', currentGameId)
end end
@ -317,7 +288,6 @@ RegisterNetEvent('tdm:deathRegistered', function()
end) end)
RegisterNetEvent('tdm:gameEnded', function(winnerTeam, team1Score, team2Score) RegisterNetEvent('tdm:gameEnded', function(winnerTeam, team1Score, team2Score)
debugPrint("Spiel beendet! Gewinner: " .. (winnerTeam or "Unentschieden"))
lib.hideTextUI() lib.hideTextUI()
local wonGame = (currentTeam == 'team1' and winnerTeam == 'team1') or (currentTeam == 'team2' and winnerTeam == 'team2') local wonGame = (currentTeam == 'team1' and winnerTeam == 'team1') or (currentTeam == 'team2' and winnerTeam == 'team2')
@ -348,8 +318,9 @@ RegisterNetEvent('tdm:gameEnded', function(winnerTeam, team1Score, team2Score)
}) })
Wait(5000) Wait(5000)
debugPrint("Verlasse Spiel nach Ende")
TriggerServerEvent('tdm:leaveGame') TriggerServerEvent('tdm:leaveGame')
debugPrint("Spiel beendet! Gewinner: " .. (winnerTeam or "Unentschieden"))
end) end)
-- Funktionen -- Funktionen
@ -425,14 +396,12 @@ function showHitMarker()
SetTextCentre(true) SetTextCentre(true)
DrawText(0.5, 0.45) DrawText(0.5, 0.45)
end end
debugPrint("Hit-Marker ausgeblendet")
end) end)
end end
function openMainMenu(fieldId) function openMainMenu(fieldId)
-- Sicherheitscheck -- Sicherheitscheck
if not fieldId or not Config.gameFields[fieldId] then if not fieldId or not Config.gameFields[fieldId] then
debugPrint("FEHLER: Ungültiges Spielfeld für Menü: " .. tostring(fieldId))
lib.notify({ lib.notify({
title = 'Fehler', title = 'Fehler',
description = 'Ungültiges Spielfeld!', description = 'Ungültiges Spielfeld!',
@ -441,7 +410,6 @@ function openMainMenu(fieldId)
return return
end end
debugPrint("Öffne Hauptmenü für Feld: " .. fieldId)
currentLobbyField = fieldId currentLobbyField = fieldId
TriggerServerEvent('tdm:requestGamesList') TriggerServerEvent('tdm:requestGamesList')
@ -455,7 +423,6 @@ function openMainMenu(fieldId)
description = 'Erstelle ein neues Spiel für ' .. fieldName, description = 'Erstelle ein neues Spiel für ' .. fieldName,
icon = 'plus', icon = 'plus',
onSelect = function() onSelect = function()
debugPrint("Öffne Menü zum Erstellen eines neuen Spiels")
openCreateGameMenu(fieldId) openCreateGameMenu(fieldId)
end end
}, },
@ -464,7 +431,6 @@ function openMainMenu(fieldId)
description = 'Trete einem laufenden Spiel bei', description = 'Trete einem laufenden Spiel bei',
icon = 'users', icon = 'users',
onSelect = function() onSelect = function()
debugPrint("Öffne Menü zum Beitreten eines Spiels")
openJoinGameMenu(fieldId) openJoinGameMenu(fieldId)
end end
} }
@ -477,7 +443,6 @@ function openMainMenu(fieldId)
icon = 'door-open', icon = 'door-open',
iconColor = 'red', iconColor = 'red',
onSelect = function() onSelect = function()
debugPrint("Verlasse aktuelles Spiel über Menü")
TriggerServerEvent('tdm:leaveGame') TriggerServerEvent('tdm:leaveGame')
end end
}) })
@ -494,7 +459,6 @@ end
function openCreateGameMenu(fieldId) function openCreateGameMenu(fieldId)
if not fieldId or not Config.gameFields[fieldId] then if not fieldId or not Config.gameFields[fieldId] then
debugPrint("FEHLER: Ungültiges Spielfeld für Erstellungsmenü: " .. tostring(fieldId))
lib.notify({ lib.notify({
title = 'Fehler', title = 'Fehler',
description = 'Ungültiges Spielfeld!', description = 'Ungültiges Spielfeld!',
@ -503,7 +467,6 @@ function openCreateGameMenu(fieldId)
return return
end end
debugPrint("Öffne Spiel-Erstellungsmenü für Feld: " .. fieldId)
local fieldData = Config.gameFields[fieldId] local fieldData = Config.gameFields[fieldId]
local input = lib.inputDialog('Neues Spiel erstellen - ' .. fieldData.name, { local input = lib.inputDialog('Neues Spiel erstellen - ' .. fieldData.name, {
@ -532,24 +495,19 @@ function openCreateGameMenu(fieldId)
} }
}) })
if not input then if not input then return end
debugPrint("Spiel-Erstellung abgebrochen")
return
end
local gameName = input[1] local gameName = input[1]
local gameType = input[2] local gameType = input[2]
local password = input[3] and input[3] ~= '' and input[3] or nil local password = input[3] and input[3] ~= '' and input[3] or nil
if gameName and gameType then if gameName and gameType then
debugPrint("Erstelle Spiel: " .. gameName .. " (Typ: " .. gameType .. ", Passwort: " .. (password and "Ja" or "Nein") .. ")")
TriggerServerEvent('tdm:createGame', gameName, fieldId, gameType, password) TriggerServerEvent('tdm:createGame', gameName, fieldId, gameType, password)
end end
end end
function openJoinGameMenu(fieldId) function openJoinGameMenu(fieldId)
if not fieldId or not Config.gameFields[fieldId] then if not fieldId or not Config.gameFields[fieldId] then
debugPrint("FEHLER: Ungültiges Spielfeld für Join-Menü: " .. tostring(fieldId))
lib.notify({ lib.notify({
title = 'Fehler', title = 'Fehler',
description = 'Ungültiges Spielfeld!', description = 'Ungültiges Spielfeld!',
@ -558,7 +516,6 @@ function openJoinGameMenu(fieldId)
return return
end end
debugPrint("Öffne Spiel-Beitrittsmenü für Feld: " .. fieldId)
TriggerServerEvent('tdm:requestGamesList') TriggerServerEvent('tdm:requestGamesList')
Wait(200) Wait(200)
@ -567,10 +524,8 @@ function openJoinGameMenu(fieldId)
local fieldName = Config.gameFields[fieldId].name local fieldName = Config.gameFields[fieldId].name
-- Nur Spiele für dieses Feld anzeigen -- Nur Spiele für dieses Feld anzeigen
local gamesCount = 0
for gameId, gameData in pairs(activeGames) do for gameId, gameData in pairs(activeGames) do
if gameData.fieldId == fieldId then if gameData.fieldId == fieldId then
gamesCount = gamesCount + 1
local playerCount = #gameData.team1 + #gameData.team2 local playerCount = #gameData.team1 + #gameData.team2
local maxPlayers = Config.gameFields[gameData.fieldId].maxPlayers local maxPlayers = Config.gameFields[gameData.fieldId].maxPlayers
@ -589,9 +544,7 @@ function openJoinGameMenu(fieldId)
gameType = gameData.gameType gameType = gameData.gameType
}, },
onSelect = function(args) onSelect = function(args)
debugPrint("Versuche Spiel beizutreten: " .. gameId)
if args.hasPassword then if args.hasPassword then
debugPrint("Spiel erfordert Passwort")
local input = lib.inputDialog('Passwort eingeben', { local input = lib.inputDialog('Passwort eingeben', {
{ {
type = 'input', type = 'input',
@ -603,13 +556,9 @@ function openJoinGameMenu(fieldId)
}) })
if input and input[1] then if input and input[1] then
debugPrint("Passwort eingegeben, sende Beitrittsanfrage")
TriggerServerEvent('tdm:requestJoinGame', args.gameId, input[1]) TriggerServerEvent('tdm:requestJoinGame', args.gameId, input[1])
else
debugPrint("Passwort-Eingabe abgebrochen")
end end
else else
debugPrint("Kein Passwort erforderlich, sende Beitrittsanfrage")
TriggerServerEvent('tdm:requestJoinGame', args.gameId) TriggerServerEvent('tdm:requestJoinGame', args.gameId)
end end
end end
@ -617,8 +566,6 @@ function openJoinGameMenu(fieldId)
end end
end end
debugPrint("Gefundene Spiele für Feld " .. fieldId .. ": " .. gamesCount)
if #options == 0 then if #options == 0 then
table.insert(options, { table.insert(options, {
title = 'Keine Spiele verfügbar', title = 'Keine Spiele verfügbar',
@ -674,12 +621,13 @@ CreateThread(function()
end end
end) end)
-- Verbesserte Damage Handler -- Verbesserte Damage Handler für korrekte Treffer-Registrierung
CreateThread(function() CreateThread(function()
while true do while true do
if inTDM and not isHit then if inTDM and not isHit then
local ped = PlayerPedId() local ped = PlayerPedId()
-- Prüfe, ob der Spieler Schaden genommen hat
if HasEntityBeenDamagedByAnyPed(ped) then if HasEntityBeenDamagedByAnyPed(ped) then
debugPrint("Schaden erkannt - Identifiziere Angreifer") debugPrint("Schaden erkannt - Identifiziere Angreifer")
@ -707,6 +655,7 @@ CreateThread(function()
debugPrint("Getroffen von: " .. (damagerPlayer or "Unbekannt")) debugPrint("Getroffen von: " .. (damagerPlayer or "Unbekannt"))
-- Treffer-Events auslösen
TriggerEvent('tdm:playerHit') TriggerEvent('tdm:playerHit')
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, damagerPlayer) TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, damagerPlayer)
@ -720,6 +669,42 @@ CreateThread(function()
end end
end) end)
-- Zusätzlicher Event-Handler für zuverlässigere Treffer-Erkennung
AddEventHandler('gameEventTriggered', function(name, args)
if name == "CEventNetworkEntityDamage" then
local victimId = args[1]
local attackerId = args[2]
local isDead = args[4] == 1
local weaponHash = args[5]
if inTDM and not isHit and victimId == PlayerPedId() then
local attackerServerId = nil
-- Versuche den Angreifer zu identifizieren
for _, player in ipairs(GetActivePlayers()) do
if GetPlayerPed(player) == attackerId then
attackerServerId = GetPlayerServerId(player)
break
end
end
debugPrint("Schaden-Event erkannt: Angreifer=" .. (attackerServerId or "NPC/Unbekannt") .. ", Waffe=" .. weaponHash)
if attackerServerId then
-- Lokale Stats sofort updaten
playerStats.deaths = playerStats.deaths + 1
-- Verhindern, dass der Spieler stirbt
SetEntityHealth(PlayerPedId(), GetEntityMaxHealth(PlayerPedId()))
-- Treffer-Events auslösen
TriggerEvent('tdm:playerHit')
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, attackerServerId)
end
end
end
end)
-- Death Handler -- Death Handler
CreateThread(function() CreateThread(function()
while true do while true do
@ -754,8 +739,6 @@ CreateThread(function()
local lobbyPos = fieldData.lobby.pos local lobbyPos = fieldData.lobby.pos
local npcData = fieldData.lobby.npc local npcData = fieldData.lobby.npc
debugPrint("Erstelle Blip und NPC für Feld " .. fieldId)
-- Blip erstellen -- Blip erstellen
local blip = AddBlipForCoord(lobbyPos.x, lobbyPos.y, lobbyPos.z) local blip = AddBlipForCoord(lobbyPos.x, lobbyPos.y, lobbyPos.z)
SetBlipSprite(blip, 432) SetBlipSprite(blip, 432)
@ -769,17 +752,12 @@ CreateThread(function()
tdmBlips[fieldId] = blip tdmBlips[fieldId] = blip
-- NPC erstellen
RequestModel(GetHashKey(npcData.model))
while not HasModel
-- NPC erstellen -- NPC erstellen
RequestModel(GetHashKey(npcData.model)) RequestModel(GetHashKey(npcData.model))
while not HasModelLoaded(GetHashKey(npcData.model)) do while not HasModelLoaded(GetHashKey(npcData.model)) do
Wait(1) Wait(1)
end end
debugPrint("NPC-Modell geladen für " .. fieldId)
local npc = CreatePed(4, GetHashKey(npcData.model), npcData.coords.x, npcData.coords.y, npcData.coords.z, npcData.coords.w, false, true) local npc = CreatePed(4, GetHashKey(npcData.model), npcData.coords.x, npcData.coords.y, npcData.coords.z, npcData.coords.w, false, true)
SetEntityInvincible(npc, true) SetEntityInvincible(npc, true)
FreezeEntityPosition(npc, true) FreezeEntityPosition(npc, true)
@ -811,10 +789,8 @@ end)
-- Event für Feld-spezifisches Menü -- Event für Feld-spezifisches Menü
RegisterNetEvent('tdm:openFieldMenu', function(data) RegisterNetEvent('tdm:openFieldMenu', function(data)
if data and data.fieldId then if data and data.fieldId then
debugPrint("Öffne Feldmenü für: " .. data.fieldId)
openMainMenu(data.fieldId) openMainMenu(data.fieldId)
else else
debugPrint("FEHLER: Keine Feld-ID übertragen!")
lib.notify({ lib.notify({
title = 'Fehler', title = 'Fehler',
description = 'Keine Feld-ID übertragen!', description = 'Keine Feld-ID übertragen!',
@ -826,7 +802,6 @@ end)
-- Chat Command zum Spiel verlassen -- Chat Command zum Spiel verlassen
RegisterCommand('leavetdm', function() RegisterCommand('leavetdm', function()
if inTDM then if inTDM then
debugPrint("Verlasse Spiel über Command")
TriggerServerEvent('tdm:leaveGame') TriggerServerEvent('tdm:leaveGame')
lib.notify({ lib.notify({
title = 'TeamDeathmatch', title = 'TeamDeathmatch',
@ -834,7 +809,6 @@ RegisterCommand('leavetdm', function()
type = 'info' type = 'info'
}) })
else else
debugPrint("Command 'leavetdm' ausgeführt, aber nicht in einem Spiel")
lib.notify({ lib.notify({
title = 'TeamDeathmatch', title = 'TeamDeathmatch',
description = 'Du bist in keinem Spiel!', description = 'Du bist in keinem Spiel!',
@ -863,18 +837,11 @@ RegisterCommand('debugtdm', function()
local hasLobby = fieldData.lobby and fieldData.lobby.pos and "" or "" local hasLobby = fieldData.lobby and fieldData.lobby.pos and "" or ""
debugPrint("- " .. fieldId .. ": " .. fieldData.name .. " " .. hasLobby) debugPrint("- " .. fieldId .. ": " .. fieldData.name .. " " .. hasLobby)
end end
lib.notify({
title = 'Debug Info',
description = 'Debug-Informationen wurden in die Konsole geschrieben',
type = 'info'
})
end, false) end, false)
-- Debug Commands für Masken -- Debug Commands für Masken
RegisterCommand('testmask', function(source, args) RegisterCommand('testmask', function(source, args)
if not args[1] or not args[2] then if not args[1] or not args[2] then
debugPrint("Ungültige Parameter für testmask")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Verwendung: /testmask [team1/team2] [male/female]', description = 'Verwendung: /testmask [team1/team2] [male/female]',
@ -886,22 +853,18 @@ RegisterCommand('testmask', function(source, args)
local team = args[1] local team = args[1]
local gender = args[2] local gender = args[2]
debugPrint("Teste Maske: Team=" .. team .. ", Gender=" .. gender)
if Config.teamMasks[team] and Config.teamMasks[team][gender] then if Config.teamMasks[team] and Config.teamMasks[team][gender] then
local maskData = Config.teamMasks[team][gender] local maskData = Config.teamMasks[team][gender]
local ped = PlayerPedId() local ped = PlayerPedId()
SetPedComponentVariation(ped, maskData.component, maskData.drawable, maskData.texture, 0) SetPedComponentVariation(ped, maskData.component, maskData.drawable, maskData.texture, 0)
debugPrint("Maske gesetzt: " .. team .. " (" .. gender .. ")")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Maske gesetzt: ' .. team .. ' (' .. gender .. ')', description = 'Maske gesetzt: ' .. team .. ' (' .. gender .. ')',
type = 'success' type = 'success'
}) })
else else
debugPrint("Maske nicht gefunden: " .. team .. " (" .. gender .. ")")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Maske nicht gefunden!', description = 'Maske nicht gefunden!',
@ -913,7 +876,6 @@ end, false)
-- Command zum Entfernen der Maske -- Command zum Entfernen der Maske
RegisterCommand('removemask', function() RegisterCommand('removemask', function()
SetPedComponentVariation(PlayerPedId(), 1, 0, 0, 0) SetPedComponentVariation(PlayerPedId(), 1, 0, 0, 0)
debugPrint("Maske entfernt")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Maske entfernt!', description = 'Maske entfernt!',
@ -924,7 +886,6 @@ end, false)
-- Debug-Funktion für Respawn -- Debug-Funktion für Respawn
RegisterCommand('forcetdmrespawn', function() RegisterCommand('forcetdmrespawn', function()
if inTDM and currentTeam and currentField then if inTDM and currentTeam and currentField then
debugPrint("Manueller Respawn ausgelöst")
local ped = PlayerPedId() local ped = PlayerPedId()
local fieldConfig = Config.gameFields[currentField] local fieldConfig = Config.gameFields[currentField]
local spawnPoints = fieldConfig.teamSpawns[currentTeam] local spawnPoints = fieldConfig.teamSpawns[currentTeam]
@ -942,14 +903,12 @@ RegisterCommand('forcetdmrespawn', function()
Wait(100) Wait(100)
DoScreenFadeIn(500) DoScreenFadeIn(500)
debugPrint("Manueller Respawn abgeschlossen")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Manueller Respawn durchgeführt!', description = 'Manueller Respawn durchgeführt!',
type = 'success' type = 'success'
}) })
else else
debugPrint("Manueller Respawn fehlgeschlagen - nicht in einem TDM-Spiel")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Du bist nicht in einem TDM-Spiel!', description = 'Du bist nicht in einem TDM-Spiel!',
@ -975,7 +934,6 @@ RegisterCommand('showstats', function()
type = 'info' type = 'info'
}) })
else else
debugPrint("Stats-Anzeige fehlgeschlagen - nicht in einem TDM-Spiel")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Du bist nicht in einem TDM-Spiel!', description = 'Du bist nicht in einem TDM-Spiel!',
@ -987,7 +945,6 @@ end, false)
-- Debug-Funktion für manuellen Hit -- Debug-Funktion für manuellen Hit
RegisterCommand('testhit', function() RegisterCommand('testhit', function()
if inTDM then if inTDM then
debugPrint("Test-Hit ausgelöst")
TriggerEvent('tdm:playerHit') TriggerEvent('tdm:playerHit')
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
@ -995,7 +952,6 @@ RegisterCommand('testhit', function()
type = 'info' type = 'info'
}) })
else else
debugPrint("Test-Hit fehlgeschlagen - nicht in einem TDM-Spiel")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Du bist nicht in einem TDM-Spiel!', description = 'Du bist nicht in einem TDM-Spiel!',
@ -1007,7 +963,6 @@ end, false)
-- Debug-Funktion für manuellen Treffer -- Debug-Funktion für manuellen Treffer
RegisterCommand('testtreff', function() RegisterCommand('testtreff', function()
if inTDM then if inTDM then
debugPrint("Test-Treffer ausgelöst")
TriggerEvent('tdm:hitRegistered') TriggerEvent('tdm:hitRegistered')
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
@ -1015,7 +970,6 @@ RegisterCommand('testtreff', function()
type = 'info' type = 'info'
}) })
else else
debugPrint("Test-Treffer fehlgeschlagen - nicht in einem TDM-Spiel")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Du bist nicht in einem TDM-Spiel!', description = 'Du bist nicht in einem TDM-Spiel!',
@ -1024,19 +978,21 @@ RegisterCommand('testtreff', function()
end end
end, false) end, false)
-- Neuer Debug-Command für Damage-Test -- Debug-Befehl zum Testen der Treffer-Registrierung
RegisterCommand('tdmtesthit', function() RegisterCommand('testtreffer', function()
if inTDM then if inTDM and currentGameId and currentTeam then
debugPrint("Sende Test-Hit zum Server") debugPrint("Teste Treffer-Registrierung")
-- Simuliere einen Treffer gegen sich selbst
local targetTeam = currentTeam == 'team1' and 'team2' or 'team1' local targetTeam = currentTeam == 'team1' and 'team2' or 'team1'
TriggerServerEvent('tdm:playerWasHit', currentGameId, targetTeam, GetPlayerServerId(PlayerId())) TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, GetPlayerServerId(PlayerId()))
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Test-Hit zum Server gesendet', description = 'Test-Treffer gesendet!',
type = 'info' type = 'info'
}) })
else else
debugPrint("Server-Hit-Test fehlgeschlagen - nicht in einem TDM-Spiel")
lib.notify({ lib.notify({
title = 'Debug', title = 'Debug',
description = 'Du musst in einem TDM-Spiel sein!', description = 'Du musst in einem TDM-Spiel sein!',
@ -1045,35 +1001,32 @@ RegisterCommand('tdmtesthit', function()
end end
end, false) end, false)
-- Neuer Event-Handler für Waffen-Schaden -- Debug-Befehl zum Testen des Respawns
AddEventHandler('gameEventTriggered', function(name, args) RegisterCommand('testrespawn', function()
if name == "CEventNetworkEntityDamage" then if inTDM then
local victimId = args[1] debugPrint("Teste Respawn-Funktion")
local attackerId = args[2] TriggerEvent('tdm:playerHit')
local isDead = args[4] == 1
local weaponHash = args[5]
local isMelee = args[10] == 1
if inTDM and not isHit and victimId == PlayerPedId() then lib.notify({
local attackerServerId = nil title = 'Debug',
description = 'Test-Respawn ausgelöst!',
-- Versuche den Angreifer zu identifizieren type = 'info'
for _, player in ipairs(GetActivePlayers()) do })
if GetPlayerPed(player) == attackerId then else
attackerServerId = GetPlayerServerId(player) lib.notify({
break title = 'Debug',
end description = 'Du musst in einem TDM-Spiel sein!',
end type = 'error'
})
debugPrint("Schaden-Event erkannt: Angreifer=" .. (attackerServerId or "NPC/Unbekannt") .. ", Waffe=" .. weaponHash)
if attackerServerId then
-- Lokale Stats sofort updaten
playerStats.deaths = playerStats.deaths + 1
TriggerEvent('tdm:playerHit')
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, attackerServerId)
end
end
end end
end) end, false)
-- Hilfsfunktion für table.count
table.count = function(tbl)
local count = 0
for _, _ in pairs(tbl) do
count = count + 1
end
return count
end

View file

@ -421,16 +421,12 @@ function updateScoreForGame(gameId)
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
@ -439,14 +435,11 @@ 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
@ -468,7 +461,7 @@ AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() == resourceName then if GetCurrentResourceName() == resourceName then
activeGames = {} activeGames = {}
gameIdCounter = 1 gameIdCounter = 1
debugPrint("TeamDeathmatch System gestartet! Version 1.0.1") debugPrint("TeamDeathmatch System gestartet!")
end end
end) end)
@ -485,7 +478,6 @@ 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
@ -495,34 +487,7 @@ AddEventHandler('onResourceStop', function(resourceName)
end end
end) end)
-- Neuer Debug-Command für Server -- Admin-Befehle
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) RegisterCommand('tdmreset', function(source, args)
local src = source local src = source
if src > 0 then -- Spieler if src > 0 then -- Spieler
@ -557,3 +522,39 @@ RegisterCommand('tdmreset', function(source, args)
TriggerClientEvent('QBCore:Notify', src, 'TDM System zurückgesetzt!', 'success') TriggerClientEvent('QBCore:Notify', src, 'TDM System zurückgesetzt!', 'success')
end end
end, true) end, true)
-- Debug-Befehl für Server-Status
RegisterCommand('tdmstatus', 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 STATUS ===")
debugPrint("Aktive Spiele: " .. table.count(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)
end
if src > 0 then
TriggerClientEvent('QBCore:Notify', src, 'TDM Status in Server-Konsole', 'info')
end
end, true)
-- Hilfsfunktion für table.count
table.count = function(tbl)
local count = 0
for _, _ in pairs(tbl) do
count = count + 1
end
return count
end