Recently, Valve had released their Counter-Strike: Global Offensive game state integration for developers to use. This allows the game client to send all game data, such as the player’s health, guns, ammo, frags, etc. to a HTTP POST endpoint server.
After seeing the PGL Arena Effects in the DreamHack Cluj-Napoca CS:GO tournament a couple of months ago, I decided to make full use of my Philips Hue lights in my room by recreating the C4 bomb lighting effects.
Since I’ve been coding in Python a lot recently, I stuck with this language for this project. First, I had to create the HTTP server to receive the POST game state data, so I used the Flask microframework. I launched the Flask server and joined a game in CS:GO, and immediately I was seeing tons of JSON being received in the terminal window. All I really needed was the C4 bomb information, which I was able to find in
data['round']['bomb']. By checking that key, I noticed there were 3 values if the key existed:
defused. If the bomb isn’t planted, there won’t be a
bomb key in the
round object at all. So after getting the bomb status, I made the server write the result to a file conveniently named
Now I had to do the fun part — making my Philips Hue lights turn on and change colors. I went step by step with the Philips Hue API Getting Started guide, and it was very easy to follow and understand the RESTful interface. Once I understood how to control the Hue lights, I wrote a 2nd Python script for reading the
bomb_status file. In this 2nd script, I have a while loop that runs indefinitely, with a 250ms wait time in between each loop. In each loop iteration, it gets the bomb status and goes through a series of if-statements to determine what to do. Here’s the run down of it:
- if bomb is planted: make each light blink red 1-by-1.
- if bomb is planted and plant time has been >= 30 seconds: make all lights blink red every second.
- if bomb is exploded: make all lights turn orange.
- if bomb is defused: make all lights turn blue.
- if bomb has no status: make all lights turn white.
And that’s basically it.
My Python code is now on GitHub:
I have created a Node.js version of the same code, also on GitHub:
A video of the script in action is uploaded to YouTube: