1
0
Fork 0
forked from Simnation/Main

Update server.lua

This commit is contained in:
Nordi98 2025-07-26 21:31:15 +02:00
parent 0686dcdea2
commit 7fb00900b0

View file

@ -361,3 +361,87 @@ AddEventHandler('onResourceStop', function(resourceName)
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)