1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-26 22:13:11 +02:00
parent cddc8d3aad
commit a65aa5a77e
2 changed files with 213 additions and 70 deletions

View file

@ -17,6 +17,11 @@ local playerStats = {
gamesPlayed = 0
}
-- Debug-Funktion für Konsole
local function debugPrint(message)
print("^2[TDM DEBUG]^7 " .. message)
end
-- Events
RegisterNetEvent('tdm:updateGamesList', function(games)
activeGames = games
@ -53,6 +58,8 @@ RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId)
description = 'Du bist dem Spiel beigetreten! Team: ' .. team,
type = 'success'
})
debugPrint("Spiel beigetreten: " .. gameId .. ", Team: " .. team .. ", Feld: " .. fieldId)
end)
RegisterNetEvent('tdm:leaveGame', function()
@ -104,6 +111,8 @@ RegisterNetEvent('tdm:leaveGame', function()
description = 'Du hast das Spiel verlassen!',
type = 'error'
})
debugPrint("Spiel verlassen")
end)
RegisterNetEvent('tdm:joinRequest', function(gameId, playerName, playerId)
@ -142,67 +151,79 @@ RegisterNetEvent('tdm:joinRequestResult', function(approved, gameName)
end)
RegisterNetEvent('tdm:playerHit', function()
if not inTDM or isHit then return end
if not inTDM then
print("^3[TDM WARNING]^7 Hit-Event empfangen, aber nicht im TDM!")
return
end
if isHit then
print("^3[TDM WARNING]^7 Hit-Event empfangen, aber bereits getroffen!")
return
end
isHit = true
local ped = PlayerPedId()
-- Animation für kurze Zeit
RequestAnimDict("random@mugging3")
while not HasAnimDictLoaded("random@mugging3") do
Wait(1)
end
TaskPlayAnim(ped, "random@mugging3", "handsup_standing_base", 8.0, -8.0, -1, 50, 0, false, false, false)
-- Benachrichtigung
lib.notify({
title = 'TeamDeathmatch',
description = 'Du wurdest getroffen! Respawn in 3 Sekunden...',
type = 'error'
})
-- Nach 3 Sekunden automatisch respawnen
CreateThread(function()
Wait(3000)
-- Vereinfachter Respawn ohne Animation
SetTimeout(3000, function()
if not inTDM then return end
if inTDM and isHit and currentTeam and currentField then
-- Respawn zum Team Spawn
local fieldConfig = Config.gameFields[currentField]
local spawnPoints = fieldConfig.teamSpawns[currentTeam]
local randomSpawn = spawnPoints[math.random(#spawnPoints)]
-- Bildschirm ausblenden für sauberen Teleport
DoScreenFadeOut(500)
Wait(500)
-- Animation stoppen
ClearPedTasks(ped)
-- Teleport zum Spawn
SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z)
-- Spieler ist wieder aktiv
isHit = false
-- Zone Blip Flash stoppen
if teamZoneBlips[currentTeam] and DoesBlipExist(teamZoneBlips[currentTeam]) then
SetBlipFlashes(teamZoneBlips[currentTeam], false)
end
-- Bildschirm wieder einblenden
Wait(100)
DoScreenFadeIn(500)
lib.notify({
title = 'TeamDeathmatch',
description = 'Du bist wieder im Spiel!',
type = 'success'
})
-- 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!")
return
end
local spawnPoints = fieldConfig.teamSpawns[currentTeam]
if not spawnPoints or #spawnPoints == 0 then
print("^1[TDM ERROR]^7 Keine Spawn-Punkte gefunden!")
return
end
local randomSpawn = spawnPoints[math.random(#spawnPoints)]
-- Teleport zum Spawn mit Fade
DoScreenFadeOut(500)
Wait(600)
-- Alle Animationen stoppen
ClearPedTasksImmediately(ped)
-- Teleport
SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z)
-- Spieler ist wieder aktiv
isHit = false
Wait(100)
DoScreenFadeIn(500)
lib.notify({
title = 'TeamDeathmatch',
description = 'Du bist wieder im Spiel!',
type = 'success'
})
end)
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"))
end
-- Verwende gameStats falls verfügbar, sonst lokale Stats
local myHits = gameStats and gameStats.hits or playerStats.hits
local myDeaths = gameStats and gameStats.deaths or playerStats.deaths
@ -234,14 +255,22 @@ RegisterNetEvent('tdm:hitRegistered', function()
showHitMarker()
-- Score sofort aktualisieren
TriggerServerEvent('tdm:requestScoreUpdate', currentGameId)
if currentGameId then
TriggerServerEvent('tdm:requestScoreUpdate', currentGameId)
end
debugPrint("Treffer registriert! Neue Hits: " .. playerStats.hits)
end)
RegisterNetEvent('tdm:deathRegistered', function()
playerStats.deaths = playerStats.deaths + 1
-- Score sofort aktualisieren
TriggerServerEvent('tdm:requestScoreUpdate', currentGameId)
if currentGameId then
TriggerServerEvent('tdm:requestScoreUpdate', currentGameId)
end
debugPrint("Tod registriert! Neue Deaths: " .. playerStats.deaths)
end)
RegisterNetEvent('tdm:gameEnded', function(winnerTeam, team1Score, team2Score)
@ -276,6 +305,8 @@ RegisterNetEvent('tdm:gameEnded', function(winnerTeam, team1Score, team2Score)
Wait(5000)
TriggerServerEvent('tdm:leaveGame')
debugPrint("Spiel beendet! Gewinner: " .. (winnerTeam or "Unentschieden"))
end)
-- Funktionen
@ -291,7 +322,12 @@ function setTeamMask(team)
local genderMask = maskData[playerGender]
if genderMask then
SetPedComponentVariation(ped, genderMask.component, genderMask.drawable, genderMask.texture, 0)
debugPrint("Maske gesetzt: " .. team .. " (" .. playerGender .. ")")
else
debugPrint("Keine Maske für " .. team .. " (" .. playerGender .. ") gefunden!")
end
else
debugPrint("Keine Masken-Daten für Team " .. team .. " gefunden!")
end
end
@ -304,6 +340,7 @@ function createTeamZoneBlip(team, fieldConfig)
SetBlipAlpha(blip, 128)
teamZoneBlips[team] = blip
debugPrint("Team Zone Blip erstellt für " .. team)
end
function removeTeamZoneBlips()
@ -313,6 +350,7 @@ function removeTeamZoneBlips()
end
end
teamZoneBlips = {}
debugPrint("Team Zone Blips entfernt")
end
function highlightTeamZone(team)
@ -459,6 +497,7 @@ function openJoinGameMenu(fieldId)
})
return
end
TriggerServerEvent('tdm:requestGamesList')
Wait(200)
@ -573,25 +612,14 @@ CreateThread(function()
local ped = PlayerPedId()
if HasEntityBeenDamagedByAnyPed(ped) then
local damager = NetworkGetEntityKillerOfPlayer(PlayerId())
local damager = GetPedSourceOfDeath(ped)
local damagerPlayer = nil
-- Versuche den Angreifer zu identifizieren
if damager > 0 then
damagerPlayer = NetworkGetPlayerIndexFromPed(damager)
if damagerPlayer then
damagerPlayer = GetPlayerServerId(damagerPlayer)
end
end
-- Alternativ über alle Spieler suchen
if not damagerPlayer then
for _, player in ipairs(GetActivePlayers()) do
local playerPed = GetPlayerPed(player)
if playerPed == GetPedSourceOfDeath(ped) then
damagerPlayer = GetPlayerServerId(player)
break
end
for _, player in ipairs(GetActivePlayers()) do
if GetPlayerPed(player) == damager then
damagerPlayer = GetPlayerServerId(player)
break
end
end
@ -600,6 +628,8 @@ CreateThread(function()
-- Lokale Stats sofort updaten
playerStats.deaths = playerStats.deaths + 1
debugPrint("Getroffen von: " .. (damagerPlayer or "Unbekannt"))
TriggerEvent('tdm:playerHit')
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, damagerPlayer)
end
@ -616,6 +646,8 @@ CreateThread(function()
local ped = PlayerPedId()
if IsEntityDead(ped) then
debugPrint("Spieler ist tot!")
TriggerServerEvent('tdm:playerDied', currentGameId)
lib.notify({
@ -678,6 +710,8 @@ CreateThread(function()
},
distance = 2.5
})
debugPrint("NPC und Blip für Feld " .. fieldId .. " erstellt")
else
print("^3[TDM WARNING]^7 Feld " .. fieldId .. " hat keine vollständige Lobby-Konfiguration!")
end
@ -725,6 +759,10 @@ RegisterCommand('debugtdm', function()
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)
print("^2[TDM DEBUG]^7 Verfügbare Felder:")
for fieldId, fieldData in pairs(Config.gameFields) do
@ -786,15 +824,18 @@ RegisterCommand('forcetdmrespawn', function()
local randomSpawn = spawnPoints[math.random(#spawnPoints)]
DoScreenFadeOut(500)
Wait(500)
Wait(600)
ClearPedTasks(ped)
ClearPedTasksImmediately(ped)
SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z)
isHit = false
Wait(100)
DoScreenFadeIn(500)
lib.notify({
title = 'Debug',
description = 'Manueller Respawn durchgeführt
lib.notify({
title = 'Debug',
description = 'Manueller Respawn durchgeführt!',
@ -808,4 +849,64 @@ RegisterCommand('forcetdmrespawn', function()
})
end
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)
if currentGameId then
TriggerServerEvent('tdm:debugPlayerStats', currentGameId)
end
lib.notify({
title = 'Debug',
description = 'Lokale Stats - Hits: ' .. playerStats.hits .. ', Deaths: ' .. playerStats.deaths,
type = 'info'
})
else
lib.notify({
title = 'Debug',
description = 'Du bist nicht in einem TDM-Spiel!',
type = 'error'
})
end
end, false)
-- Debug-Funktion für manuellen Hit
RegisterCommand('testhit', function()
if inTDM then
TriggerEvent('tdm:playerHit')
lib.notify({
title = 'Debug',
description = 'Test-Hit ausgelöst!',
type = 'info'
})
else
lib.notify({
title = 'Debug',
description = 'Du bist nicht in einem TDM-Spiel!',
type = 'error'
})
end
end, false)
-- Debug-Funktion für manuellen Treffer
RegisterCommand('testtreff', function()
if inTDM then
TriggerEvent('tdm:hitRegistered')
lib.notify({
title = 'Debug',
description = 'Test-Treffer registriert!',
type = 'info'
})
else
lib.notify({
title = 'Debug',
description = 'Du bist nicht in einem TDM-Spiel!',
type = 'error'
})
end
end, false)