skadistats / clarity-examples

Example code for clarity
BSD 3-Clause "New" or "Revised" License
113 stars 37 forks source link

pls how to pring hero postion? #7

Closed vodcms closed 8 years ago

vodcms commented 9 years ago

pls how to pring hero postion?

spheenik commented 9 years ago

Here is some old code that can get you going: https://gist.github.com/spheenik/3766744d47c170f25cf5

vodcms commented 9 years ago

i run is error Entity is have't m_vecOrigin property pls help me

spheenik commented 9 years ago

It’s hard for me to understand what your problem is. What’s your native language?

spheenik commented 9 years ago

Sounds like the entity does not have „m_vecOrigin“? Then it probably is no hero entity?

vodcms commented 9 years ago
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import skadistats.clarity.model.Entity;
import skadistats.clarity.processor.runner.Context;
import skadistats.clarity.processor.runner.SimpleRunner;
import skadistats.clarity.processor.tempentities.OnTempEntity;
import skadistats.clarity.source.MappedFileSource;

public class Main {

    private final Logger log = LoggerFactory.getLogger("da");
  @OnTempEntity
    public void onTempEntity(Context ctx, Entity e) {
        Object v = e.getProperty("m_vecOrigin")
        System.out.println(v);
    }

    public void run(String[] args) throws Exception {
        long tStart = System.currentTimeMillis();
        new SimpleRunner(new MappedFileSource("/Users/guest/Downloads/1667995496_replay.dem")).runWith(this);
        long tMatch = System.currentTimeMillis() - tStart;
        log.info("total time taken: {}s", (tMatch) / 1000.0);
    }

    public static void main(String[] args) throws Exception {
        new Main().run(args);
    }

}
spheenik commented 9 years ago

TempEntites are not real Entities! They are used for showing effects like blood, muzzle flash etc. Take a look at the MatchEnd example on how to get a real entity. There's also @OnEntityCreated and @OnEntityUpdated, you can play around with that :)

howardchung commented 9 years ago

I didn't know there was an @OnEntityCreated!

Might be a little faster than trying to check for new wards every second :)

spheenik commented 9 years ago

Be careful, they might reuse an entity spot, and you'd only get one call. But I could hack together an @OnEntityEnters for that case pretty quickly. If you want that for the 2.1 release, could you write a small request for it on the main project?

vodcms commented 9 years ago

thank @spheenik

spheenik commented 9 years ago

Sure @vodcms, np :) Btw: You can just do e.toString() on an entity to get a nice dump of all it's properties.

vodcms commented 9 years ago

hi @spheenik .where have about replay explian docuemnt? i do not understand properties

spheenik commented 9 years ago

hehe, there simply is none... But if you can read code, here is the parser of YASP, that uses clarity in a lot of ways: https://github.com/yasp-dota/yasp/blob/master/parser/src/main/java/yasp/Main.java

OlivierCavadenti commented 9 years ago

I try to process my replay with this function, but there are nothing printed, it's strange :'(. My parameters are good?

@OnEntityUpdated
    public void onEntityUpdated(Context ctx, Entity e,int[] a, int b) {
        System.out.println( b);
    }
spheenik commented 9 years ago

which version of clarity are you using?

OlivierCavadenti commented 9 years ago

The last version, snapshot 2.1.

spheenik commented 9 years ago

Then it was because of me, since exactly that one event was disabled in 2.1 until now, since it's signature was going to change. I just pushed a new snapshot that should have the event again. It's signature changed, however:

@OnEntityUpdated
public void onEntityUpdated(Context ctx, Entity e, FieldPath[] changedPaths, int numChangedPaths) {
  // the first numChangedPaths entries in fieldPaths show exactly what properties have changed.
  // do *not* keep a reference to changedPaths, since it's reused by clarity! 
}
OlivierCavadenti commented 9 years ago

Thanks, it works like a charm !

spheenik commented 9 years ago

you're welcome!