Open Mrfull opened 3 years ago
dota.wait_event(job_id)
to wait for response to that specific request, or to any match details response wait_event('match_details')
So for get this match_details, user witch one play via python code, should be in lobby all time till game will finished?
I don't understand what you are asking
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?
No. Just get the match details after the match
How script can know when match is finished?
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.
You can create a dispatcher that handles all the lobby states from the EVENT_LOBBY_CHANGED
event.
Can you give me some example how to do it for get match results?
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
I made a slight error which I corrected.
Attach the post game handler to LobbyState.POSTGAME
instead of LOBBYASSIGN
@DEV-ONI If you know can you answer on thats questions: https://github.com/ValvePython/dota2/issues/68
Can you show me the code for this?
You're getting a KeyError, which means you're attempting to get a key
in state_handler_dispatch
that doesn't exist.
On Mon, Jul 12, 2021 at 2:11 AM Mrfull @.***> wrote:
@DEV-ONI https://github.com/DEV-ONI If you know can you answer on thats questions:
68 https://github.com/ValvePython/dota2/issues/68
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ValvePython/dota2/issues/67#issuecomment-877840711, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMOT7ZAHRKNGCEKL7QDM63LTXHNFBANCNFSM47J6BBWA .
@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}")
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 bysettings = { 'game_name': lobby_name, "game_mode": DOTA_GameMode.DOTA_GAMEMODE_1V1MID, "pass_key": "PWA", } self.dota.create_practice_lobby(password, settings)