MLFeed: Race Data

A plugin by XertroV(Trusted developer)

MLFeed: Race Data
Downloads 62,889
Updated 9 days ago
Released 2 years ago
Created 2 years ago
Numeric ID 255
Min. Openplanet 1.26.0
Signed
Game Trackmania

MLFeed: Race Data

This plugin provides other plugins with data about the current race. You might need to install it to make other plugins work.

Requires MLHook (you need to install that plugin too)

Please report performance issues! See bottom of page for who/where.

For Developers

Currently exposed data:

  • Sorted Player data
    • For each player: LatestCPTime, CPCount, Cached Previous CP Times, Spawn Status, Best Time, Best CP Times, Best Lap Times, Time Lost to Respawns (in total and per CP), NbRespawns
    • Sort methods
      • TimeAttack: sort by best time
      • Race: sorted by race leader
      • Race_Respawns: sorted by race leader, but updates ranking immediately when a player respawns to account for time-loss
  • Knockout data (for COTD / KO)
    • Per-Player Alive and DNF status
    • Total Rounds, Current Round, Alive Players, Number of KOs This Round, Next KO Milestone, Number of Players (originally)
  • The last record set by the current player
  • Ghost Data
    • Which ghosts have been loaded, the name of the ghost, and the ghost's checkpoint times.

Additional data exposure available upon request.

Using MLFeed: Race Data

Some plugins already using MLFeed:

Importing to your plugin

Include this in your info.toml file:

[script]
dependencies = ["MLHook", "MLFeedRaceData"] # need both

see also: https://openplanet.dev/docs/reference/info-toml

Usage: Getting started

Note: it is recommended that you use the Openplanet VSCode extension which will provide autocompletion and documentation for you when using MLFeed.

Main Entry Points

Several feeds are available that provide different information. The functions that provide the feeds are:

  • auto RaceData = MLFeed::GetRaceData_V4()
  • auto KoData = MLFeed::GetKoData() -- for knockout mode (including COTD KO)
  • auto GhostData = MLFeed::GetGhostData() -- info about loaded ghosts
  • auto MMData = MLFeed::GetTeamsMMData_V1() -- info about matchmaking
  • auto MapListUids = MLFeed::Get_MapListUids_Receiver() -- info about the server map list

The main info for players can be accessed via the sorted RaceData lists, getting via name, or getting via login:

  • auto player = RaceData.GetPlayer_V4(name)
  • auto player = RaceData.GetPlayer_V4_ByLogin(login)
  • auto leadInRace = cast<MLFeed::PlayerCpInfo_V4>(RaceData.SortedPlayers_Race[0])
  • auto leadInRace = cast<MLFeed::PlayerCpInfo_V4>(RaceData.SortedPlayers_RaceRespawns[0])
  • auto leadInTA = cast<MLFeed::PlayerCpInfo_V4>(RaceData.SortedPlayers_TimeAttack[0])

Note: all player classes can be cast to MLFeed::PlayerCpInfo_V4 -- the sorted arrays contain MLFeed::PlayerCpInfo_V2 for historical reasons.

PlayerCpInfo contains checkpoint and race data, respawn info, and a bunch of other useful info.

Full docs can be found in the export files:

Race Data Example

Main type: HookRaceStatsEventsBase_V4

Example usage: doing something on player respawn.

uint lastRespawnCount = 0;

void Update(float dt) {
    if (GetApp().CurrentPlayground is null) return;
    // Get race data and the local player
    auto RaceData = MLFeed::GetRaceData_V4();
    auto player = RaceData.GetPlayer_V4(MLFeed::LocalPlayersName);
    if (player is null) return;
    // check for respawns
    if (player.NbRespawnsRequested != lastRespawnCount) {
        lastRespawnCount = player.NbRespawnsRequested;
        if (lastRespawnCount != 0) {
            startnew(OnPlayerRespawn);
        }
    }
}

void OnPlayerRespawn() {
    // do stuff
}

Docs at end

Usage: See Also

The Demo UIs available in (openplanet's) developer mode (via Scripts menu) & associated source code in the repo.

Exported functions (https://github.com/XertroV/tm-mlfeed-race-data/blob/manialink-base/src/MLFeed_Export.as)

Exported classes (https://github.com/XertroV/tm-mlfeed-race-data/blob/manialink-base/src/MLFeed_ExportShared.as)

Example Usage - COTD Buffer Time

Example Usage - Race Stats

Example Optional Usage - List Players' PBs

Still curious about how to use something? Read the examples and use github search to find usages! Still not sure? Ask @XertroV on the Openplanet Discord

Boring Stuff

License: Public Domain

Authors: XertroV

Suggestions/feedback: @XertroV on Openplanet discord

Code/issues: https://github.com/XertroV/tm-mlfeed-race-data

GL HF

Changelog

0.6.2 - 9 days ago

  • Fix const on PlayersLeftThisBatch and friends
  • Fix edge case sorting unspawned players with race ranking
  • Fix spawn counter and spawn index so spawn indexes are the same for players spawning on the same frame

0.6.1 - 22 days ago

  • Fix ML exception in ShouldUpdatePlayers

0.6.0 - 24 days ago

A game restart may be required after updating

  • optimized RaceStatsFeed: 40% reduction in frame time (approx 0.5ms reduction in full COTD server)
  • Added List Server Map UIDs. Access it via MapListUids_Receiver@ MLFeed::Get_MapListUids_Receiver()
    • Methods/Properties
    • bool MapList_Request() - initiate a request, does nothing & returns false if a request is already in progress. Max 25* UIDs are returned.
    • bool MapList_Request_Larger(int nbMaxUids) - as above but increases the number of UIDs returned for the next request only.
    • bool MapList_IsInProgress - is a request in progress
    • const array<string>@ MapList_Names - names of maps returned from the MapList request. Limited to 25* for performance reasons.
    • const array<string>@ MapList_MapUids - map UIDs returned from the MapList request. Limited to 25* for performance reasons, but it's the slice starting immediately after the current map.
    • uint UpdateCount - incremented whenever data is received from the Maniascript component
    • uint64 LastRequestStart - Time::Now when the last request started
    • uint64 LastRequestEnd - Time::Now when the last request finished
    • uint64 MsSinceLastReqStart - millis since LastRequestStart
    • uint64 MsSinceLastReqEnd - millis since LastRequestEnd
    • int Slice_StartIx - Start index of the slice of map uids shown.
    • int Slice_EndIx - End index of the slice of map uids shown; can be greater than Slice_NbMaps.
    • int Slice_NbMaps - The complete number of maps in the MapList response.
    • int MapOrigIxInList - The original index of the map in the UID list when the map loaded. (If you update the current map in the map list later, this is important information to know.)
    • string MapOrigIxInListUid - The UID of the map for which MapOrigIxInList applies.
    • string[]@ GetUidSlice_Async(int startIx, int endIx) - Read a slice from MapList_MapUids. Will yield for 1-3 frames in total.
  • Added PlayerCpInfo_V4@ HookRaceStatsEventsBase_V2::GetPlayer_V4_ByLogin(const string &in login)
  • Added int HookRaceStatsEventsBase::get_Rules_MillisSinceStart()
    • Mostly returns: GameTime - StartTime; the time (in ms) since the game mode started, or -1 if the game mode hasn't started yet or is an invalid (map loading?) state.
  • Added int HookRaceStatsEventsBase::get_Rules_TimeElapsed()
    • Milliseconds since the game mode started, or -1 if the game mode hasn't started yet or is an invalid (map loading?) state.
  • Added int HookRaceStatsEventsBase::get_Rules_TimeRemaining()
    • Milliseconds left in the game mode, or -1 if the game mode hasn't started yet or is infinite (or maybe if we're in an invalid state).
  • Added bool HookRaceStatsEventsBase::IsRemainingRulesTimeLessThan(int durationMs)
    • Convenience function to check there is a valid time remaining and that it is less than the given duration.
  • Added uint HookRaceStatsEventsBase::PlayersLeft_BatchNumber
  • Added string[]@ HookRaceStatsEventsBase::PlayersLeftThisBatch
  • Added uint[]@ HookRaceStatsEventsBase::PlayersLeftThisBatch_LoginIdValues
  • Added int PlayerCpInfo_V2::get_FinishTime()
    • Player's current Finish time as on their chronometer (2^31 - 1 if not finished)
  • Added MwId PlayerCpInfo_V4::LoginMwId
  • Added MwId PlayerCpInfo_V4::NameMwId
  • Add const PlayerCpInfo_V4@ HookRaceStatsEventsBase_V4::get_LocalPlayer()
    • It will always be the local player and is essentially free to get.
  • Add MLFeed::LocalPlayersLoginIdValue
    • Returns the MwId::Value for the local player's login.
  • Add local player to race data demo UI.
  • Fix PlayerCpInfo_V4::FindCSmPlayer() not being const
  • There might be a bug with KoStats::roundNb and friend not resetting. If such a bug exists, it might have been fixed.

*: there's an off by 1 error with the number of uids returned, so the max is 1 more than specified.

View all changelogs