1
0
Fork 0
forked from Simnation/Main

Update client.lua

This commit is contained in:
Nordi98 2025-07-26 22:42:38 +02:00
parent a65aa5a77e
commit 957126dddf

View file

@ -24,10 +24,13 @@ 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
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
@ -40,11 +43,21 @@ 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
@ -63,6 +76,8 @@ 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
@ -76,14 +91,18 @@ 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
@ -91,15 +110,17 @@ 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 (anpassen an deine Map) -- Notfall-Fallback Position
debugPrint("WARNUNG: Keine Lobby gefunden, verwende Fallback-Position")
SetEntityCoords(PlayerPedId(), -1042.4, -2745.8, 21.4) SetEntityCoords(PlayerPedId(), -1042.4, -2745.8, 21.4)
print("^3[TDM WARNING]^7 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()
@ -112,10 +133,12 @@ RegisterNetEvent('tdm:leaveGame', function()
type = 'error' type = 'error'
}) })
debugPrint("Spiel verlassen") debugPrint("Spiel verlassen - Cleanup abgeschlossen")
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?',
@ -128,20 +151,24 @@ 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!',
@ -152,15 +179,16 @@ end)
RegisterNetEvent('tdm:playerHit', function() RegisterNetEvent('tdm:playerHit', function()
if not inTDM then 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 return
end end
if isHit then if isHit then
print("^3[TDM WARNING]^7 Hit-Event empfangen, aber bereits getroffen!") debugPrint("WARNUNG: Hit-Event empfangen, aber bereits getroffen!")
return return
end end
debugPrint("Spieler wurde getroffen - Starte Respawn-Sequenz")
isHit = true isHit = true
local ped = PlayerPedId() local ped = PlayerPedId()
@ -171,40 +199,49 @@ RegisterNetEvent('tdm:playerHit', function()
type = 'error' type = 'error'
}) })
-- Vereinfachter Respawn ohne Animation -- Verbesserte Respawn-Logik
SetTimeout(3000, function() 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...") debugPrint("Respawn wird ausgeführt...")
-- Respawn zum Team Spawn -- Respawn zum Team Spawn
local fieldConfig = Config.gameFields[currentField] local fieldConfig = Config.gameFields[currentField]
if not fieldConfig then if not fieldConfig then
print("^1[TDM ERROR]^7 Feldkonfiguration nicht gefunden!") debugPrint("FEHLER: Feldkonfiguration nicht gefunden für Respawn!")
return return
end end
local spawnPoints = fieldConfig.teamSpawns[currentTeam] local spawnPoints = fieldConfig.teamSpawns[currentTeam]
if not spawnPoints or #spawnPoints == 0 then 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 return
end end
local randomSpawn = spawnPoints[math.random(#spawnPoints)] local randomSpawn = spawnPoints[math.random(#spawnPoints)]
debugPrint("Respawn-Position: " .. randomSpawn.x .. ", " .. randomSpawn.y .. ", " .. randomSpawn.z)
-- Teleport zum Spawn mit Fade -- Teleport zum Spawn mit Fade
DoScreenFadeOut(500) DoScreenFadeOut(500)
Wait(600) 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 -- Alle Animationen stoppen
ClearPedTasksImmediately(ped) ClearPedTasksImmediately(ped)
-- Teleport -- Teleport
SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z) SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z)
SetEntityHealth(ped, GetEntityMaxHealth(ped))
-- Spieler ist wieder aktiv -- Spieler ist wieder aktiv
isHit = false isHit = false
debugPrint("Respawn abgeschlossen - Spieler ist wieder aktiv")
Wait(100) Wait(100)
DoScreenFadeIn(500) DoScreenFadeIn(500)
@ -218,7 +255,6 @@ 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"))
@ -243,6 +279,7 @@ 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({
@ -252,10 +289,14 @@ RegisterNetEvent('tdm:hitRegistered', function()
duration = 2000 duration = 2000
}) })
-- Spiele einen Sound ab
PlaySoundFrontend(-1, "WEAPON_PURCHASE", "HUD_AMMO_SHOP_SOUNDSET", true)
showHitMarker() showHitMarker()
-- 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
@ -263,10 +304,12 @@ 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
@ -274,6 +317,7 @@ 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')
@ -304,9 +348,8 @@ 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
@ -360,15 +403,19 @@ function highlightTeamZone(team)
end end
function showHitMarker() function showHitMarker()
debugPrint("Zeige Hit-Marker an")
CreateThread(function() CreateThread(function()
local startTime = GetGameTimer() local startTime = GetGameTimer()
local duration = 500 -- 500ms display
while GetGameTimer() - startTime < 500 do while GetGameTimer() - startTime < duration do
Wait(0) Wait(0)
-- Draw hit marker
DrawRect(0.5, 0.5, 0.02, 0.002, 255, 0, 0, 255) 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) DrawRect(0.5, 0.5, 0.002, 0.02, 255, 0, 0, 255)
-- Draw hit text
SetTextFont(4) SetTextFont(4)
SetTextProportional(1) SetTextProportional(1)
SetTextScale(0.5, 0.5) SetTextScale(0.5, 0.5)
@ -378,12 +425,14 @@ 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!',
@ -392,6 +441,7 @@ function openMainMenu(fieldId)
return return
end end
debugPrint("Öffne Hauptmenü für Feld: " .. fieldId)
currentLobbyField = fieldId currentLobbyField = fieldId
TriggerServerEvent('tdm:requestGamesList') TriggerServerEvent('tdm:requestGamesList')
@ -405,6 +455,7 @@ 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
}, },
@ -413,6 +464,7 @@ 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
} }
@ -425,6 +477,7 @@ 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
}) })
@ -441,6 +494,7 @@ 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!',
@ -449,6 +503,7 @@ 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, {
@ -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 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!',
@ -498,6 +558,7 @@ 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)
@ -506,8 +567,10 @@ 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
@ -526,7 +589,9 @@ 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',
@ -538,9 +603,13 @@ 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
@ -548,6 +617,8 @@ 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',
@ -603,27 +674,33 @@ CreateThread(function()
end end
end) end)
-- Damage Handler (erweitert) -- Verbesserte Damage Handler
CreateThread(function() CreateThread(function()
while true do while true do
Wait(100)
if inTDM and not isHit then if inTDM and not isHit then
local ped = PlayerPedId() local ped = PlayerPedId()
if HasEntityBeenDamagedByAnyPed(ped) then if HasEntityBeenDamagedByAnyPed(ped) then
local damager = GetPedSourceOfDeath(ped) debugPrint("Schaden erkannt - Identifiziere Angreifer")
local damager = nil
local damagerPlayer = nil local damagerPlayer = nil
-- Versuche den Angreifer zu identifizieren -- Versuche den Angreifer zu identifizieren
for _, player in ipairs(GetActivePlayers()) do 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) damagerPlayer = GetPlayerServerId(player)
debugPrint("Angreifer identifiziert: " .. damagerPlayer)
break break
end end
end end
-- Schaden zurücksetzen
ClearEntityLastDamageEntity(ped) ClearEntityLastDamageEntity(ped)
ClearPedLastWeaponDamage(ped)
SetEntityHealth(ped, GetEntityMaxHealth(ped))
-- Lokale Stats sofort updaten -- Lokale Stats sofort updaten
playerStats.deaths = playerStats.deaths + 1 playerStats.deaths = playerStats.deaths + 1
@ -632,7 +709,13 @@ CreateThread(function()
TriggerEvent('tdm:playerHit') TriggerEvent('tdm:playerHit')
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, damagerPlayer) TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, damagerPlayer)
-- Warten um mehrfache Auslösung zu verhindern
Wait(500)
end end
Wait(0)
else
Wait(500)
end end
end end
end) end)
@ -671,6 +754,8 @@ 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)
@ -684,12 +769,17 @@ 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)
@ -713,7 +803,7 @@ CreateThread(function()
debugPrint("NPC und Blip für Feld " .. fieldId .. " erstellt") debugPrint("NPC und Blip für Feld " .. fieldId .. " erstellt")
else 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 end
end) end)
@ -721,8 +811,10 @@ 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!',
@ -734,6 +826,7 @@ 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',
@ -741,6 +834,7 @@ 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!',
@ -754,26 +848,33 @@ RegisterKeyMapping('leavetdm', 'TeamDeathmatch verlassen', 'keyboard', 'F7')
-- Debug Command zum Testen der Config -- Debug Command zum Testen der Config
RegisterCommand('debugtdm', function() RegisterCommand('debugtdm', function()
print("^2[TDM DEBUG]^7 Aktuelle Werte:") debugPrint("Aktuelle Werte:")
print("inTDM: " .. tostring(inTDM)) debugPrint("inTDM: " .. tostring(inTDM))
print("currentField: " .. tostring(currentField)) debugPrint("currentField: " .. tostring(currentField))
print("currentLobbyField: " .. tostring(currentLobbyField)) debugPrint("currentLobbyField: " .. tostring(currentLobbyField))
print("currentTeam: " .. tostring(currentTeam)) debugPrint("currentTeam: " .. tostring(currentTeam))
print("currentGameId: " .. tostring(currentGameId)) debugPrint("currentGameId: " .. tostring(currentGameId))
print("isHit: " .. tostring(isHit)) debugPrint("isHit: " .. tostring(isHit))
print("Hits: " .. playerStats.hits) debugPrint("Hits: " .. playerStats.hits)
print("Deaths: " .. playerStats.deaths) debugPrint("Deaths: " .. playerStats.deaths)
print("^2[TDM DEBUG]^7 Verfügbare Felder:") debugPrint("Verfügbare Felder:")
for fieldId, fieldData in pairs(Config.gameFields) do for fieldId, fieldData in pairs(Config.gameFields) do
local hasLobby = fieldData.lobby and fieldData.lobby.pos and "" or "" local hasLobby = fieldData.lobby and fieldData.lobby.pos and "" or ""
print("- " .. 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]',
@ -785,18 +886,22 @@ 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!',
@ -808,6 +913,7 @@ 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!',
@ -818,6 +924,7 @@ 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]
@ -827,21 +934,22 @@ RegisterCommand('forcetdmrespawn', function()
Wait(600) Wait(600)
ClearPedTasksImmediately(ped) ClearPedTasksImmediately(ped)
NetworkResurrectLocalPlayer(randomSpawn.x, randomSpawn.y, randomSpawn.z, 0.0, true, false)
SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z) SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z)
SetEntityHealth(ped, GetEntityMaxHealth(ped))
isHit = false isHit = false
Wait(100) Wait(100)
DoScreenFadeIn(500) DoScreenFadeIn(500)
lib.notify({ debugPrint("Manueller Respawn abgeschlossen")
title = 'Debug',
description = 'Manueller Respawn durchgeführt
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!',
@ -853,9 +961,9 @@ end, false)
-- Debug-Funktion für Stats -- Debug-Funktion für Stats
RegisterCommand('showstats', function() RegisterCommand('showstats', function()
if inTDM then if inTDM then
print("^2[TDM DEBUG]^7 Lokale Stats:") debugPrint("Lokale Stats:")
print("Hits: " .. playerStats.hits) debugPrint("Hits: " .. playerStats.hits)
print("Deaths: " .. playerStats.deaths) debugPrint("Deaths: " .. playerStats.deaths)
if currentGameId then if currentGameId then
TriggerServerEvent('tdm:debugPlayerStats', currentGameId) TriggerServerEvent('tdm:debugPlayerStats', currentGameId)
@ -867,6 +975,7 @@ 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!',
@ -878,6 +987,7 @@ 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',
@ -885,6 +995,7 @@ 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!',
@ -896,6 +1007,7 @@ 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',
@ -903,6 +1015,7 @@ 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!',
@ -910,3 +1023,57 @@ RegisterCommand('testtreff', function()
}) })
end end
end, false) 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)