Module stats
Stats
Tracks kill and death counts for each player in a multiplayer session.
Core responsibilities:
- Increment death count for victims
- Increment kill count for attackers (when valid)
- Provide API to query per-player kills and deaths
Execution context:
- statsTick must be called server-side
- statsGetKills / statsGetDeaths can be used on both server and client
Functions
| statsInit () | Initialize the stats (server). |
| statsTick (playerTeamList) | Update player statistics based on playerdied events (server). |
| statsGetKills (playerId) | Get the number of kills for a player. |
| statsGetDeaths (playerId) | Get the number of deaths for a player. |
Functions
- statsInit ()
-
Initialize the stats (server).
Clears all previously recorded stats. Call this at the start of a match or round.
- statsTick (playerTeamList)
-
Update player statistics based on
playerdiedevents (server).Processes all
playerdiedevents since the last tick and updates stats. This should be called once per tick on the server during an active match.Parameters:
- playerTeamList table or nil Table mapping player IDs to team identifiers.
Usage:
-- Example local playerGroupList = {} playerGroupList[1] = 1 -- player id 1,2,3 is in team 1 and 4,5,6 in team 2 playerGroupList[2] = 1 playerGroupList[3] = 1 playerGroupList[4] = 2 playerGroupList[5] = 2 playerGroupList[6] = 2 statsTick(playerGroupList) -- or in a free-for-all game mode statsTick(nil)
- statsGetKills (playerId)
-
Get the number of kills for a player.
If the player has no recorded stats, returns 0.
Parameters:
- playerId number Player ID.
Returns:
-
number
Number of kills recorded for this player.
- statsGetDeaths (playerId)
-
Get the number of deaths for a player.
If the player has no recorded stats, returns 0.
Parameters:
- playerId number Player ID.
Returns:
-
number
Number of deaths recorded for this player.