From 957126dddfb118fde15fca4b37b75e8608e225e9 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Sat, 26 Jul 2025 22:42:38 +0200 Subject: [PATCH] Update client.lua --- resources/[standalone]/nordi_tdm/client.lua | 243 +++++++++++++++++--- 1 file changed, 205 insertions(+), 38 deletions(-) diff --git a/resources/[standalone]/nordi_tdm/client.lua b/resources/[standalone]/nordi_tdm/client.lua index 025e20953..ad8da1863 100644 --- a/resources/[standalone]/nordi_tdm/client.lua +++ b/resources/[standalone]/nordi_tdm/client.lua @@ -24,10 +24,13 @@ end -- Events RegisterNetEvent('tdm:updateGamesList', function(games) + debugPrint("Spiele-Liste aktualisiert - Anzahl: " .. (games and #games or "0")) activeGames = games end) RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId) + debugPrint("Join Game Event empfangen: GameID=" .. gameId .. ", Team=" .. team .. ", FieldID=" .. fieldId) + currentGameId = gameId currentTeam = team currentField = fieldId @@ -40,11 +43,21 @@ RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId) playerStats.gamesPlayed = playerStats.gamesPlayed + 1 local fieldConfig = Config.gameFields[fieldId] + if not fieldConfig then + debugPrint("FEHLER: Feldkonfiguration nicht gefunden für ID " .. fieldId) + return + end -- Teleport zu Team Spawn 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)] + debugPrint("Teleportiere zu: " .. randomSpawn.x .. ", " .. randomSpawn.y .. ", " .. randomSpawn.z) SetEntityCoords(PlayerPedId(), randomSpawn.x, randomSpawn.y, randomSpawn.z) -- Team Maske setzen @@ -63,6 +76,8 @@ RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId) end) RegisterNetEvent('tdm:leaveGame', function() + debugPrint("Leave Game Event empfangen") + inTDM = false local previousField = currentField currentTeam = nil @@ -76,14 +91,18 @@ RegisterNetEvent('tdm:leaveGame', function() -- Versuche zuerst die vorherige Feld-Lobby if previousField and Config.gameFields[previousField] and Config.gameFields[previousField].lobby then lobbyPos = Config.gameFields[previousField].lobby.pos + debugPrint("Verwende vorherige Feld-Lobby für Teleport") -- Dann die aktuelle Lobby-Feld elseif currentLobbyField and Config.gameFields[currentLobbyField] and Config.gameFields[currentLobbyField].lobby then lobbyPos = Config.gameFields[currentLobbyField].lobby.pos + debugPrint("Verwende aktuelle Lobby-Feld für Teleport") -- Fallback zur ersten verfügbaren Lobby else + debugPrint("Suche nach verfügbarer Lobby für Teleport") for fieldId, fieldData in pairs(Config.gameFields) do if fieldData.lobby and fieldData.lobby.pos then lobbyPos = fieldData.lobby.pos + debugPrint("Fallback-Lobby gefunden: " .. fieldId) break end end @@ -91,15 +110,17 @@ RegisterNetEvent('tdm:leaveGame', function() -- Teleport zur Lobby (mit Fallback-Position) if lobbyPos then + debugPrint("Teleportiere zur Lobby: " .. lobbyPos.x .. ", " .. lobbyPos.y .. ", " .. lobbyPos.z) SetEntityCoords(PlayerPedId(), lobbyPos.x, lobbyPos.y, lobbyPos.z) else - -- Notfall-Fallback Position (anpassen an deine Map) + -- Notfall-Fallback Position + debugPrint("WARNUNG: Keine Lobby gefunden, verwende Fallback-Position") SetEntityCoords(PlayerPedId(), -1042.4, -2745.8, 21.4) - print("^3[TDM WARNING]^7 Keine Lobby gefunden, Fallback-Position verwendet!") end -- Maske entfernen SetPedComponentVariation(PlayerPedId(), 1, 0, 0, 0) + debugPrint("Maske entfernt") -- Zone Blips entfernen removeTeamZoneBlips() @@ -112,10 +133,12 @@ RegisterNetEvent('tdm:leaveGame', function() type = 'error' }) - debugPrint("Spiel verlassen") + debugPrint("Spiel verlassen - Cleanup abgeschlossen") end) RegisterNetEvent('tdm:joinRequest', function(gameId, playerName, playerId) + debugPrint("Join-Anfrage erhalten von: " .. playerName .. " (ID: " .. playerId .. ") für Spiel " .. gameId) + local alert = lib.alertDialog({ header = 'Join Anfrage', content = playerName .. ' möchte deinem Spiel beitreten.\n\nErlauben?', @@ -128,20 +151,24 @@ RegisterNetEvent('tdm:joinRequest', function(gameId, playerName, playerId) }) if alert == 'confirm' then + debugPrint("Join-Anfrage von " .. playerName .. " akzeptiert") TriggerServerEvent('tdm:approveJoinRequest', gameId, playerId, true) else + debugPrint("Join-Anfrage von " .. playerName .. " abgelehnt") TriggerServerEvent('tdm:approveJoinRequest', gameId, playerId, false) end end) RegisterNetEvent('tdm:joinRequestResult', function(approved, gameName) if approved then + debugPrint("Join-Anfrage für Spiel '" .. gameName .. "' wurde akzeptiert") lib.notify({ title = 'TeamDeathmatch', description = 'Deine Anfrage wurde angenommen!', type = 'success' }) else + debugPrint("Join-Anfrage für Spiel '" .. gameName .. "' wurde abgelehnt") lib.notify({ title = 'TeamDeathmatch', description = 'Deine Anfrage für "' .. gameName .. '" wurde abgelehnt!', @@ -152,15 +179,16 @@ end) RegisterNetEvent('tdm:playerHit', function() if not inTDM then - print("^3[TDM WARNING]^7 Hit-Event empfangen, aber nicht im TDM!") + debugPrint("WARNUNG: Hit-Event empfangen, aber nicht im TDM!") return end if isHit then - print("^3[TDM WARNING]^7 Hit-Event empfangen, aber bereits getroffen!") + debugPrint("WARNUNG: Hit-Event empfangen, aber bereits getroffen!") return end + debugPrint("Spieler wurde getroffen - Starte Respawn-Sequenz") isHit = true local ped = PlayerPedId() @@ -171,40 +199,49 @@ RegisterNetEvent('tdm:playerHit', function() type = 'error' }) - -- Vereinfachter Respawn ohne Animation + -- Verbesserte Respawn-Logik SetTimeout(3000, function() - if not inTDM then return end + if not inTDM then + debugPrint("Respawn abgebrochen - nicht mehr im TDM") + return + end - -- Debug-Nachricht debugPrint("Respawn wird ausgeführt...") -- Respawn zum Team Spawn local fieldConfig = Config.gameFields[currentField] if not fieldConfig then - print("^1[TDM ERROR]^7 Feldkonfiguration nicht gefunden!") + debugPrint("FEHLER: Feldkonfiguration nicht gefunden für Respawn!") return end local spawnPoints = fieldConfig.teamSpawns[currentTeam] if not spawnPoints or #spawnPoints == 0 then - print("^1[TDM ERROR]^7 Keine Spawn-Punkte gefunden!") + debugPrint("FEHLER: Keine Spawn-Punkte gefunden für Respawn!") return end local randomSpawn = spawnPoints[math.random(#spawnPoints)] + debugPrint("Respawn-Position: " .. randomSpawn.x .. ", " .. randomSpawn.y .. ", " .. randomSpawn.z) -- Teleport zum Spawn mit Fade DoScreenFadeOut(500) Wait(600) + -- Stellen Sie sicher, dass der Spieler lebt + NetworkResurrectLocalPlayer(randomSpawn.x, randomSpawn.y, randomSpawn.z, 0.0, true, false) + debugPrint("Spieler wiederbelebt") + -- Alle Animationen stoppen ClearPedTasksImmediately(ped) -- Teleport SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z) + SetEntityHealth(ped, GetEntityMaxHealth(ped)) -- Spieler ist wieder aktiv isHit = false + debugPrint("Respawn abgeschlossen - Spieler ist wieder aktiv") Wait(100) DoScreenFadeIn(500) @@ -218,7 +255,6 @@ RegisterNetEvent('tdm:playerHit', function() end) RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score, gameStats) - -- Debug-Ausgabe debugPrint("Score Update empfangen: Team1=" .. team1Score .. ", Team2=" .. team2Score) if gameStats then debugPrint("GameStats: Hits=" .. (gameStats.hits or "nil") .. ", Deaths=" .. (gameStats.deaths or "nil")) @@ -243,6 +279,7 @@ RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score, gameStats) end) RegisterNetEvent('tdm:hitRegistered', function() + debugPrint("Treffer registriert! Aktualisiere lokale Stats") playerStats.hits = playerStats.hits + 1 lib.notify({ @@ -252,10 +289,14 @@ RegisterNetEvent('tdm:hitRegistered', function() duration = 2000 }) + -- Spiele einen Sound ab + PlaySoundFrontend(-1, "WEAPON_PURCHASE", "HUD_AMMO_SHOP_SOUNDSET", true) + showHitMarker() -- Score sofort aktualisieren if currentGameId then + debugPrint("Fordere Score-Update an für Spiel " .. currentGameId) TriggerServerEvent('tdm:requestScoreUpdate', currentGameId) end @@ -263,10 +304,12 @@ RegisterNetEvent('tdm:hitRegistered', function() end) RegisterNetEvent('tdm:deathRegistered', function() + debugPrint("Tod registriert! Aktualisiere lokale Stats") playerStats.deaths = playerStats.deaths + 1 -- Score sofort aktualisieren if currentGameId then + debugPrint("Fordere Score-Update an für Spiel " .. currentGameId) TriggerServerEvent('tdm:requestScoreUpdate', currentGameId) end @@ -274,6 +317,7 @@ RegisterNetEvent('tdm:deathRegistered', function() end) RegisterNetEvent('tdm:gameEnded', function(winnerTeam, team1Score, team2Score) + debugPrint("Spiel beendet! Gewinner: " .. (winnerTeam or "Unentschieden")) lib.hideTextUI() local wonGame = (currentTeam == 'team1' and winnerTeam == 'team1') or (currentTeam == 'team2' and winnerTeam == 'team2') @@ -304,9 +348,8 @@ RegisterNetEvent('tdm:gameEnded', function(winnerTeam, team1Score, team2Score) }) Wait(5000) + debugPrint("Verlasse Spiel nach Ende") TriggerServerEvent('tdm:leaveGame') - - debugPrint("Spiel beendet! Gewinner: " .. (winnerTeam or "Unentschieden")) end) -- Funktionen @@ -360,15 +403,19 @@ function highlightTeamZone(team) end function showHitMarker() + debugPrint("Zeige Hit-Marker an") CreateThread(function() local startTime = GetGameTimer() + local duration = 500 -- 500ms display - while GetGameTimer() - startTime < 500 do + while GetGameTimer() - startTime < duration do Wait(0) + -- Draw hit marker DrawRect(0.5, 0.5, 0.02, 0.002, 255, 0, 0, 255) DrawRect(0.5, 0.5, 0.002, 0.02, 255, 0, 0, 255) + -- Draw hit text SetTextFont(4) SetTextProportional(1) SetTextScale(0.5, 0.5) @@ -378,12 +425,14 @@ function showHitMarker() SetTextCentre(true) DrawText(0.5, 0.45) end + debugPrint("Hit-Marker ausgeblendet") end) end function openMainMenu(fieldId) -- Sicherheitscheck if not fieldId or not Config.gameFields[fieldId] then + debugPrint("FEHLER: Ungültiges Spielfeld für Menü: " .. tostring(fieldId)) lib.notify({ title = 'Fehler', description = 'Ungültiges Spielfeld!', @@ -392,6 +441,7 @@ function openMainMenu(fieldId) return end + debugPrint("Öffne Hauptmenü für Feld: " .. fieldId) currentLobbyField = fieldId TriggerServerEvent('tdm:requestGamesList') @@ -405,6 +455,7 @@ function openMainMenu(fieldId) description = 'Erstelle ein neues Spiel für ' .. fieldName, icon = 'plus', onSelect = function() + debugPrint("Öffne Menü zum Erstellen eines neuen Spiels") openCreateGameMenu(fieldId) end }, @@ -413,6 +464,7 @@ function openMainMenu(fieldId) description = 'Trete einem laufenden Spiel bei', icon = 'users', onSelect = function() + debugPrint("Öffne Menü zum Beitreten eines Spiels") openJoinGameMenu(fieldId) end } @@ -425,6 +477,7 @@ function openMainMenu(fieldId) icon = 'door-open', iconColor = 'red', onSelect = function() + debugPrint("Verlasse aktuelles Spiel über Menü") TriggerServerEvent('tdm:leaveGame') end }) @@ -441,6 +494,7 @@ end function openCreateGameMenu(fieldId) if not fieldId or not Config.gameFields[fieldId] then + debugPrint("FEHLER: Ungültiges Spielfeld für Erstellungsmenü: " .. tostring(fieldId)) lib.notify({ title = 'Fehler', description = 'Ungültiges Spielfeld!', @@ -449,6 +503,7 @@ function openCreateGameMenu(fieldId) return end + debugPrint("Öffne Spiel-Erstellungsmenü für Feld: " .. fieldId) local fieldData = Config.gameFields[fieldId] local input = lib.inputDialog('Neues Spiel erstellen - ' .. fieldData.name, { @@ -477,19 +532,24 @@ function openCreateGameMenu(fieldId) } }) - if not input then return end + if not input then + debugPrint("Spiel-Erstellung abgebrochen") + return + end local gameName = input[1] local gameType = input[2] local password = input[3] and input[3] ~= '' and input[3] or nil if gameName and gameType then + debugPrint("Erstelle Spiel: " .. gameName .. " (Typ: " .. gameType .. ", Passwort: " .. (password and "Ja" or "Nein") .. ")") TriggerServerEvent('tdm:createGame', gameName, fieldId, gameType, password) end end function openJoinGameMenu(fieldId) if not fieldId or not Config.gameFields[fieldId] then + debugPrint("FEHLER: Ungültiges Spielfeld für Join-Menü: " .. tostring(fieldId)) lib.notify({ title = 'Fehler', description = 'Ungültiges Spielfeld!', @@ -498,6 +558,7 @@ function openJoinGameMenu(fieldId) return end + debugPrint("Öffne Spiel-Beitrittsmenü für Feld: " .. fieldId) TriggerServerEvent('tdm:requestGamesList') Wait(200) @@ -506,8 +567,10 @@ function openJoinGameMenu(fieldId) local fieldName = Config.gameFields[fieldId].name -- Nur Spiele für dieses Feld anzeigen + local gamesCount = 0 for gameId, gameData in pairs(activeGames) do if gameData.fieldId == fieldId then + gamesCount = gamesCount + 1 local playerCount = #gameData.team1 + #gameData.team2 local maxPlayers = Config.gameFields[gameData.fieldId].maxPlayers @@ -526,7 +589,9 @@ function openJoinGameMenu(fieldId) gameType = gameData.gameType }, onSelect = function(args) + debugPrint("Versuche Spiel beizutreten: " .. gameId) if args.hasPassword then + debugPrint("Spiel erfordert Passwort") local input = lib.inputDialog('Passwort eingeben', { { type = 'input', @@ -538,9 +603,13 @@ function openJoinGameMenu(fieldId) }) if input and input[1] then + debugPrint("Passwort eingegeben, sende Beitrittsanfrage") TriggerServerEvent('tdm:requestJoinGame', args.gameId, input[1]) + else + debugPrint("Passwort-Eingabe abgebrochen") end else + debugPrint("Kein Passwort erforderlich, sende Beitrittsanfrage") TriggerServerEvent('tdm:requestJoinGame', args.gameId) end end @@ -548,6 +617,8 @@ function openJoinGameMenu(fieldId) end end + debugPrint("Gefundene Spiele für Feld " .. fieldId .. ": " .. gamesCount) + if #options == 0 then table.insert(options, { title = 'Keine Spiele verfügbar', @@ -603,27 +674,33 @@ CreateThread(function() end end) --- Damage Handler (erweitert) +-- Verbesserte Damage Handler CreateThread(function() while true do - Wait(100) - if inTDM and not isHit then local ped = PlayerPedId() if HasEntityBeenDamagedByAnyPed(ped) then - local damager = GetPedSourceOfDeath(ped) + debugPrint("Schaden erkannt - Identifiziere Angreifer") + + local damager = nil local damagerPlayer = nil -- Versuche den Angreifer zu identifizieren for _, player in ipairs(GetActivePlayers()) do - if GetPlayerPed(player) == damager then + local playerPed = GetPlayerPed(player) + if HasPedBeenDamagedBy(ped, playerPed) then + damager = playerPed damagerPlayer = GetPlayerServerId(player) + debugPrint("Angreifer identifiziert: " .. damagerPlayer) break end end + -- Schaden zurücksetzen ClearEntityLastDamageEntity(ped) + ClearPedLastWeaponDamage(ped) + SetEntityHealth(ped, GetEntityMaxHealth(ped)) -- Lokale Stats sofort updaten playerStats.deaths = playerStats.deaths + 1 @@ -632,7 +709,13 @@ CreateThread(function() TriggerEvent('tdm:playerHit') TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, damagerPlayer) + + -- Warten um mehrfache Auslösung zu verhindern + Wait(500) end + Wait(0) + else + Wait(500) end end end) @@ -671,6 +754,8 @@ CreateThread(function() local lobbyPos = fieldData.lobby.pos local npcData = fieldData.lobby.npc + debugPrint("Erstelle Blip und NPC für Feld " .. fieldId) + -- Blip erstellen local blip = AddBlipForCoord(lobbyPos.x, lobbyPos.y, lobbyPos.z) SetBlipSprite(blip, 432) @@ -684,12 +769,17 @@ CreateThread(function() tdmBlips[fieldId] = blip + -- NPC erstellen + RequestModel(GetHashKey(npcData.model)) + while not HasModel -- NPC erstellen RequestModel(GetHashKey(npcData.model)) while not HasModelLoaded(GetHashKey(npcData.model)) do Wait(1) 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) SetEntityInvincible(npc, true) FreezeEntityPosition(npc, true) @@ -713,7 +803,7 @@ CreateThread(function() debugPrint("NPC und Blip für Feld " .. fieldId .. " erstellt") else - print("^3[TDM WARNING]^7 Feld " .. fieldId .. " hat keine vollständige Lobby-Konfiguration!") + debugPrint("WARNUNG: Feld " .. fieldId .. " hat keine vollständige Lobby-Konfiguration!") end end end) @@ -721,8 +811,10 @@ end) -- Event für Feld-spezifisches Menü RegisterNetEvent('tdm:openFieldMenu', function(data) if data and data.fieldId then + debugPrint("Öffne Feldmenü für: " .. data.fieldId) openMainMenu(data.fieldId) else + debugPrint("FEHLER: Keine Feld-ID übertragen!") lib.notify({ title = 'Fehler', description = 'Keine Feld-ID übertragen!', @@ -734,6 +826,7 @@ end) -- Chat Command zum Spiel verlassen RegisterCommand('leavetdm', function() if inTDM then + debugPrint("Verlasse Spiel über Command") TriggerServerEvent('tdm:leaveGame') lib.notify({ title = 'TeamDeathmatch', @@ -741,6 +834,7 @@ RegisterCommand('leavetdm', function() type = 'info' }) else + debugPrint("Command 'leavetdm' ausgeführt, aber nicht in einem Spiel") lib.notify({ title = 'TeamDeathmatch', description = 'Du bist in keinem Spiel!', @@ -754,26 +848,33 @@ RegisterKeyMapping('leavetdm', 'TeamDeathmatch verlassen', 'keyboard', 'F7') -- Debug Command zum Testen der Config RegisterCommand('debugtdm', function() - print("^2[TDM DEBUG]^7 Aktuelle Werte:") - print("inTDM: " .. tostring(inTDM)) - print("currentField: " .. tostring(currentField)) - print("currentLobbyField: " .. tostring(currentLobbyField)) - print("currentTeam: " .. tostring(currentTeam)) - print("currentGameId: " .. tostring(currentGameId)) - print("isHit: " .. tostring(isHit)) - print("Hits: " .. playerStats.hits) - print("Deaths: " .. playerStats.deaths) + debugPrint("Aktuelle Werte:") + debugPrint("inTDM: " .. tostring(inTDM)) + debugPrint("currentField: " .. tostring(currentField)) + debugPrint("currentLobbyField: " .. tostring(currentLobbyField)) + debugPrint("currentTeam: " .. tostring(currentTeam)) + debugPrint("currentGameId: " .. tostring(currentGameId)) + debugPrint("isHit: " .. tostring(isHit)) + debugPrint("Hits: " .. playerStats.hits) + debugPrint("Deaths: " .. playerStats.deaths) - print("^2[TDM DEBUG]^7 Verfügbare Felder:") + debugPrint("Verfügbare Felder:") for fieldId, fieldData in pairs(Config.gameFields) do local hasLobby = fieldData.lobby and fieldData.lobby.pos and "✅" or "❌" - print("- " .. fieldId .. ": " .. fieldData.name .. " " .. hasLobby) + debugPrint("- " .. fieldId .. ": " .. fieldData.name .. " " .. hasLobby) end + + lib.notify({ + title = 'Debug Info', + description = 'Debug-Informationen wurden in die Konsole geschrieben', + type = 'info' + }) end, false) -- Debug Commands für Masken RegisterCommand('testmask', function(source, args) if not args[1] or not args[2] then + debugPrint("Ungültige Parameter für testmask") lib.notify({ title = 'Debug', description = 'Verwendung: /testmask [team1/team2] [male/female]', @@ -785,18 +886,22 @@ RegisterCommand('testmask', function(source, args) local team = args[1] local gender = args[2] + debugPrint("Teste Maske: Team=" .. team .. ", Gender=" .. gender) + if Config.teamMasks[team] and Config.teamMasks[team][gender] then local maskData = Config.teamMasks[team][gender] local ped = PlayerPedId() SetPedComponentVariation(ped, maskData.component, maskData.drawable, maskData.texture, 0) + debugPrint("Maske gesetzt: " .. team .. " (" .. gender .. ")") lib.notify({ title = 'Debug', description = 'Maske gesetzt: ' .. team .. ' (' .. gender .. ')', type = 'success' }) else + debugPrint("Maske nicht gefunden: " .. team .. " (" .. gender .. ")") lib.notify({ title = 'Debug', description = 'Maske nicht gefunden!', @@ -808,6 +913,7 @@ end, false) -- Command zum Entfernen der Maske RegisterCommand('removemask', function() SetPedComponentVariation(PlayerPedId(), 1, 0, 0, 0) + debugPrint("Maske entfernt") lib.notify({ title = 'Debug', description = 'Maske entfernt!', @@ -818,6 +924,7 @@ end, false) -- Debug-Funktion für Respawn RegisterCommand('forcetdmrespawn', function() if inTDM and currentTeam and currentField then + debugPrint("Manueller Respawn ausgelöst") local ped = PlayerPedId() local fieldConfig = Config.gameFields[currentField] local spawnPoints = fieldConfig.teamSpawns[currentTeam] @@ -827,21 +934,22 @@ RegisterCommand('forcetdmrespawn', function() Wait(600) ClearPedTasksImmediately(ped) + NetworkResurrectLocalPlayer(randomSpawn.x, randomSpawn.y, randomSpawn.z, 0.0, true, false) SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z) + SetEntityHealth(ped, GetEntityMaxHealth(ped)) isHit = false Wait(100) DoScreenFadeIn(500) - lib.notify({ - title = 'Debug', - description = 'Manueller Respawn durchgeführt + debugPrint("Manueller Respawn abgeschlossen") lib.notify({ title = 'Debug', description = 'Manueller Respawn durchgeführt!', type = 'success' }) else + debugPrint("Manueller Respawn fehlgeschlagen - nicht in einem TDM-Spiel") lib.notify({ title = 'Debug', description = 'Du bist nicht in einem TDM-Spiel!', @@ -853,9 +961,9 @@ end, false) -- Debug-Funktion für Stats RegisterCommand('showstats', function() if inTDM then - print("^2[TDM DEBUG]^7 Lokale Stats:") - print("Hits: " .. playerStats.hits) - print("Deaths: " .. playerStats.deaths) + debugPrint("Lokale Stats:") + debugPrint("Hits: " .. playerStats.hits) + debugPrint("Deaths: " .. playerStats.deaths) if currentGameId then TriggerServerEvent('tdm:debugPlayerStats', currentGameId) @@ -867,6 +975,7 @@ RegisterCommand('showstats', function() type = 'info' }) else + debugPrint("Stats-Anzeige fehlgeschlagen - nicht in einem TDM-Spiel") lib.notify({ title = 'Debug', description = 'Du bist nicht in einem TDM-Spiel!', @@ -878,6 +987,7 @@ end, false) -- Debug-Funktion für manuellen Hit RegisterCommand('testhit', function() if inTDM then + debugPrint("Test-Hit ausgelöst") TriggerEvent('tdm:playerHit') lib.notify({ title = 'Debug', @@ -885,6 +995,7 @@ RegisterCommand('testhit', function() type = 'info' }) else + debugPrint("Test-Hit fehlgeschlagen - nicht in einem TDM-Spiel") lib.notify({ title = 'Debug', description = 'Du bist nicht in einem TDM-Spiel!', @@ -896,6 +1007,7 @@ end, false) -- Debug-Funktion für manuellen Treffer RegisterCommand('testtreff', function() if inTDM then + debugPrint("Test-Treffer ausgelöst") TriggerEvent('tdm:hitRegistered') lib.notify({ title = 'Debug', @@ -903,6 +1015,7 @@ RegisterCommand('testtreff', function() type = 'info' }) else + debugPrint("Test-Treffer fehlgeschlagen - nicht in einem TDM-Spiel") lib.notify({ title = 'Debug', description = 'Du bist nicht in einem TDM-Spiel!', @@ -910,3 +1023,57 @@ RegisterCommand('testtreff', function() }) end end, false) + +-- Neuer Debug-Command für Damage-Test +RegisterCommand('tdmtesthit', function() + if inTDM then + debugPrint("Sende Test-Hit zum Server") + local targetTeam = currentTeam == 'team1' and 'team2' or 'team1' + TriggerServerEvent('tdm:playerWasHit', currentGameId, targetTeam, GetPlayerServerId(PlayerId())) + lib.notify({ + title = 'Debug', + description = 'Test-Hit zum Server gesendet', + type = 'info' + }) + else + debugPrint("Server-Hit-Test fehlgeschlagen - nicht in einem TDM-Spiel") + lib.notify({ + title = 'Debug', + description = 'Du musst in einem TDM-Spiel sein!', + type = 'error' + }) + end +end, false) + +-- Neuer Event-Handler für Waffen-Schaden +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] + local isMelee = args[10] == 1 + + 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 + + TriggerEvent('tdm:playerHit') + TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, attackerServerId) + end + end + end +end)