Henrik-3 / unofficial-valorant-api

Unofficial VALORANT API using the VALORANT Ingame API
423 stars 18 forks source link

friendly_fire for players is not calculated (correctly) #74

Open Root-DE opened 3 months ago

Root-DE commented 3 months ago

In the ["players"]["all_players"] list returned by the /valorant/v3/by-puuid/matches/{affinity}/{puuid} endpoint, each entry has the behavior dictonary which includes the key friendly_fireamong others. However its value is always set to 0, it is possible to calculate it yourself beacuse you can iterate over the damage_events. Here as python example:

import json
import requests

match_id = "0123456789" # CHANGE THIS TO THE MATCH ID YOU WANT TO CHECK

response = json.loads(
    requests.get("https://api.henrikdev.xyz/valorant/v2/match/" + match_id).content
)

for round_num, round in enumerate(response["data"]["rounds"]):
    for player_stats in round["player_stats"]:
        # check if on the same team
        source_team = player_stats["player_team"]
        source_player = player_stats["player_display_name"]
        for damage_event in player_stats["damage_events"]:
            receiver_team = damage_event["receiver_team"]
            receiver_player = damage_event["receiver_display_name"]
            if source_team == receiver_team and not source_player == receiver_player:
                print(
                    f"Friendly fire in round {round_num+1} by {source_player} to {receiver_player} for {damage_event['damage']} damage"
                )
            )
Henrik-3 commented 2 months ago

Do you have an example match ID where the calculation is wrong?