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

Different entities when listening on create vs postcreate #295

Closed
thecatontheflat opened this issue May 2, 2021 · 3 comments · Fixed by #300
Closed

Different entities when listening on create vs postcreate #295

thecatontheflat opened this issue May 2, 2021 · 3 comments · Fixed by #300
Labels

Comments

@thecatontheflat
Copy link
Contributor

thecatontheflat commented May 2, 2021

There is a difference in entities when listening to create vs postcreate events. I've noticed it on various demos, but I have recorded a small one to isolate the case, in which I consequently throw 3 grenades:

  1. weapon_hegrenade
  2. weapon_flashbang
  3. weapon_smokegrenade

If I do this (listen to the create):

    this.demoFile.entities.on('create', (e) => {
      if (!('DT_BaseCSGrenadeProjectile' in e.entity.props)) return;

      const projectileEntity = (e.entity as unknown) as BaseEntity<CBaseCSGrenadeProjectile>;
      const thrower = projectileEntity.owner as Player;

      console.log('%s threw %s at:', thrower ? thrower.name : '(someone)', projectileEntity.modelName, projectileEntity.position);
    });

it outputs the following data, which is wrong:

d0h threw models/Weapons/w_eq_fraggrenade_dropped.mdl at: { x: 341.6875, y: 2492.34375, z: -53.21875 }
d0h threw models/Weapons/w_eq_fraggrenade_dropped.mdl at: { x: 341.6875, y: 2492.34375, z: -53.21875 }
d0h threw models/Weapons/w_eq_smokegrenade_thrown.mdl at: { x: 330.15625, y: 2484.28125, z: -52.78125 }

When I listen on postcreate with the same code

    this.demoFile.entities.on('postcreate', (e) => {
      if (!('DT_BaseCSGrenadeProjectile' in e.entity.props)) return;

      const projectileEntity = (e.entity as unknown) as BaseEntity<CBaseCSGrenadeProjectile>;
      const thrower = projectileEntity.owner as Player;

      console.log('%s threw %s at:', thrower ? thrower.name : '(someone)', projectileEntity.modelName, projectileEntity.position);
    });

the output is correct:

d0h threw models/Weapons/w_eq_fraggrenade_dropped.mdl at: { x: 341.6875, y: 2492.34375, z: -53.21875 }
d0h threw models/Weapons/w_eq_flashbang_dropped.mdl at: { x: 316.5, y: 2493.21875, z: -47.84375 }
d0h threw models/Weapons/w_eq_smokegrenade_thrown.mdl at: { x: 330.15625, y: 2484.28125, z: -52.78125 }

Could you please help me understand the underlying issue? Is it due to the nature of the sequence of the events being recorded in the demo, or is it a bug in the parser? If it's the latter, could you point me in the right direction so I could try to submit a fix for it?

nades.dem.zip

@saul
Copy link
Owner

saul commented May 8, 2021

This isn't a bug, see the documentation for the create event: https://github.com/saul/demofile/blob/master/src/entities.ts#L228-L234. Specifically "Note no entity properties are available yet."

This is because when the entity is created, the props are all initially set to the 'baseline' (usually the same as an entity that used that index previously). postcreate is fired when the entity's actual props are read from the demo.

I may get rid of the create/postcreate split as it doesn't really serve any useful purpose. (I'd get rid of create and rename postcreate to create instead.)

@thecatontheflat
Copy link
Contributor Author

Ah, understood.

Personally I think that switching them around would make more sense, as this is what I intuitively expected when hooking to create event.

Thanks for the clarification!

@saul
Copy link
Owner

saul commented May 9, 2021

This will be released as part of v2.1.0

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

Successfully merging a pull request may close this issue.

2 participants