Last active
December 17, 2022 10:00
-
-
Save glmn/a3ac1c3d856752a2efd0163c0e3bc730 to your computer and use it in GitHub Desktop.
Calculate PUBG players accuracy and headshot percents for PUBGDiscoBot with pubg_python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pubg_python import * | |
api_key = 'YOUR SECRET KEY' | |
api = PUBG(api_key, Shard.STEAM) | |
player = api.players().filter(player_names=['glmn'])[0] | |
player_id = player.id | |
match = api.matches().get(player.matches[1]) | |
telemetry = api.telemetry(match.assets[0].url) | |
attacks = telemetry.events_from_type('LogPlayerAttack') | |
kills = telemetry.events_from_type('LogPlayerKill') | |
damages = telemetry.events_from_type('LogPlayerTakeDamage') | |
player_kills = len([_ for _ in kills if _.killer.account_id == player_id]) | |
player_attacks = [_ for _ in attacks if _.attacker.account_id == player_id | |
and _.weapon.category == 'Weapon' | |
and _.weapon.sub_category in ['Main', 'Handgun']] | |
player_damages = [_ for _ in damages if _.attacker.account_id == player_id] | |
used_weapon = {_.weapon.item_id:_.fire_weapon_stack_count | |
for _ in player_attacks} | |
shots = sum(used_weapon.values()) | |
hits = len([_ for _ in player_damages if _.damage_reason in [ | |
"ArmShot", | |
"HeadShot", | |
"LegShot", | |
"PelvisShot", | |
"TorsoShot"]]) | |
headshots = len([_ for _ in player_damages if _.damage_reason == 'HeadShot']) | |
headshots_percent = (headshots / hits * 100) if hits > 0 else 0 | |
accuracy = (hits / shots * 100) if shots > 0 else 0 | |
print('Kills: {} Shots: {} Hits: {} HS: {} HS%: {} ACC%: {}'.format( | |
player_kills, | |
shots, | |
hits, | |
headshots, | |
format(headshots_percent, '.2f'), | |
format(accuracy, '.2f'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of how to calculate players accuracy and headshots percents with telemetry data.
Based on pubg_python library for my project -> PUBGDiscoBot