forked from Simnation/Main
ed
This commit is contained in:
parent
eec7910283
commit
7def30a2ec
2 changed files with 216 additions and 109 deletions
|
@ -8,6 +8,13 @@ local teamZoneBlips = {}
|
|||
local isHit = false
|
||||
local activeGames = {}
|
||||
|
||||
-- Spieler Statistiken
|
||||
local playerStats = {
|
||||
hits = 0,
|
||||
deaths = 0,
|
||||
gamesPlayed = 0
|
||||
}
|
||||
|
||||
-- Events
|
||||
RegisterNetEvent('tdm:updateGamesList', function(games)
|
||||
activeGames = games
|
||||
|
@ -20,6 +27,11 @@ RegisterNetEvent('tdm:joinGame', function(gameId, team, fieldId)
|
|||
inTDM = true
|
||||
isHit = false
|
||||
|
||||
-- Stats zurücksetzen
|
||||
playerStats.hits = 0
|
||||
playerStats.deaths = 0
|
||||
playerStats.gamesPlayed = playerStats.gamesPlayed + 1
|
||||
|
||||
local fieldConfig = Config.gameFields[fieldId]
|
||||
|
||||
-- Teleport zu Team Spawn
|
||||
|
@ -57,6 +69,8 @@ RegisterNetEvent('tdm:leaveGame', function()
|
|||
-- Zone Blips entfernen
|
||||
removeTeamZoneBlips()
|
||||
|
||||
lib.hideTextUI()
|
||||
|
||||
lib.notify({
|
||||
title = 'TeamDeathmatch',
|
||||
description = 'Du hast das Spiel verlassen!',
|
||||
|
@ -123,19 +137,64 @@ RegisterNetEvent('tdm:playerHit', function()
|
|||
highlightTeamZone(currentTeam)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score)
|
||||
lib.showTextUI('[Team 1: ' .. team1Score .. '] VS [Team 2: ' .. team2Score .. ']', {
|
||||
RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score, gameStats)
|
||||
local displayText = string.format(
|
||||
'[Team 1: %d] VS [Team 2: %d] | Deine Treffer: %d | Tode: %d',
|
||||
team1Score,
|
||||
team2Score,
|
||||
playerStats.hits,
|
||||
playerStats.deaths
|
||||
)
|
||||
|
||||
lib.showTextUI(displayText, {
|
||||
position = "top-center",
|
||||
icon = 'crosshairs'
|
||||
})
|
||||
end)
|
||||
|
||||
RegisterNetEvent('tdm:hitRegistered', function()
|
||||
playerStats.hits = playerStats.hits + 1
|
||||
|
||||
lib.notify({
|
||||
title = 'Treffer!',
|
||||
description = 'Du hast einen Gegner getroffen! (+1 Punkt)',
|
||||
type = 'success',
|
||||
duration = 2000
|
||||
})
|
||||
|
||||
showHitMarker()
|
||||
end)
|
||||
|
||||
RegisterNetEvent('tdm:deathRegistered', function()
|
||||
playerStats.deaths = playerStats.deaths + 1
|
||||
end)
|
||||
|
||||
RegisterNetEvent('tdm:gameEnded', function(winnerTeam, team1Score, team2Score)
|
||||
lib.hideTextUI()
|
||||
|
||||
local wonGame = (currentTeam == 'team1' and winnerTeam == 'team1') or (currentTeam == 'team2' and winnerTeam == 'team2')
|
||||
local resultText = wonGame and '🏆 GEWONNEN!' or '💀 VERLOREN!'
|
||||
|
||||
local statsText = string.format(
|
||||
'%s\n\n' ..
|
||||
'Endergebnis:\n' ..
|
||||
'Team 1: %d Punkte\n' ..
|
||||
'Team 2: %d Punkte\n\n' ..
|
||||
'Deine Statistiken:\n' ..
|
||||
'🎯 Treffer: %d\n' ..
|
||||
'💀 Tode: %d\n' ..
|
||||
'📊 K/D: %.2f',
|
||||
resultText,
|
||||
team1Score,
|
||||
team2Score,
|
||||
playerStats.hits,
|
||||
playerStats.deaths,
|
||||
playerStats.deaths > 0 and (playerStats.hits / playerStats.deaths) or playerStats.hits
|
||||
)
|
||||
|
||||
local alert = lib.alertDialog({
|
||||
header = 'Spiel beendet!',
|
||||
content = 'Team ' .. winnerTeam .. ' hat gewonnen!\n\nTeam 1: ' .. team1Score .. '\nTeam 2: ' .. team2Score,
|
||||
content = statsText,
|
||||
centered = true,
|
||||
cancel = false
|
||||
})
|
||||
|
@ -180,10 +239,34 @@ function highlightTeamZone(team)
|
|||
end
|
||||
end
|
||||
|
||||
function showHitMarker()
|
||||
CreateThread(function()
|
||||
local startTime = GetGameTimer()
|
||||
|
||||
while GetGameTimer() - startTime < 500 do
|
||||
Wait(0)
|
||||
|
||||
-- Rotes X in der Mitte des Bildschirms
|
||||
DrawRect(0.5, 0.5, 0.02, 0.002, 255, 0, 0, 255) -- Horizontale Linie
|
||||
DrawRect(0.5, 0.5, 0.002, 0.02, 255, 0, 0, 255) -- Vertikale Linie
|
||||
|
||||
-- Text
|
||||
SetTextFont(4)
|
||||
SetTextProportional(1)
|
||||
SetTextScale(0.5, 0.5)
|
||||
SetTextColour(255, 0, 0, 255)
|
||||
SetTextEntry("STRING")
|
||||
AddTextComponentString("TREFFER!")
|
||||
SetTextCentre(true)
|
||||
DrawText(0.5, 0.45)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function openMainMenu()
|
||||
TriggerServerEvent('tdm:requestGamesList')
|
||||
|
||||
Wait(100) -- Kurz warten für Server Response
|
||||
Wait(100)
|
||||
|
||||
local options = {
|
||||
{
|
||||
|
@ -228,7 +311,6 @@ end
|
|||
function openCreateGameMenu()
|
||||
local fieldOptions = {}
|
||||
|
||||
-- Spielfelder zu Options hinzufügen
|
||||
for fieldId, fieldData in pairs(Config.gameFields) do
|
||||
table.insert(fieldOptions, {
|
||||
value = fieldId,
|
||||
|
@ -273,7 +355,7 @@ function openCreateGameMenu()
|
|||
|
||||
local gameName = input[1]
|
||||
local fieldId = input[2]
|
||||
local gameType = input[3] -- 'public' oder 'private'
|
||||
local gameType = input[3]
|
||||
local password = input[4] and input[4] ~= '' and input[4] or nil
|
||||
|
||||
if gameName and fieldId and gameType then
|
||||
|
@ -348,7 +430,6 @@ function openJoinGameMenu()
|
|||
lib.showContext('tdm_join_menu')
|
||||
end
|
||||
|
||||
|
||||
-- Zone Checker Thread
|
||||
CreateThread(function()
|
||||
while true do
|
||||
|
@ -424,9 +505,19 @@ CreateThread(function()
|
|||
local ped = PlayerPedId()
|
||||
|
||||
if HasEntityBeenDamagedByAnyPed(ped) then
|
||||
local damager = GetPedSourceOfDeath(ped)
|
||||
local damagerPlayer = nil
|
||||
|
||||
for _, player in pairs(GetActivePlayers()) do
|
||||
if GetPlayerPed(player) == damager then
|
||||
damagerPlayer = GetPlayerServerId(player)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
ClearEntityLastDamageEntity(ped)
|
||||
TriggerEvent('tdm:playerHit')
|
||||
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam)
|
||||
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, damagerPlayer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue