forked from Simnation/Main
ed
This commit is contained in:
parent
7fb00900b0
commit
e6e25aa23e
2 changed files with 126 additions and 134 deletions
|
@ -171,6 +171,10 @@ RegisterNetEvent('tdm:playerHit', function()
|
|||
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)
|
||||
|
||||
|
@ -185,6 +189,10 @@ RegisterNetEvent('tdm:playerHit', function()
|
|||
SetBlipFlashes(teamZoneBlips[currentTeam], false)
|
||||
end
|
||||
|
||||
-- Bildschirm wieder einblenden
|
||||
Wait(100)
|
||||
DoScreenFadeIn(500)
|
||||
|
||||
lib.notify({
|
||||
title = 'TeamDeathmatch',
|
||||
description = 'Du bist wieder im Spiel!',
|
||||
|
@ -451,7 +459,6 @@ function openJoinGameMenu(fieldId)
|
|||
})
|
||||
return
|
||||
end
|
||||
|
||||
TriggerServerEvent('tdm:requestGamesList')
|
||||
|
||||
Wait(200)
|
||||
|
@ -566,15 +573,27 @@ CreateThread(function()
|
|||
local ped = PlayerPedId()
|
||||
|
||||
if HasEntityBeenDamagedByAnyPed(ped) then
|
||||
local damager = GetPedSourceOfDeath(ped)
|
||||
local damager = NetworkGetEntityKillerOfPlayer(PlayerId())
|
||||
local damagerPlayer = nil
|
||||
|
||||
for _, player in pairs(GetActivePlayers()) do
|
||||
if GetPlayerPed(player) == damager then
|
||||
-- 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
|
||||
end
|
||||
end
|
||||
|
||||
ClearEntityLastDamageEntity(ped)
|
||||
|
||||
|
@ -678,7 +697,6 @@ RegisterNetEvent('tdm:openFieldMenu', function(data)
|
|||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Chat Command zum Spiel verlassen
|
||||
RegisterCommand('leavetdm', function()
|
||||
if inTDM then
|
||||
|
@ -758,3 +776,36 @@ RegisterCommand('removemask', function()
|
|||
type = 'info'
|
||||
})
|
||||
end, false)
|
||||
|
||||
-- Debug-Funktion für Respawn
|
||||
RegisterCommand('forcetdmrespawn', function()
|
||||
if inTDM and currentTeam and currentField then
|
||||
local ped = PlayerPedId()
|
||||
local fieldConfig = Config.gameFields[currentField]
|
||||
local spawnPoints = fieldConfig.teamSpawns[currentTeam]
|
||||
local randomSpawn = spawnPoints[math.random(#spawnPoints)]
|
||||
|
||||
DoScreenFadeOut(500)
|
||||
Wait(500)
|
||||
|
||||
ClearPedTasks(ped)
|
||||
SetEntityCoords(ped, randomSpawn.x, randomSpawn.y, randomSpawn.z)
|
||||
isHit = false
|
||||
|
||||
Wait(100)
|
||||
DoScreenFadeIn(500)
|
||||
|
||||
lib.notify({
|
||||
title = 'Debug',
|
||||
description = 'Manueller Respawn durchgeführt!',
|
||||
type = 'success'
|
||||
})
|
||||
else
|
||||
lib.notify({
|
||||
title = 'Debug',
|
||||
description = 'Du bist nicht in einem TDM-Spiel!',
|
||||
type = 'error'
|
||||
})
|
||||
end
|
||||
end, false)
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ RegisterNetEvent('tdm:createGame', function(gameName, fieldId, gameType, passwor
|
|||
score = {team1 = 0, team2 = 0},
|
||||
startTime = nil,
|
||||
maxTime = Config.maxGameTime,
|
||||
maxHits = Config.maxHits
|
||||
maxHits = Config.maxHits,
|
||||
playerStats = {} -- Spieler-Statistiken initialisieren
|
||||
}
|
||||
|
||||
local typeText = gameType == 'public' and 'öffentliches' or 'privates'
|
||||
|
@ -132,44 +133,50 @@ RegisterNetEvent('tdm:leaveGame', function()
|
|||
TriggerClientEvent('tdm:leaveGame', src)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('tdm:playerWasHit', function(gameId, victimTeam, shooterId)
|
||||
local src = source
|
||||
RegisterNetEvent('tdm:playerWasHit', function(gameId, victimTeam, attackerId)
|
||||
local victim = source
|
||||
|
||||
if not activeGames[gameId] then return end
|
||||
|
||||
local game = activeGames[gameId]
|
||||
|
||||
if not game then return end
|
||||
|
||||
local shooterTeam = nil
|
||||
if shooterId then
|
||||
for _, playerId in ipairs(game.team1) do
|
||||
if playerId == shooterId then
|
||||
shooterTeam = 'team1'
|
||||
break
|
||||
end
|
||||
end
|
||||
if not shooterTeam then
|
||||
for _, playerId in ipairs(game.team2) do
|
||||
if playerId == shooterId then
|
||||
shooterTeam = 'team2'
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Spieler Stats initialisieren falls nicht vorhanden
|
||||
if not game.playerStats then
|
||||
game.playerStats = {}
|
||||
end
|
||||
|
||||
if shooterTeam and shooterTeam ~= victimTeam then
|
||||
game.score[shooterTeam] = game.score[shooterTeam] + 1
|
||||
|
||||
if shooterId then
|
||||
TriggerClientEvent('tdm:hitRegistered', shooterId)
|
||||
if not game.playerStats[victim] then
|
||||
game.playerStats[victim] = {hits = 0, deaths = 0}
|
||||
end
|
||||
|
||||
TriggerClientEvent('tdm:deathRegistered', src)
|
||||
if attackerId and not game.playerStats[attackerId] then
|
||||
game.playerStats[attackerId] = {hits = 0, deaths = 0}
|
||||
end
|
||||
|
||||
-- Stats updaten
|
||||
game.playerStats[victim].deaths = (game.playerStats[victim].deaths or 0) + 1
|
||||
|
||||
if attackerId then
|
||||
game.playerStats[attackerId].hits = (game.playerStats[attackerId].hits or 0) + 1
|
||||
TriggerClientEvent('tdm:hitRegistered', attackerId)
|
||||
end
|
||||
|
||||
-- Team Score erhöhen
|
||||
if victimTeam == 'team1' then
|
||||
game.score.team2 = game.score.team2 + 1
|
||||
else
|
||||
game.score.team1 = game.score.team1 + 1
|
||||
end
|
||||
|
||||
TriggerClientEvent('tdm:deathRegistered', victim)
|
||||
|
||||
-- Score an alle Spieler senden
|
||||
updateScoreForGame(gameId)
|
||||
|
||||
if game.score[shooterTeam] >= game.maxHits then
|
||||
endGame(gameId, shooterTeam)
|
||||
end
|
||||
-- Spiel beenden prüfen
|
||||
if game.score.team1 >= game.maxHits or game.score.team2 >= game.maxHits then
|
||||
local winnerTeam = game.score.team1 >= game.maxHits and 'team1' or 'team2'
|
||||
endGame(gameId, winnerTeam)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -178,6 +185,14 @@ RegisterNetEvent('tdm:playerDied', function(gameId)
|
|||
removePlayerFromGame(src, gameId)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('tdm:requestScoreUpdate', function(gameId)
|
||||
local src = source
|
||||
|
||||
if activeGames[gameId] then
|
||||
updateScoreForGame(gameId)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Funktionen
|
||||
function joinPlayerToGame(playerId, gameId)
|
||||
local game = activeGames[gameId]
|
||||
|
@ -188,6 +203,13 @@ function joinPlayerToGame(playerId, gameId)
|
|||
|
||||
table.insert(game[team], playerId)
|
||||
|
||||
-- Spieler-Stats initialisieren
|
||||
if not game.playerStats then
|
||||
game.playerStats = {}
|
||||
end
|
||||
|
||||
game.playerStats[playerId] = {hits = 0, deaths = 0}
|
||||
|
||||
-- Spiel starten wenn mindestens 2 Spieler
|
||||
if #game.team1 + #game.team2 >= 2 and game.status == 'waiting' then
|
||||
game.status = 'active'
|
||||
|
@ -301,16 +323,20 @@ function updateScoreForGame(gameId)
|
|||
local game = activeGames[gameId]
|
||||
if not game then return end
|
||||
|
||||
local gameStats = {
|
||||
totalHits = game.score.team1 + game.score.team2,
|
||||
gameTime = game.startTime and (os.time() - game.startTime) or 0
|
||||
}
|
||||
|
||||
for _, playerId in ipairs(game.team1) do
|
||||
TriggerClientEvent('tdm:updateScore', playerId, game.score.team1, game.score.team2, gameStats)
|
||||
local playerStats = game.playerStats[playerId] or {hits = 0, deaths = 0}
|
||||
TriggerClientEvent('tdm:updateScore', playerId, game.score.team1, game.score.team2, {
|
||||
hits = playerStats.hits or 0,
|
||||
deaths = playerStats.deaths or 0
|
||||
})
|
||||
end
|
||||
|
||||
for _, playerId in ipairs(game.team2) do
|
||||
TriggerClientEvent('tdm:updateScore', playerId, game.score.team1, game.score.team2, gameStats)
|
||||
local playerStats = game.playerStats[playerId] or {hits = 0, deaths = 0}
|
||||
TriggerClientEvent('tdm:updateScore', playerId, game.score.team1, game.score.team2, {
|
||||
hits = playerStats.hits or 0,
|
||||
deaths = playerStats.deaths or 0
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -360,88 +386,3 @@ AddEventHandler('onResourceStop', function(resourceName)
|
|||
print('[TDM] TeamDeathmatch System gestoppt!')
|
||||
end
|
||||
end)
|
||||
|
||||
-- In server.lua hinzufügen
|
||||
RegisterNetEvent('tdm:requestScoreUpdate', function(gameId)
|
||||
local src = source
|
||||
|
||||
if activeGames[gameId] then
|
||||
local game = activeGames[gameId]
|
||||
|
||||
-- Score an alle Spieler senden
|
||||
for _, playerId in pairs(game.team1) do
|
||||
TriggerClientEvent('tdm:updateScore', playerId, game.team1Score, game.team2Score, {
|
||||
hits = game.playerStats[playerId] and game.playerStats[playerId].hits or 0,
|
||||
deaths = game.playerStats[playerId] and game.playerStats[playerId].deaths or 0
|
||||
})
|
||||
end
|
||||
|
||||
for _, playerId in pairs(game.team2) do
|
||||
TriggerClientEvent('tdm:updateScore', playerId, game.team1Score, game.team2Score, {
|
||||
hits = game.playerStats[playerId] and game.playerStats[playerId].hits or 0,
|
||||
deaths = game.playerStats[playerId] and game.playerStats[playerId].deaths or 0
|
||||
})
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Erweiterte playerWasHit Event
|
||||
RegisterNetEvent('tdm:playerWasHit', function(gameId, victimTeam, attackerId)
|
||||
local victim = source
|
||||
|
||||
if not activeGames[gameId] then return end
|
||||
|
||||
local game = activeGames[gameId]
|
||||
|
||||
-- Spieler Stats initialisieren falls nicht vorhanden
|
||||
if not game.playerStats then
|
||||
game.playerStats = {}
|
||||
end
|
||||
|
||||
if not game.playerStats[victim] then
|
||||
game.playerStats[victim] = {hits = 0, deaths = 0}
|
||||
end
|
||||
|
||||
if attackerId and not game.playerStats[attackerId] then
|
||||
game.playerStats[attackerId] = {hits = 0, deaths = 0}
|
||||
end
|
||||
|
||||
-- Stats updaten
|
||||
game.playerStats[victim].deaths = game.playerStats[victim].deaths + 1
|
||||
|
||||
if attackerId then
|
||||
game.playerStats[attackerId].hits = game.playerStats[attackerId].hits + 1
|
||||
TriggerClientEvent('tdm:hitRegistered', attackerId)
|
||||
end
|
||||
|
||||
-- Team Score erhöhen
|
||||
if victimTeam == 'team1' then
|
||||
game.team2Score = game.team2Score + 1
|
||||
else
|
||||
game.team1Score = game.team1Score + 1
|
||||
end
|
||||
|
||||
TriggerClientEvent('tdm:deathRegistered', victim)
|
||||
|
||||
-- Score an alle Spieler senden
|
||||
local allPlayers = {}
|
||||
for _, playerId in pairs(game.team1) do
|
||||
table.insert(allPlayers, playerId)
|
||||
end
|
||||
for _, playerId in pairs(game.team2) do
|
||||
table.insert(allPlayers, playerId)
|
||||
end
|
||||
|
||||
for _, playerId in pairs(allPlayers) do
|
||||
TriggerClientEvent('tdm:updateScore', playerId, game.team1Score, game.team2Score, {
|
||||
hits = game.playerStats[playerId] and game.playerStats[playerId].hits or 0,
|
||||
deaths = game.playerStats[playerId] and game.playerStats[playerId].deaths or 0
|
||||
})
|
||||
end
|
||||
|
||||
-- Spiel beenden prüfen
|
||||
if game.team1Score >= Config.maxHits or game.team2Score >= Config.maxHits then
|
||||
local winnerTeam = game.team1Score >= Config.maxHits and 'team1' or 'team2'
|
||||
endGame(gameId, winnerTeam)
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue