GraylinKim / sc2reader

A python library that extracts data from various Starcraft II resources to power tools and services for the SC2 community. Who doesn't want to hack on the games they play?
http://sc2reader.readthedocs.org
MIT License
413 stars 85 forks source link

Parsing events and complex data #81

Closed mikemassari closed 11 years ago

mikemassari commented 11 years ago

Hello, i'm trying to get a list of events and messages of the game Basically i just want to ha something like Player ID => [event.name] [event.time](sorry if the syntax is not correct, i'm quite new to python)

same thing for the messages.

I would also like to determine what happened at a certain time in the game. like: at 10:00 how many workers every player has.

As last. I don't seem to be able to retrieve the game_summary from the replay. Where do I find the hash to input in the url that should be called?

Is that possible? (p.s. sorry again for the noob question, please help a fellow developer ) :)

Prillan commented 11 years ago

"Hello, i'm trying to get a list of events and messages of the game Basically i just want to ha something like"

I think you could take a look at the sc2replayer script. However, that script is not working in the current branch. You can download a working version here (until it's merged with master): https://github.com/Prillan/sc2reader/blob/master/sc2reader/scripts/sc2replayer.py

"I would also like to determine what happened at a certain time in the game. like: at 10:00 how many workers every player has."

That is unfortunately not possible. The replays only contain the actions the players perform. You'd have to use the actual game engine to get an idea of that.

"As last. I don't seem to be able to retrieve the game_summary from the replay. Where do I find the hash to input in the url that should be called?"

We haven't found any reference to the summary in the replay. The summary has to do with the Battle.net side of things while the replay is a more game client/local thing. So that's probably why.

mikemassari commented 11 years ago

Hello Prillian, thanks for your help.

I tried your script. it seems to be working but as far as i can understand it only records "the Initialization, Ability, and Selection events by default."

is there a way to record them separately, including also creation of units?


i see there is also a sc2boprinter.py that should print the build order. if i provide it a s2gs file will it work? i mean.. is it updated?

GraylinKim commented 11 years ago

Hello, i'm trying to get a list of events and messages of the game

replay = sc2reader.load_replay('path/to/replay.SC2Replay')
for event in replay.events:
    print '{0} => {1}: {2}'.format(event.pid,event.name, event.time)

Please see the documentation for more information. The documentation needs improvement so if it is unable to answer your questions file a separate issue so the documentation can be improved.

I would also like to determine what happened at a certain time in the game; like: at 10:00 how many workers every player has.

This is difficult. Events are only recorded for player initiated actions and you'll find that both successful and unsuccessful actions are included. That means several things complicates our lives:

  1. There is no "unit created" event. Only a "player attempted to use train " events.
  2. There is no "death" event. You can only tell a unit is alive when it is actively selected.
  3. Game state information: player resources, available supply, etc are unavailable at all times.

It may be possible to overcome these limitations and approximate game state with a series of very smart assumptions and cool algorithms. If you could accurately count workers though, you'd be the first I think.

I don't seem to be able to retrieve the game_summary from the replay. Where do I find the hash to input in the url that should be called?

s2gs files hashes are not contained inside any other SC2 resources as far as anyone knows. Make sure you read this thread for details.

Aside from manually causing s2gs files to download to your battle.net cache folder you might try set up this software to scrape them from the process memory. I can't speak to its legality or effectiveness but it is somewhere to start if you want to automate things.

Seems like @Prillan beat me to it. Posting anyways.

GraylinKim commented 11 years ago

It is true that not all the scripts are very well maintained. They were originally intended as mini usage examples. It seems that people are trying to use them as a primary interface for sc2reader though. I'll have to make sure they don't break going forward.

Patches to the scripts are always accepted, just issue a pull request or email me a patch file.

mikemassari commented 11 years ago

Thanks a lot GraylinKim. I will look into what you send me and, if I find something interesting I will definitely issue a pull request.

GraylinKim commented 11 years ago

Okay, great. I added your questions and my answers to the online documentation for next time these things come up.