Skip to content

How it works inside?

spumer edited this page May 5, 2014 · 8 revisions

Left 4 Dead 2 score calculation system: short overview

Determine the player

By default engine support only 4 players in each team. To determine players in the world it can use "client indexes" or "character types". The character type is just value from 0 to 3 for your character like "Nick", "Ellis", "Coach" or "Rochell". Client index can be any value in range from 1 to 32. This is why game can't be more than 16vs16. Client index is a entity world identifier. For unique determine each player they has a "userid" which increased for each new connection.


But let's talk about how the "score calculation system" use this information.

Where is the score stored?

In memory. Yes, it's simple. Left 4 Dead 2 have two interesting for us buffers:

  1. Current completion score for each player
  2. Completion score for each player before he die -- "death score". By default is -1. Initial score state on map start

Or if speaking in C-like programming language:

In-memory struct

Recompute Loop

Score updated every second by special function (RecomputeVersusCompletion). After every call we got the updated buffer for current survivors team. If player die his score saved and don't compute again, just retreived from "death score" buffer. The another system use this information to show scull over progressbar.