bombsimon / hltv-python

📺 HLTV live score implementation with Socket.IO
MIT License
15 stars 3 forks source link

Implement winType #1

Closed Funeoz closed 4 years ago

Funeoz commented 4 years ago

I've found your implementation for the scorebot very interesting. I understood how to use the events for end rounds, kills in the round etc.. but I'm struggling a bit with winType. Can you explain a little bit about how to use it ?

bombsimon commented 4 years ago

Glad you like it! It's currently just a POC but would be cool to expand and make it usable.

Kill event is currently the only event that returns an object, all other events just returns the structured data as a map (or whatever way it's sent over the socket) to the end user. All events are described in the DOCUMENTATION and the available winTypes are found here. These should probably be converted to proper constants/enums but for now they're returned as plain strings.

So, what you can do is hook your event to EVENT_ROUND_END and check what made the team win. Here's an example:

def on_round_end(data):
    if data["winType"] == "Bomb_Defused":
        print("The bomb got defused")
    elif data["winType"] == "Target_Bombed":
        print("The bomb exploded before the CTs defused it")
    elif data["winType"] == "CTs_Win":
        print("All Ts got killed or the Ts didn't plant the bomb")
    elif data["winType"] == "Ts_Win":
        print("All CTs got killed")

def main():
    ls = Livescore(list_id=2340838)

    ls.on(ls.EVENT_ROUND_END, on_round_end)
    ls.socket().wait()

if __name__ == "__main__":
    main()
Funeoz commented 4 years ago

Thanks a lot ! It's now a bit more clear. I have another question. When a match ends, do you need to disconnect from the scorebot manually or is it done automatically ?

bombsimon commented 4 years ago

Nah I wouldn't say it's mandatory but it depends on your usage. Since you receive the plain socket you can refer to the python-stocketio documentation.

Funeoz commented 4 years ago

Thanks a lot !