forked from Simnation/Main
ed
This commit is contained in:
parent
cddc8d3aad
commit
a65aa5a77e
2 changed files with 213 additions and 70 deletions
|
@ -4,6 +4,11 @@ local QBCore = exports['qb-core']:GetCoreObject()
|
|||
local activeGames = {}
|
||||
local gameIdCounter = 1
|
||||
|
||||
-- Debug-Funktion für Konsole
|
||||
local function debugPrint(message)
|
||||
print("^2[TDM SERVER]^7 " .. message)
|
||||
end
|
||||
|
||||
-- Events
|
||||
RegisterNetEvent('tdm:createGame', function(gameName, fieldId, gameType, password)
|
||||
local src = source
|
||||
|
@ -45,6 +50,7 @@ RegisterNetEvent('tdm:createGame', function(gameName, fieldId, gameType, passwor
|
|||
TriggerClientEvent('QBCore:Notify', src, 'Dein ' .. typeText .. ' Spiel "' .. gameName .. '" wurde erstellt!', 'success')
|
||||
|
||||
updateGamesListForAll()
|
||||
debugPrint("Spiel erstellt: " .. gameId .. " von " .. Player.PlayerData.name)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('tdm:requestGamesList', function()
|
||||
|
@ -136,7 +142,10 @@ end)
|
|||
RegisterNetEvent('tdm:playerWasHit', function(gameId, victimTeam, attackerId)
|
||||
local victim = source
|
||||
|
||||
if not activeGames[gameId] then return end
|
||||
if not activeGames[gameId] then
|
||||
debugPrint("Hit registriert, aber Spiel " .. gameId .. " existiert nicht!")
|
||||
return
|
||||
end
|
||||
|
||||
local game = activeGames[gameId]
|
||||
|
||||
|
@ -159,6 +168,9 @@ RegisterNetEvent('tdm:playerWasHit', function(gameId, victimTeam, attackerId)
|
|||
if attackerId then
|
||||
game.playerStats[attackerId].hits = (game.playerStats[attackerId].hits or 0) + 1
|
||||
TriggerClientEvent('tdm:hitRegistered', attackerId)
|
||||
debugPrint("Treffer von " .. attackerId .. " gegen " .. victim)
|
||||
else
|
||||
debugPrint("Treffer gegen " .. victim .. " von unbekanntem Angreifer")
|
||||
end
|
||||
|
||||
-- Team Score erhöhen
|
||||
|
@ -193,6 +205,18 @@ RegisterNetEvent('tdm:requestScoreUpdate', function(gameId)
|
|||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('tdm:debugPlayerStats', function(gameId)
|
||||
local src = source
|
||||
if activeGames[gameId] and activeGames[gameId].playerStats and activeGames[gameId].playerStats[src] then
|
||||
local stats = activeGames[gameId].playerStats[src]
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Server Stats - Hits: ' .. (stats.hits or 0) .. ', Deaths: ' .. (stats.deaths or 0), 'info')
|
||||
debugPrint("Stats für Spieler " .. src .. ": Hits=" .. (stats.hits or 0) .. ", Deaths=" .. (stats.deaths or 0))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Keine Stats gefunden!', 'error')
|
||||
debugPrint("Keine Stats für Spieler " .. src .. " in Spiel " .. gameId)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Funktionen
|
||||
function joinPlayerToGame(playerId, gameId)
|
||||
local game = activeGames[gameId]
|
||||
|
@ -222,6 +246,8 @@ function joinPlayerToGame(playerId, gameId)
|
|||
TriggerClientEvent('tdm:joinGame', playerId, gameId, team, game.fieldId)
|
||||
updateScoreForGame(gameId)
|
||||
updateGamesListForAll()
|
||||
|
||||
debugPrint("Spieler " .. playerId .. " ist Spiel " .. gameId .. " beigetreten (Team: " .. team .. ")")
|
||||
end
|
||||
|
||||
function removePlayerFromGame(playerId, gameId)
|
||||
|
@ -232,6 +258,7 @@ function removePlayerFromGame(playerId, gameId)
|
|||
for i, id in ipairs(game.team1) do
|
||||
if id == playerId then
|
||||
table.remove(game.team1, i)
|
||||
debugPrint("Spieler " .. playerId .. " aus Team 1 entfernt")
|
||||
break
|
||||
end
|
||||
end
|
||||
|
@ -239,6 +266,7 @@ function removePlayerFromGame(playerId, gameId)
|
|||
for i, id in ipairs(game.team2) do
|
||||
if id == playerId then
|
||||
table.remove(game.team2, i)
|
||||
debugPrint("Spieler " .. playerId .. " aus Team 2 entfernt")
|
||||
break
|
||||
end
|
||||
end
|
||||
|
@ -279,7 +307,9 @@ function endGame(gameId, winnerTeam, reason)
|
|||
end)
|
||||
|
||||
if reason then
|
||||
print('[TDM] Spiel ' .. gameId .. ' beendet: ' .. reason)
|
||||
debugPrint("Spiel " .. gameId .. " beendet: " .. reason)
|
||||
else
|
||||
debugPrint("Spiel " .. gameId .. " beendet. Gewinner: " .. (winnerTeam or "Unentschieden"))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -291,9 +321,16 @@ function startGameTimer(gameId)
|
|||
local maxTime = game.maxTime
|
||||
local startTime = os.time()
|
||||
|
||||
debugPrint("Timer für Spiel " .. gameId .. " gestartet. Maximale Zeit: " .. maxTime .. " Sekunden")
|
||||
|
||||
while game and game.status == 'active' and (os.time() - startTime) < maxTime do
|
||||
Wait(1000)
|
||||
game = activeGames[gameId] -- Refresh game data
|
||||
|
||||
-- Alle 30 Sekunden Debug-Info
|
||||
if (os.time() - startTime) % 30 == 0 then
|
||||
debugPrint("Spiel " .. gameId .. " läuft seit " .. (os.time() - startTime) .. " Sekunden")
|
||||
end
|
||||
end
|
||||
|
||||
-- Zeit abgelaufen
|
||||
|
@ -316,6 +353,7 @@ function checkGameEnd(gameId)
|
|||
elseif totalPlayers == 0 then
|
||||
activeGames[gameId] = nil
|
||||
updateGamesListForAll()
|
||||
debugPrint("Spiel " .. gameId .. " gelöscht (keine Spieler)")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -323,6 +361,8 @@ function updateScoreForGame(gameId)
|
|||
local game = activeGames[gameId]
|
||||
if not game then return end
|
||||
|
||||
debugPrint("Score Update für Spiel " .. gameId .. ": Team1=" .. game.score.team1 .. ", Team2=" .. game.score.team2)
|
||||
|
||||
for _, playerId in ipairs(game.team1) do
|
||||
local playerStats = game.playerStats[playerId] or {hits = 0, deaths = 0}
|
||||
TriggerClientEvent('tdm:updateScore', playerId, game.score.team1, game.score.team2, {
|
||||
|
@ -354,6 +394,8 @@ AddEventHandler('playerDropped', function()
|
|||
for gameId, game in pairs(activeGames) do
|
||||
removePlayerFromGame(src, gameId)
|
||||
end
|
||||
|
||||
debugPrint("Spieler " .. src .. " hat den Server verlassen - aus allen Spielen entfernt")
|
||||
end)
|
||||
|
||||
-- Server Start - Games Liste leeren
|
||||
|
@ -361,7 +403,7 @@ AddEventHandler('onResourceStart', function(resourceName)
|
|||
if GetCurrentResourceName() == resourceName then
|
||||
activeGames = {}
|
||||
gameIdCounter = 1
|
||||
print('[TDM] TeamDeathmatch System gestartet!')
|
||||
debugPrint("TeamDeathmatch System gestartet!")
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -383,6 +425,6 @@ AddEventHandler('onResourceStop', function(resourceName)
|
|||
end
|
||||
|
||||
activeGames = {}
|
||||
print('[TDM] TeamDeathmatch System gestoppt!')
|
||||
debugPrint("TeamDeathmatch System gestoppt!")
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue