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

CS2: Player Inventory now includes initial loadout at the beginning of the game #449

Merged
merged 2 commits into from
Oct 18, 2023

Conversation

esbengc
Copy link
Contributor

@esbengc esbengc commented Oct 18, 2023

Fixed an issue in CS2 where Player.Inventory would not include any weapons with which the player started.

As a simple test run the following program (for my own test, I used https://www.hltv.org/matches/2367165/rhyno-vs-perroflautas-aveiro-techdays-cup-2023 map 2 anubis):

func main() {
	demoFilePath := flag.String("demo", "", "path to demo file")
	flag.Parse()

	demoFile, err := os.Open(*demoFilePath)
	if err != nil {
		panic(err)
	}

	parser := demoinfocs.NewParser(demoFile)
	if err != nil {
		panic(err)
	}

	parser.RegisterEventHandler(func(_ events.RoundStart) {
		fmt.Printf("Round start: %d\n", parser.GameState().TotalRoundsPlayed()+1)
		var players []*common.Player
		players = append(players, parser.GameState().TeamTerrorists().Members()...)
		players = append(players, parser.GameState().TeamCounterTerrorists().Members()...)
		for _, player := range players {
			fmt.Print(player.Name, "has the following weapons:")
			for _, weapon := range player.Weapons() {
				fmt.Print(" " + weapon.String())
			}
			fmt.Println()
		}
		fmt.Println()
	})

	err = parser.ParseToEnd()
	if err != nil {
		panic(err)
	}
}

For round 1, it will print completely empty inventories for everybody. For round 2, it will not include any weapons that any surviving players had through the entire round 1.

@markus-wa markus-wa merged commit 9d80bca into markus-wa:master Oct 18, 2023
3 checks passed
@markus-wa
Copy link
Owner

thanks @esbengc ! merged and released

@esbengc esbengc deleted the cs2-starting-weapons branch October 19, 2023 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants