Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match details #67

Open
Mrfull opened this issue Jun 25, 2021 · 13 comments
Open

Match details #67

Mrfull opened this issue Jun 25, 2021 · 13 comments
Labels

Comments

@Mrfull
Copy link

Mrfull commented Jun 25, 2021

I want to get results(who win or lose) in match, how i can do it?
It's return to me some job_id, but what is it?
self.dota.request_match_details(match_id)
And where i can get match_id if i create lobby by

settings = { 'game_name': lobby_name, "game_mode": DOTA_GameMode.DOTA_GAMEMODE_1V1MID, "pass_key": "PWA", } self.dota.create_practice_lobby(password, settings)

@rossengeorgiev
Copy link
Member

dota.wait_event(job_id) to wait for response to that specific request, or to any match details response wait_event('match_details')

@Mrfull
Copy link
Author

Mrfull commented Jun 25, 2021

So for get this match_details, user witch one play via python code, should be in lobby all time till game will finished?

@rossengeorgiev
Copy link
Member

I don't understand what you are asking

@Mrfull
Copy link
Author

Mrfull commented Jun 29, 2021

I'm asking about, to get information about which team won, you need the bot to be in the match until the end of the game, right?

@rossengeorgiev
Copy link
Member

No. Just get the match details after the match

@Mrfull
Copy link
Author

Mrfull commented Jul 1, 2021

How script can know when match is finished?

@DEV-ONI
Copy link

DEV-ONI commented Jul 2, 2021

Assuming you're waiting for the match to finish and not retrieving details of a public lobby -

On the lobby event: EVENT_LOBBY_CHANGED,
if the CSODOTALobby.State is POSTGAME, the protobuf message passed to the event handler will contain details you want about the match such as the match duration and the winning faction. The outcome is k_EMatchOutcome_Unknown by default until the postgame.

optional .EMatchOutcome match_outcome = 70 [default = k_EMatchOutcome_Unknown];

You can create a dispatcher that handles all the lobby states from the EVENT_LOBBY_CHANGED event.

@Mrfull
Copy link
Author

Mrfull commented Jul 3, 2021

Can you give me some example how to do it for get match results?

@DEV-ONI
Copy link

DEV-ONI commented Jul 5, 2021

Sure friend

Initialize the Dota2Client.
Let's say dota_client here is an instance of Dota2Client

I wrote this in a hurry so hope you can understand

from dota2.common_enums import ESOType
from dota2.features import sharedobjects as so


# get lobby proto
CSODOTALobbyProto = so.find_so_proto(ESOType.CSODOTALobby)
LobbyState = CSODOTALobbyProto.State


# add this callback for event 'lobby_changed'
dota_client.on('lobby_changed', lobby_change_handler)


# lobby state handler dispatch
state_handler_dispatch = dict([
    (LobbyState.UI, #callable here),
    (LobbyState.READYUP, #callable here),
    (LobbyState.NOTREADY, #callable here),
    (LobbyState.SERVERSETUP, #callable here),
    (LobbyState.RUN, #callable here),
    (LobbyState.POSTGAME,  post_game_handler),
    (LobbyState.SERVERASSIGN, #callable)
])


def lobby_change_handler(message):

    logger.info(f"Event: Lobby Change: {message}")
    
   # if message field has state
    if message.HasField('state'):
        # call appropriate handler for lobby state
        state_handler_dispatch[message.state](message)


def post_game_handler(message):
    # protobuf message passed to this callable will contain info about the postgame
    pass

@DEV-ONI
Copy link

DEV-ONI commented Jul 6, 2021

I made a slight error which I corrected.

Attach the post game handler to LobbyState.POSTGAME instead of LOBBYASSIGN

@Mrfull
Copy link
Author

Mrfull commented Jul 11, 2021

@DEV-ONI If you know can you answer on thats questions:
#68

@DEV-ONI
Copy link

DEV-ONI commented Jul 12, 2021 via email

@Mrfull
Copy link
Author

Mrfull commented Jul 12, 2021

@DEV-ONI
Thats how its look in my code:

class DotaController:
    def  __init__(self):
        self.client = SteamClient()
        self.dota = Dota2Client(self.client)

        # get lobby proto
        CSODOTALobbyProto = so.find_so_proto(ESOType.CSODOTALobby)
        LobbyState = CSODOTALobbyProto.State

        # add this callback for event 'lobby_changed'
        self.dota.on('lobby_changed', self.lobby_change_handler)
        self.client.on('disconnected', self.reconnect_client)

        # lobby state handler dispatch
        self.state_handler_dispatch = dict([
            (LobbyState.UI, self.test),
            (LobbyState.READYUP, self.test),
            (LobbyState.NOTREADY, self.test),
            (LobbyState.SERVERSETUP, self.test),
            (LobbyState.RUN, self.test),
            (LobbyState.POSTGAME, self.post_game_handler),
            (LobbyState.SERVERASSIGN, self.test)
        ])

    def lobby_change_handler(self, message):
        logging.info(f"Event: Lobby Change: {message}")

        # if message field has state
        print("all members: " + str(len(message.all_members)))
        if message.HasField('state'):
            # call appropriate handler for lobby state

            self.state_handler_dispatch[message.state](message)

    def post_game_handler(self, message):
        print("message: " + str(message))
        print("match_outcome: " + str(message.match_outcome))

    def test(self, message):
        logging.info(f"Event: State: {message.state}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants