Categories
bflist Games How To Live streaming OBS Windows

How to add a live k/d overlay to your Battlefield streams

I was recently approached by Twitch streamer and world class Battlefield 4 Little Bird pilot “x8reaps“, asking if it was possible to create a stream overlay showing off his current in-game k/d ratio. Thanks to another project of mine (bflist.io), I already had the data and I just needed to figure out a way to get that data into OBS. The solution is rather simple: have a PowerShell script pull the data from bflist and write it to a text file. Then, create an OBS source that reads from the text file. So, here is how to set everything up.

Let’s set it up

Step 1: Download and extract the PowerShell script.

You can find it over on GitHub as a public gist. Simply click “Download ZIP” in the top right corner and then extract the downloaded .zip file (right click “Extract all”).

Step 2: Move the script to a convenient location.

I highly recommend moving the script out of the extracted folder in your “Downloads”-directory. Place it somewhere you can easily remember and find again later.

Step 3: Insert your in-game name into the script.

You need to edit the script in order to make it work with your in-game name. The easiest way to do this is to right click the script file and then click “Edit”. This will open the script in Windows’ built-in PowerShell editor. Locate line 17, which should currently contain:

$playerName = 'your_player_name'

Within the single quotes, replace your_player_name with your actual in-game name. For me, the final result would be:

$playerName = 'mister249'

Step 4: If you want to use the script for a Battlefield game other than Battlefield 4, change the URL in line 18 (right below $playerName) accordingly.

bflist currently supports: Battlefield 1942, Battlefield Vietnam, Battlefield 2, Battlefield 2142, Battlefield 3, Battlefield 4 and Battlefield Hardline. You can always find an up to date overview of supported games over on the bflist website: bflist.io/#games. If you want to use the script for Battlefield 2 instead of Battlefield 4 for example, simply change bf4 in the URL to bf2:

$baseUrl = 'https://api.bflist.io/bf2/v1/players/'

Step 5: Save your changes to the script.

Step 6: Run the script to generate the text file.

You need to run the script once to generate the text file containing your k/d data before you can set up the source in OBS. The easiest way to run the script is to right click the file and select “Run with PowerShell”. A PowerShell window will open and the script will start pulling your k/d ratio from bflist. You can minimize the window at any time, but do not close it.

Please note: bflist cannot return any live data if you are not currently on a public server in the respective Battlefield game. So, if you haven’t joined a server (yet), you will see script output the following:

Updated k/d file (0/0)
Error fetching player data from bflist
The remote server returned an error: (404) Not Found.

You don’t have to join a server during setup, since the script will generate the text file regardless of whether you are currently playing. However, make sure the script and thus the overlay are working correctly before going live.

Step 7: Open OBS and create a new text source.

After creating the text source and giving it a fitting name, check “Read from file” in the properties window of your newly created text source. Then, click “Browse” next to the field labeled “Text file (UTF-8)” to locate the text file generated by the script. The script will always generate/update the text file in the same folder the script itself is in.

Step 8: Make the overlay look nice and then click “OK”.

You can change the remaining settings of the text source however you like. Once you are done, click “OK” to save your changes.

Step 9: Make sure everything works!

Everything is set up now, so it’s time to open the game and join a public server in order to verify everything is up and running.


And we’re done!

That’s all there is to it. Viewers can now see your current in-game k/d ratio at any time. The script will update the text file about every 20 seconds. Be sure to start the script before you click “Start streaming” in OBS for all your future Battlefield streams.

If anything is not working as it should, please refer to the troubleshooting section below.


It is not working BibleThump!!

If the script and/or the OBS overlay are not working as expected, here are few things to check before reaching out.

When I run the script, the window shows some red text for a second and then closes.

There is an error in the script which causes it to exit. Double check your changes to the script. Make sure you did not accidentally remove one of the single quotes around your in-game name (for example). If you are still encountering errors, try re-downloading the script and running it without any modifications. Once you got it running as is, modify the script as described above.

I joined a public server but the script still says “Error fetching player data from bflist” over and over

While it may take a few seconds for bflist to notice you joined a server, it should never take much longer then about a minute. If you still get the error after a minute, double check you are using the account whose in-game name you entered in the script. Try joining a different public server if the names match but you are still seeing the script output the error message. If the error does not appear when on the other server, let me know which server you had issues with.

I changed my in-game name and the overlay is no longer working

Your in-game name is important for this setup, as it is referenced twice: once in the script and once in the name of the text file. So, if you end up changing your in-game name, you need to also update the script. Run the script once after updating it and then tell OBS to use the text file with the new name.

I started streaming but my k/d is not updating

Verify that the script is currently running. You need to start the script before every stream. If it is running, check the PowerShell window for any errors and refer to the above steps to rectify any errors you see.

Still having trouble? Reach out via Twitter (@cetteup).