forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
0b3fe80767
commit
2834b543f4
1 changed files with 65 additions and 112 deletions
|
@ -9,9 +9,6 @@ local teamZoneBlips = {}
|
||||||
local isHit = false
|
local isHit = false
|
||||||
local activeGames = {}
|
local activeGames = {}
|
||||||
local spawnedNPCs = {}
|
local spawnedNPCs = {}
|
||||||
local lastDamager = nil
|
|
||||||
local lastDamageTime = 0
|
|
||||||
local lastDamageWeapon = 0
|
|
||||||
|
|
||||||
-- Spieler Statistiken
|
-- Spieler Statistiken
|
||||||
local playerStats = {
|
local playerStats = {
|
||||||
|
@ -25,31 +22,14 @@ local function debugPrint(message)
|
||||||
print("^2[TDM DEBUG]^7 " .. message)
|
print("^2[TDM DEBUG]^7 " .. message)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Helper function to dump tables for debugging
|
|
||||||
function dumpTable(table, indent)
|
|
||||||
if not indent then indent = 0 end
|
|
||||||
for k, v in pairs(table) do
|
|
||||||
local formatting = string.rep(" ", indent) .. k .. ": "
|
|
||||||
if type(v) == "table" then
|
|
||||||
print(formatting)
|
|
||||||
dumpTable(v, indent+1)
|
|
||||||
else
|
|
||||||
print(formatting .. tostring(v))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Funktion zum Prüfen, ob eine Waffe eine Airsoft-Waffe ist
|
-- Funktion zum Prüfen, ob eine Waffe eine Airsoft-Waffe ist
|
||||||
function isAirsoftWeapon(weaponHash)
|
function isAirsoftWeapon(weaponHash)
|
||||||
return Config.airsoftWeapons[weaponHash] or Config.treatAllWeaponsAsAirsoft
|
return Config.airsoftWeapons[weaponHash] or Config.treatAllWeaponsAsAirsoft
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Enhanced function to check if a player is in ragdoll state
|
-- Funktion zum Prüfen, ob der Spieler im Ragdoll-Zustand ist
|
||||||
function isPedInRagdoll(ped)
|
function isPedInRagdoll(ped)
|
||||||
return IsPedRagdoll(ped) or
|
return IsPedRagdoll(ped) or IsPedFalling(ped) or IsPedDiving(ped)
|
||||||
IsPedFalling(ped) or
|
|
||||||
IsPedDiving(ped) or
|
|
||||||
(not IsPedStill(ped) and IsPedOnFoot(ped) and not IsPedWalking(ped) and not IsPedRunning(ped) and not IsPedSprinting(ped))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Events
|
-- Events
|
||||||
|
@ -100,9 +80,6 @@ RegisterNetEvent('tdm:leaveGame', function()
|
||||||
currentGameId = nil
|
currentGameId = nil
|
||||||
currentField = nil
|
currentField = nil
|
||||||
isHit = false
|
isHit = false
|
||||||
lastDamager = nil
|
|
||||||
lastDamageTime = 0
|
|
||||||
lastDamageWeapon = 0
|
|
||||||
|
|
||||||
-- Sichere Rückkehr zur Lobby
|
-- Sichere Rückkehr zur Lobby
|
||||||
local lobbyPos = nil
|
local lobbyPos = nil
|
||||||
|
@ -265,28 +242,15 @@ RegisterNetEvent('tdm:playerHit', function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score, gameStats)
|
RegisterNetEvent('tdm:updateScore', function(team1Score, team2Score, gameStats)
|
||||||
-- Enhanced debug output
|
-- Debug-Ausgabe
|
||||||
debugPrint("Score Update empfangen: Team1=" .. team1Score .. ", Team2=" .. team2Score)
|
debugPrint("Score Update empfangen: Team1=" .. team1Score .. ", Team2=" .. team2Score)
|
||||||
if gameStats then
|
if gameStats then
|
||||||
debugPrint("GameStats received: ")
|
debugPrint("GameStats: Hits=" .. (gameStats.hits or "nil") .. ", Deaths=" .. (gameStats.deaths or "nil"))
|
||||||
dumpTable(gameStats)
|
|
||||||
else
|
|
||||||
debugPrint("WARNING: No gameStats received from server!")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- More robust handling of stats
|
-- Verwende gameStats falls verfügbar, sonst lokale Stats
|
||||||
local myHits = 0
|
local myHits = gameStats and gameStats.hits or playerStats.hits
|
||||||
local myDeaths = 0
|
local myDeaths = gameStats and gameStats.deaths or playerStats.deaths
|
||||||
|
|
||||||
if gameStats and type(gameStats) == "table" then
|
|
||||||
myHits = gameStats.hits or 0
|
|
||||||
myDeaths = gameStats.deaths or 0
|
|
||||||
debugPrint("Using server stats: Hits=" .. myHits .. ", Deaths=" .. myDeaths)
|
|
||||||
else
|
|
||||||
myHits = playerStats.hits
|
|
||||||
myDeaths = playerStats.deaths
|
|
||||||
debugPrint("Using local stats: Hits=" .. myHits .. ", Deaths=" .. myDeaths)
|
|
||||||
end
|
|
||||||
|
|
||||||
local displayText = string.format(
|
local displayText = string.format(
|
||||||
'[Team 1: %d] VS [Team 2: %d] | Deine Treffer: %d | Tode: %d',
|
'[Team 1: %d] VS [Team 2: %d] | Deine Treffer: %d | Tode: %d',
|
||||||
|
@ -694,12 +658,6 @@ CreateThread(function()
|
||||||
-- Versuche die Waffe zu ermitteln
|
-- Versuche die Waffe zu ermitteln
|
||||||
weaponHash = GetSelectedPedWeapon(playerPed)
|
weaponHash = GetSelectedPedWeapon(playerPed)
|
||||||
debugPrint("Angreifer identifiziert: " .. damagerPlayer .. " mit Waffe: " .. weaponHash)
|
debugPrint("Angreifer identifiziert: " .. damagerPlayer .. " mit Waffe: " .. weaponHash)
|
||||||
|
|
||||||
-- Update last damager info
|
|
||||||
lastDamager = damagerPlayer
|
|
||||||
lastDamageTime = GetGameTimer()
|
|
||||||
lastDamageWeapon = weaponHash
|
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -738,7 +696,7 @@ CreateThread(function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Enhanced damage detection for ragdoll kills
|
-- Zusätzlicher Event-Handler für zuverlässigere Treffer-Erkennung
|
||||||
AddEventHandler('gameEventTriggered', function(name, args)
|
AddEventHandler('gameEventTriggered', function(name, args)
|
||||||
if name == "CEventNetworkEntityDamage" then
|
if name == "CEventNetworkEntityDamage" then
|
||||||
local victimId = args[1]
|
local victimId = args[1]
|
||||||
|
@ -760,14 +718,6 @@ AddEventHandler('gameEventTriggered', function(name, args)
|
||||||
|
|
||||||
debugPrint("Schaden-Event erkannt: Angreifer=" .. (attackerServerId or "NPC/Unbekannt") .. ", Waffe=" .. weaponHash)
|
debugPrint("Schaden-Event erkannt: Angreifer=" .. (attackerServerId or "NPC/Unbekannt") .. ", Waffe=" .. weaponHash)
|
||||||
|
|
||||||
-- Update last damager info
|
|
||||||
if attackerServerId then
|
|
||||||
lastDamager = attackerServerId
|
|
||||||
lastDamageTime = GetGameTimer()
|
|
||||||
lastDamageWeapon = weaponHash
|
|
||||||
debugPrint("Last damager updated to " .. attackerServerId .. " with weapon " .. weaponHash)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Prüfe, ob es eine Airsoft-Waffe ist oder alle Waffen als Airsoft behandelt werden
|
-- Prüfe, ob es eine Airsoft-Waffe ist oder alle Waffen als Airsoft behandelt werden
|
||||||
if isAirsoftWeapon(weaponHash) and attackerServerId then
|
if isAirsoftWeapon(weaponHash) and attackerServerId then
|
||||||
-- Lokale Stats sofort updaten
|
-- Lokale Stats sofort updaten
|
||||||
|
@ -784,48 +734,6 @@ AddEventHandler('gameEventTriggered', function(name, args)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Improved Ragdoll-Erkennung Thread
|
|
||||||
CreateThread(function()
|
|
||||||
while true do
|
|
||||||
Wait(50) -- Check more frequently
|
|
||||||
if inTDM and not isHit then
|
|
||||||
local ped = PlayerPedId()
|
|
||||||
|
|
||||||
-- Prüfe, ob der Spieler im Ragdoll-Zustand ist
|
|
||||||
if isPedInRagdoll(ped) then
|
|
||||||
-- Bestimme den Angreifer
|
|
||||||
-- Prüfe, ob der Spieler im Ragdoll-Zustand ist
|
|
||||||
if isPedInRagdoll(ped) then
|
|
||||||
-- Bestimme den Angreifer (verwende den letzten Angreifer, wenn innerhalb von 3 Sekunden)
|
|
||||||
if lastDamager and (GetGameTimer() - lastDamageTime) < 3000 then
|
|
||||||
local attacker = lastDamager
|
|
||||||
|
|
||||||
-- Prüfe ob die Waffe eine Airsoft-Waffe ist
|
|
||||||
if isAirsoftWeapon(lastDamageWeapon) then
|
|
||||||
debugPrint("Ragdoll durch Airsoft-Waffe - Zählt als Tod durch: " .. attacker)
|
|
||||||
|
|
||||||
-- Lokale Stats sofort updaten
|
|
||||||
playerStats.deaths = playerStats.deaths + 1
|
|
||||||
|
|
||||||
-- Treffer-Events auslösen
|
|
||||||
TriggerEvent('tdm:playerHit')
|
|
||||||
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, attacker)
|
|
||||||
|
|
||||||
-- Zurücksetzen des letzten Angreifers
|
|
||||||
lastDamager = nil
|
|
||||||
lastDamageWeapon = 0
|
|
||||||
|
|
||||||
-- Warten um mehrfache Auslösung zu verhindern
|
|
||||||
Wait(1000)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Wait(500)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Direkter Waffen-Schaden Monitor für zusätzliche Zuverlässigkeit
|
-- Direkter Waffen-Schaden Monitor für zusätzliche Zuverlässigkeit
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
|
@ -847,7 +755,63 @@ CreateThread(function()
|
||||||
|
|
||||||
-- Treffer-Events auslösen
|
-- Treffer-Events auslösen
|
||||||
TriggerEvent('tdm:playerHit')
|
TriggerEvent('tdm:playerHit')
|
||||||
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, lastDamager)
|
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam)
|
||||||
|
|
||||||
|
-- Warten um mehrfache Auslösung zu verhindern
|
||||||
|
Wait(500)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Wait(500)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Ragdoll-Erkennung Thread
|
||||||
|
CreateThread(function()
|
||||||
|
local lastDamager = nil
|
||||||
|
local lastDamageTime = 0
|
||||||
|
|
||||||
|
while true do
|
||||||
|
Wait(100)
|
||||||
|
if inTDM and not isHit then
|
||||||
|
local ped = PlayerPedId()
|
||||||
|
|
||||||
|
-- Speichere den letzten Angreifer, wenn Schaden genommen wurde
|
||||||
|
if HasEntityBeenDamagedByAnyPed(ped) then
|
||||||
|
for _, player in ipairs(GetActivePlayers()) do
|
||||||
|
local playerPed = GetPlayerPed(player)
|
||||||
|
if HasPedBeenDamagedBy(ped, playerPed) then
|
||||||
|
lastDamager = GetPlayerServerId(player)
|
||||||
|
lastDamageTime = GetGameTimer()
|
||||||
|
debugPrint("Letzter Angreifer gespeichert: " .. lastDamager)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ClearEntityLastDamageEntity(ped)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Prüfe, ob der Spieler im Ragdoll-Zustand ist
|
||||||
|
if isPedInRagdoll(ped) then
|
||||||
|
debugPrint("Ragdoll-Zustand erkannt - Zählt als Tod")
|
||||||
|
|
||||||
|
-- Lokale Stats sofort updaten
|
||||||
|
playerStats.deaths = playerStats.deaths + 1
|
||||||
|
|
||||||
|
-- Bestimme den Angreifer (verwende den letzten Angreifer, wenn innerhalb von 3 Sekunden)
|
||||||
|
local attacker = nil
|
||||||
|
if lastDamager and (GetGameTimer() - lastDamageTime) < 3000 then
|
||||||
|
attacker = lastDamager
|
||||||
|
debugPrint("Ragdoll-Tod zugeordnet an Angreifer: " .. attacker)
|
||||||
|
else
|
||||||
|
debugPrint("Kein Angreifer für Ragdoll-Tod gefunden")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Treffer-Events auslösen
|
||||||
|
TriggerEvent('tdm:playerHit')
|
||||||
|
TriggerServerEvent('tdm:playerWasHit', currentGameId, currentTeam, attacker)
|
||||||
|
|
||||||
|
-- Zurücksetzen des letzten Angreifers
|
||||||
|
lastDamager = nil
|
||||||
|
|
||||||
-- Warten um mehrfache Auslösung zu verhindern
|
-- Warten um mehrfache Auslösung zu verhindern
|
||||||
Wait(500)
|
Wait(500)
|
||||||
|
@ -966,14 +930,3 @@ AddEventHandler('onResourceStop', function(resourceName)
|
||||||
cleanupResources()
|
cleanupResources()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Helper function for table.count
|
|
||||||
if not table.count then
|
|
||||||
table.count = function(tbl)
|
|
||||||
local count = 0
|
|
||||||
for _, _ in pairs(tbl) do
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
return count
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue