From 281d73eb6bbe83421a93687b07725cb61dd8adc7 Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 15 Jan 2024 02:48:08 +0100 Subject: [PATCH] Fix wrong OnDeath trigger actually --- OpenCS2hock/CS2MessageHandler.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/OpenCS2hock/CS2MessageHandler.cs b/OpenCS2hock/CS2MessageHandler.cs index 60cf609..08f8421 100644 --- a/OpenCS2hock/CS2MessageHandler.cs +++ b/OpenCS2hock/CS2MessageHandler.cs @@ -29,24 +29,20 @@ internal class CS2MessageHandler Team playerTeam = ParseTeamFromString(messageJson.SelectToken("player.team", false)?.Value()); Team winnerTeam = ParseTeamFromString(messageJson.SelectToken("round.win_team", false)?.Value()); - if(winnerTeam != Team.None && playerTeam == winnerTeam) + if(winnerTeam != Team.None && playerTeam != Team.None && playerTeam == winnerTeam) OnRoundWin?.Invoke(); - else if(winnerTeam != Team.None && playerTeam != winnerTeam) + else if(winnerTeam != Team.None && playerTeam != Team.None && playerTeam != winnerTeam) OnRoundLoss?.Invoke(); int? previousDeaths = messageJson.SelectToken("previously.player.match_stats.deaths", false)?.Value(); int? currentDeaths = messageJson.SelectToken("player.match_stats.deaths", false)?.Value(); - if(currentSteamId == mySteamId && previousSteamId == currentSteamId && currentDeaths > previousDeaths) + if(previousSteamId is null && currentSteamId == mySteamId && currentDeaths > previousDeaths) OnDeath?.Invoke(); - else if(currentSteamId != mySteamId) - Console.WriteLine("Not my SteamId"); int? previousKills = messageJson.SelectToken("previously.player.match_stats.kills", false)?.Value(); int? currentKills = messageJson.SelectToken("player.match_stats.kills", false)?.Value(); - if(currentSteamId == mySteamId && previousSteamId == currentSteamId && currentKills > previousKills) + if(previousSteamId is null && currentSteamId == mySteamId && currentKills > previousKills) OnKill?.Invoke(); - else if(currentSteamId != mySteamId) - Console.WriteLine("Not my SteamId"); } private RoundState ParseRoundStateFromString(string? str)