Coder Social home page Coder Social logo

Improved Examples about demofile HOT 14 CLOSED

saul avatar saul commented on August 22, 2024
Improved Examples

from demofile.

Comments (14)

BitDesert avatar BitDesert commented on August 22, 2024 2

Mabe add the values from m_szTeamFlagImage and m_szTeamLogoImage as well, could be useful.

from demofile.

saul avatar saul commented on August 22, 2024 2

See e41ca9d, I've added isSpotted, isSpottedBy, allSpotters, hasSpotted, allSpotted and isFriendly functions to the Player class.

from demofile.

saul avatar saul commented on August 22, 2024 1

Completely agree - as it stands the library is quite low-level. In the near future (i.e. this month), I plan to add functions to the Entity class like:

  • getOrigin
  • getOwner (for getting the thrower of grenades)

And methods to a new Player class such as:

  • getViewAngles
  • getSteamId
  • getUserId
  • getWeapons

Watch this space :)

from demofile.

cinkonaap avatar cinkonaap commented on August 22, 2024 1

Is it possible to determine distance from one entity to another?

If demofile hasn't some player to player distance map, then I think each player entity has position property, so you can calculate distance with simple vector manipulation.

magnitude = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z) // or use dot product

It should be easier if position or euler angles properties are transformed to some Vector objects, for easier manipulation (https://evanw.github.io/lightgl.js/docs/vector.html for ref.)

Of course above distance is straight line from player A to player B, so it's not real move from A to B distance. If you want calculate this, you would need to create proper structure for that (pathfinding problems).

from demofile.

saul avatar saul commented on August 22, 2024

@mavrick - what do you think of these provisional API additions? I've got it working locally, but wondering if there are any other functions you think would be useful:

Entity:

  • getPosition
  • getOwner
  • getTeamNumber

Player:

  • getHealth
  • getEyeAngles
  • getAccount
  • getLifeState
  • isAlive
  • getUserInfo
  • getUserId
  • getSteamId
  • getName
  • isFakePlayer
  • isHltv
  • getArmor
  • getPlaceName
  • getActiveWeapon
  • getWeapons
  • isInBombZone
  • isInBuyZone
  • isDefusing
  • hasDefuser
  • hasHelmet
  • getKills
  • getAssists
  • getDeaths
  • hasC4

Entities:

  • getByUserId

from demofile.

BitDesert avatar BitDesert commented on August 22, 2024

Maybe insted of getTeamNumber something like getTeam? And maybe a Team class for all that info would be great. Keep up the good work!

from demofile.

saul avatar saul commented on August 22, 2024

That makes sense :) I've also made them getter properties instead of functions too.

from demofile.

saul avatar saul commented on August 22, 2024

@derpalmer I've added:

Team:

  • teamNumber
  • players
  • clanName
  • teamName
  • score
  • scoreFirstHalf
  • scoreSecondHalf

Anything else?

from demofile.

mavrick avatar mavrick commented on August 22, 2024

Hey mate,

These additional options are a great start! Using the demo files to rebuild match stats will be much easier now.

For player what about:

  • getBank

Also, I was thinking what about round information:

round

  • getRound (int)
  • isKnife (bool)
  • score (object of teams with running score for this round)
  • getWinner (teamId) - round winner
  • bombPlanted (bool)
  • bombDefused (bool)
  • getRoundMVP

Some additional things I'd like for data analysis if possible, would be:

  • Ability to determine if an entity is a player and if they are an ally or enemy
    • isAlly()
  • Entities in FOV (who/what can the player currently see on the screen during an event)
    • visibileEntitiesInFov()
  • All available entities within FOV
    • availableEntitiesInFov()
  • Ability to determine is the crosshair/eyeAngle is on an entity at a given event.
    • hasEntityInFocus()

Examples:

var entities = player.visibileEntitiesInFov();

for(var k in entities)
{
	var entity = entities[k];

	if(entity.isPlayer() == true && player.hasEntityInFocus(entity) == true)
	{
		console.log("player is on the screen and we're locked on");

		if(entity.isAlly(player) == true)
		{
			console.log("they are on the same team")
		}
		else
		{
			console.log("the enemy has been found");
		}
	}
}

or, on a kill event:

player.on("kill", function(event, entity)
{
	if(entity.isVisible() == true)
	{
		// possible knife or gun kill
		console.log("kill was visible on screen");
	}
	else
	{
		// wall bang, grenade, molly kill
		console.log("kill was made offscreen");
		console.log(event.killType()); // what was the kill from?
	}
});

Then using them altogether, example:

player.on("eyeAngles", function(event)
{
	var entities = event.availableEntitiesInFov();

	for(var k in entities)
	{
		var entity = entities[k];

		if(
			entity.isPlayer() == true && 
			player.hasEntityInFocus(entity) == true && 
			entity.isAlly(player) == false &&
			entity.isVisible() == false
		)
		{
			console.log("player is aiming at someone through a wall or door");
		}
	}
});

I'm just writing 'freehand' for the above examples, they are in no way accurate based on current documentation.

I'll add some more tonight when I get home.

from demofile.

saul avatar saul commented on August 22, 2024

Thanks for the thorough feedback.

For player what about:

  • getBank

Use player.account.

round

  • getRound (int)
  • isKnife (bool)
  • score (object of teams with running score for this round)
  • getWinner (teamId) - round winner
  • bombPlanted (bool)
  • bombDefused (bool)
  • getRoundMVP

Most of this information is available in the round_end and round_mvp events, alongside Team#score. Unfortunately I don't think there's a way to determine if a round was a 'knife round'.

  • Ability to determine if an entity is a player and if they are an ally or enemy
    • isAlly()

This should be do-able, just need to check whether the team numbers match or if mp_teammates_are_enemies is set.

  • Entities in FOV (who/what can the player currently see on the screen during an event)
    • visibileEntitiesInFov()
  • All available entities within FOV
    • availableEntitiesInFov()
  • Ability to determine is the crosshair/eyeAngle is on an entity at a given event.
    • hasEntityInFocus()

Unfortunately none of these will be viable (besides possibly availableEntitiesInFov). We need to be able to trace lines across the game world, which we can't do unless we have a full 3D representation of the level loaded into memory. This would be beyond the scope of this library.

from demofile.

mavrick avatar mavrick commented on August 22, 2024

Awesome, based on those additions does this look correct:

demo.entities.on('change', function() 
{
	console.dir(arguments);
});
{ '0':
   { entity:
      Player {
        _demo: [Object],
        index: 10,
        classId: 35,
        serialNum: 923,
        props: [Object],
        clientSlot: 9 },
     tableName: 'm_iMatchStats_KillReward',
     varName: '003',
     oldValue: 0,
     newValue: 200 } }
demo.entities.on('change', function(data) 
{
	var Entity = data.entity;
	var tableName = data.tableName;
	var varName = data.varName;

	var filters = [ 'm_bIsWalking', 'm_flLowerBodyYawTarget', 'm_bStrafing', 'm_angEyeAngles', 'm_bIsScoped' ];

	if(tableName == 'DT_CSPlayer' && filters.indexOf(varName) != -1)
	{
		var playerEntities = Entity.allSpotted;

		for(var k in playerEntities)
		{
			var playerEntity = playerEntities[k];

			if(playerEntity.isFriendly(Entity.teamNumber) == false)
			{
				console.log("we've spotted an enemy");
			}
		}
	}
});

Is it possible to determine distance from one entity to another?

from demofile.

cinkonaap avatar cinkonaap commented on August 22, 2024

And what about more generic information, like current map for example?

Is there any good external reference, which shows what data is saved in these stringtables, gameevents etc.?

from demofile.

saul avatar saul commented on August 22, 2024

@cinkonaap the current map is available in DemoFile#header. I don't believe there is a reference as to what's in string tables. For events, see: https://wiki.alliedmods.net/Counter-Strike:_Global_Offensive_Events

from demofile.

mavrick avatar mavrick commented on August 22, 2024

@cinkonaap thanks for that. I will have a crack at it.

from demofile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.