BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Kills, assists and team damage: who gets the credit

BF22142Heroes

The engine does not know what a kill is worth. It decides who killed whom, who helped, and whether it was a team kill, and tells the Python layer in a fixed order of events. The points, the ranks and the medals are the script's. This page is the engine's half: one function, GameLogicDamage::serverGiveDamage, which every hit on the server passes through.

One hit that destroys a manned vehicle: what the script hears, in order VehicleDestroyed(vehicle, attacker) once, when the hit made a wreck of a vehicle that was whole PlayerKilled(victim, attacker, weapon, assists, killer object) for each occupant in seat order; then the kill feed's message and one to each assistant PlayerDeath(victim) unless the victim is a soldier who only went man down the armor takes the damage only now do the hit points change PlayerTeamDamagePoint in the tail, when team damage passed its threshold bf2_w32ded.exe!0x00586eb0 (handleDamage, called from addDamage 0x004599f0 before the armor's 0x006325d0)
One hit that destroys a manned vehicle, in the order the script hears of it.

Where it sits#

Every damage, whatever its cause, arrives at GameLogic::addDamage (damage and armor). After the team scale it calls handleDamage (bf2_w32ded.exe!0x00586eb0) before the armor takes the hit points: the bookkeeping sees the state before the hit and can tell "this hit kills".

Guards#

Nothing is booked when the victim has no armor up its parent chain, or is invulnerable (a fresh spawn's one second). An attacker of another team than the one the damage was fired for is dropped: a shell fired before its gunner changed sides is nobody's.

The armor remembers the attacker, his weapon, the hit's position and direction. The hit indicator on the victim's HUD comes from here: the damage as a share of the maximum hit points is added up, and past a threshold the victim's client is told from which direction.

The kill tests#

VictimKilled whenDead when
a soldier on foothe was not already down, and the hit takes him to 0 or belowthe hit takes him to minus his wreck health
a vehicle, or a soldier in onethe hit takes it to 0.001 or below

"Killed" for a soldier means man down: he can still be revived. "Dead" is final. The two are separate because the script hears of them separately.

Everyone aboard#

For a vehicle the function walks the seats in position order. For each occupant, when the vehicle was killed:

  • no attacker (it burned out, sank, fell): the occupant simply dies;
  • the attacker is of his team: a team kill, for the whole call;
  • the attacker is an enemy: the assists are collected (below);
  • in both cases the armor's damage lists are cleared, so that an assist is paid once.

Assists#

The helpers are kept in a map by player (its insert is 0x00587dc0), and the first kind entered for a player wins; 0x00587f40 hands the map to Python:

KindWho
crew assistthe crew of the shooter's vehicle: the driver of a tank whose gunner made the kill. The first of the crew list gets the driver's kind, the rest the passengers'
target assistsomebody who marked the target: the projectile has a target object within 10 m of the victim, set by another player (a laser designator)
damage assistwhoever is on the victim's armor's damage list: players who hurt it before the killing hit. Counted for enemy kills and for team kills; not the attacker himself, not the victim's team mates

The script receives the assists as a list with their kinds and decides the points for each.

The order of events#

For one hit, always in this order:

  1. VehicleDestroyed(vehicle, attacker), when the hit destroyed a vehicle that was not already a wreck;
  2. for each victim, in seat order: PlayerKilled(victim, attacker, weapon, assists, killer object), then the "killed by" message to the clients (the kill feed; its data is filled by 0x00586bb0), then a message to each assistant;
  3. PlayerDeath(victim), unless the victim is a soldier who only went man down;
  4. the armor takes the damage;
  5. in the tail of addDamage (0x004599f0, from 0x00459c1f on): PlayerTeamDamagePoint, when it applies.

A scoring script that counts on another order (a death before its kill) is wrong, and a port that sends another order breaks scripts that are right. The port's function is verified call for call against the original.

Team kills and team damage#

  • A team kill with reporting sets the victim's "killed by team mate" mark, the mark a punish or forgive choice can work from. Without reporting (some causes do not report) the victim gets no kill event and no death event at all from this function.
  • Team damage short of a kill is counted on the victim's armor. For a soldier, any listed hit by a team mate raises PlayerTeamDamagePoint. For a vehicle the hits are summed, and the event comes when the sum passes a share of the vehicle's maximum hit points that the score manager sets.
  • How much friendly fire hurts in the first place is the server's settings (sv.soldierFriendlyFire, sv.vehicleFriendlyFire and their splash twins), applied by teamDamageScale (0x00586c80) before any of

this.

The script's half#

game.scoringCommon registers handlers for the events above and adds to the player's score fields: kills, deaths, team kills, the assist counts, and the points. Because it is a script, a mod or a server admin changes scoring without touching the engine. What the port must get right is the events' order, their arguments, and the player's score fields the script reads and writes (the Python layer).

Heroes
Battlefield Heroes

Heroes' scoring script gives the assist kinds no points of their own; a damage assist is counted and paid in another way. Its server also credits each assistant with a kill in the scoreboard's column, as the screens sweep read it, which the port does not do: an open row on the Heroes HUD page.

How it is tested#

WhatCheck
handleDamageverified call for call against the original function: the same calls with the same arguments in the same order
the assistsverified
the team damage scaleverified
the tail of addDamage (team damage accounting) and the attacker's resolutionread, not run against the original, as the notes say
rules as a wholeheadless players play scripted rounds on the original server and the port's; scores, kills, deaths and awards are compared (test rigs)

In the code#

WhatWhere
the bookkeepingcrates/bf2-gameplay/src/kills/bookkeeping.rs (handle_damage)
the chain on the servercrates/bf2-server/src/damage.rs
the events to Pythoncrates/bf2-server/src/ (the host functions and event calls)
the scoring scriptthe game's own python/game/scoringCommon.py, run by the port's Python host

Notes: notes/subsystems/gameplay-kills.md, notes/subsystems/gameplay-damage.md (section 1), notes/subsystems/python-usage.md.

Source: docs/dev/server/scoring.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.