bhoptimer icon indicating copy to clipboard operation
bhoptimer copied to clipboard

VScript API

Open rtldg opened this issue 9 months ago • 1 comments

NOTE: hasn't had a lot of testing in real scripts

Requirements (which are very incompatible with 64-bit):

Before vscript, checkpoints only saved these because maps couldn't do much:

  • targetname
  • classname
  • events (from FireInput & whatever)

~~(note the lack of player_speedmod disabled-buttons in there! I still need to add that TODO!)~~

Since you can do a lot of funky stuff with vscript (and a mapper is already asking for vscript checkpoint support), these are the vscript/squirrel API I think should be enough.

And thank gosh I added StringMap cp_cache_t::customdata for this kind of thing a million years ago!

// Timer provided functions:
// - function Timer_SetCheckpointCustomData(player, key, value)
//   Sets a string value.
//   (only usable from Timer_OnCheckpointSave)
// - function Timer_GetCheckpointCustomData(player, key)
//   Returns a string value.
//   (only usable from Timer_OnCheckpointLoadPre & Timer_OnCheckpointLoadPost)
// - function Timer_GetTime(player)
//   Can be used anywhere and returns a float for the player's current run time.
// - function Timer_GetStatus(player)
//   Can be used anywhere and returns an int. 0=stopped, 1=running, 2=paused.
// - function Timer_GetTrack(player)
//   Can be used anywhere and returns an int. 0=main, 1 or higher = a bonus track.

// Functions that maps can implement (with examples):
::Timer_OnStart <- function(player, track)
{
    PlayerReset()
}
::Timer_OnFinish <- function(player, track)
{
    // idk
}
::Timer_OnCheckpointSave <- function(player)
{
    Timer_SetCheckpointCustomData(player, "mystate", "floating")
}
::Timer_OnCheckpointLoadPre <- function(player)
{
    local mystate = Timer_GetCheckpointCustomData(player, "mystate")
    //do something with mystate here lol
}
::Timer_OnCheckpointLoadPost <- function(player)
{
    local mystate = Timer_GetCheckpointCustomData(player, "mystate")
    //do something with mystate here lol
}

TODO:

  • Indicate in OnCheckpointLoad if it's like a Segmented style checkpoint or like a kz checkpoint.
  • Figure out a good way to indicate that a checkpoint is actually from a bot or something idk...
    • Maybe let the mapper find it out in OnCheckpointLoad when parsing the custom data and finding it empty?

rtldg avatar Mar 06 '25 14:03 rtldg

vscript.inc line 9 - vaires -> varies line 114 - it's -> its line 317 - Return whenever if -> Return whether or not(?)

hehe

typo fixes like that should go into the upstream vscript repo

rtldg avatar Jun 21 '25 12:06 rtldg