Per-player statistics a game declares once and reports in batches. Counters, gauges, bests and lowests are merged by a rule the game states, and filed to the TMC back end without a server ever handing over an account id.
GameSpice addon under the MIT licence, built with Claude Code, with a headless suite in examples/stats_selftest.tscn. The games in Zee's Games run on live servers built from GameSpice addons, and they report their player statistics through this one. Bug reports go to the issue tracker.
State the merge rule once per stat (add, replace or keep the better) and every party applies it the same way: the server counting, the reporter batching and the site storing.
- Get Godot 4.7.
- Either use GameSpice Bootstrap, which clones every project and links the addons, or copy
addons/gs_stats/and GameSpice Core'saddons/gs_core/into your project and enable gs-stats in Project > Project Settings > Plugins.
GameSpice Core and GameSpice Save (copy its addons/gs_save/ beside gs_core) are the dependencies. GameSpice Auth is optional and supplies the two clients (GSBackboneClient for a server, GSAuthClient for a player).
var schema := GSStatsSchema.new()
schema.define(&"kills").publish = true
schema.define(&"top_speed", GSStatsDef.Kind.BEST, "Top speed").publish = true
schema.define(&"level", GSStatsDef.Kind.GAUGE) # kept, never reported
var tracker := GSStatsTracker.new()
tracker.schema = schema
tracker.report_to_backbone = true
tracker.reporter.client = backbone # gs-auth's GSBackboneClient
add_child(tracker)
tracker.begin(player_key, display_name) # the scoped key, never the account id
tracker.record(player_key, &"kills")
tracker.record(player_key, &"top_speed", 41.2)
tracker.end(player_key) # reports the last delta, forgets themEvery report_interval seconds (default 30) and once more on shutdown, the tracker sends each player's delta since the last report, such as {"kills": 3, "top_speed": 41.2}. The site merges each by its kind.
var store := GSStatsStoreSql.new(driver) # any gs-sql driver; or GSStatsStoreMemory
await store.open() # creates or migrates its table
tracker.store = store # before add_childEach reported delta is also merged into the store by the same rule, so a server with no back end still keeps every player's totals. The store answers values_for(player), top(stat, limit, offset) (a LOWEST ascending, the rest descending, ties sharing a rank), rank_of(stat, player) and remove_player(player).
GSStatsStoreSql speaks SQLite, PostgreSQL and MySQL/MariaDB through GameSpice SQL, without needing it to parse. Writes are guarded by a revision, so two servers sharing a table add up instead of overwriting. A failed write is kept for the next flush and never counts a counter twice.
A player's own client can report its own figures with the player's token and no integration credential:
var mine := GSStatsClient.new()
mine.schema = schema
mine.client = auth_client # gs-auth's GSAuthClient
add_child(mine)
mine.record(&"launches")
var held := await mine.fetch_mine()Both land on the same rows. Keep anything competitive on the server; this is for a diary.
tools/export_site_defs.gd writes a game's published stats as the site's gs-stat-defs JSON, from the schema the game really builds, so the site owner imports it instead of retyping it. Run it from the game project with Godot headless as a script, passing --source (a script path), --method (the function returning the GSStatsSchema) and --out.
| Option | Does |
|---|---|
--check |
Writes nothing and exits 1 when the file on disk is stale. |
--game <id> |
Pins the site app id. Left out by default so one file imports anywhere. |
The file is GSStatsSchema.to_site_defs(). A scaled difference is skipped with a warning, because the site's diff ignores scale.
Import the project once, then run examples/stats_selftest.tscn headless with Godot. examples/stats_sql_live.tscn runs the SQL store against real databases through ../gs-sql/tools/test_live.sh. More in docs/.
All of these games from Zee's Games vendor this addon:
- Fatal Contact
- Airdrift
- Playlot
- Hungario
- Buses From Hell
- Smash Copter
- Zombie Zone
- Hide n Seek
- Prop Hunt
- Murder Mystery
- Deathrun
- Wipeout
- Dangerous Delivery
- Look At Me
The whole collection is at zeesgames.com.
MIT licence, see LICENSE. The only closed part of the GameSpice platform is the web back end; you can use your own instead of GameSpice's.
