Skip to content

Commit

Permalink
Fix wrong OnDeath trigger actually
Browse files Browse the repository at this point in the history
  • Loading branch information
C9Glax committed Jan 15, 2024
1 parent 0367d07 commit 281d73e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions OpenCS2hock/CS2MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,20 @@ internal void HandleCS2Message(string message, string mySteamId)

Team playerTeam = ParseTeamFromString(messageJson.SelectToken("player.team", false)?.Value<string>());
Team winnerTeam = ParseTeamFromString(messageJson.SelectToken("round.win_team", false)?.Value<string>());
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>();
int? currentDeaths = messageJson.SelectToken("player.match_stats.deaths", false)?.Value<int>();
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>();
int? currentKills = messageJson.SelectToken("player.match_stats.kills", false)?.Value<int>();
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)
Expand Down

0 comments on commit 281d73e

Please sign in to comment.