Last active
March 20, 2021 10:48
-
-
Save cetteup/41012acd7fbd06553f1388579f96ad53 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<# | |
Simple PowerShell script to fetch Battlefield 4 player data from bflist and write the k/d to a textfile ([your_player_name]-bflist-live-kd.txt). | |
Before using the script, be sure to replace your_player_name with your player name. | |
#> | |
function Write-KDFile { | |
Param([string] $playerName, [int] $kills, [int] $deaths) | |
try { | |
Set-Content -Path "$($playerName)-bflist-live-kd.txt" -Value "$kills/$deaths" -Encoding utf8 -ErrorAction Stop | |
Write-Host "Updated k/d file ($kills/$deaths)" | |
} catch { | |
Write-Host "Error updating k/d file" | |
} | |
} | |
$playerName = 'your_player_name' | |
$baseUrl = 'https://api.bflist.io/bf4/v1/players/' | |
# Init kd file | |
Write-KDFile $playerName 0 0 | |
# Fetch kd every 15 seconds until script is stopped | |
while ($true) { | |
$requestOk = $false | |
try { | |
$resp = Invoke-RestMethod "$($baseUrl)$($playerName)" -TimeoutSec 5 | |
$requestOk = $true | |
Write-Host "Got player data from bflist" | |
} catch { | |
Write-Host "Error fetching player data from bflist" | |
Write-Host $_.Exception.Message | |
} | |
if ($requestOk) { | |
Write-KDFile $playerName $resp.kills $resp.deaths | |
} | |
Start-Sleep -Seconds 15 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment