Skip to content

Commit

Permalink
feat: implement sar_speedrun_triggers_info (#301)
Browse files Browse the repository at this point in the history
* feat: implement `sar_speedrun_triggers_info`

* feat: print `sar_speedrun_triggers_info` on all splits

* feat: co-op support for `sar_speedrun_triggers_info`

* docs: doc cvar
  • Loading branch information
p2r3 authored Jan 15, 2025
1 parent 8942ec4 commit d15c37b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/cvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@
|sar_speedrun_stop|cmd|sar_speedrun_stop - stop the speedrun timer|
|sar_speedrun_stop_in_menu|0|Automatically stop the speedrun timer when the menu is loaded.|
|sar_speedrun_time_pauses|0|Include time spent paused in the speedrun timer.|
|sar_speedrun_triggers_info|0|Print player velocity (and position) upon mtrigger activation.<br>1 - position and velocity<br>2 - only horizontal velocity|
|sar_sr_hud|0|Draws speedrun timer.|
|sar_sr_hud_font_color|255 255 255 255|RGBA font color of speedrun timer HUD.|
|sar_sr_hud_font_index|70|Font index of speedrun timer HUD.|
Expand Down
22 changes: 22 additions & 0 deletions src/Features/Speedrun/Categories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Event.hpp"
#include "Features/Demo/DemoGhostPlayer.hpp"
#include "Features/Hud/Hud.hpp"
#include "Modules/Client.hpp"
#include "Modules/Engine.hpp"
#include "Modules/Server.hpp"
#include "SpeedrunTimer.hpp"
Expand All @@ -20,6 +21,7 @@
#endif

Variable sar_speedrun_draw_triggers("sar_speedrun_draw_triggers", "0", "Draw the triggers associated with speedrun rules in the world.\n");
Variable sar_speedrun_triggers_info("sar_speedrun_triggers_info", "0", "Print player velocity (and position) upon mtrigger activation.\n1 - position and velocity\n2 - only horizontal velocity\n");

static std::optional<std::vector<std::string>> extractPartialArgs(const char *str, const char *cmd) {
while (*cmd) {
Expand Down Expand Up @@ -116,6 +118,26 @@ static void dispatchRule(std::string name, SpeedrunRule *rule) {
}

rule->fired = true;

// Handle `sar_speedrun_triggers_info`
int info = sar_speedrun_triggers_info.GetInt();
if (info == 0) return;

void *player = client->GetPlayer(GET_SLOT() + 1);
if (!player) return;

Vector pos = client->GetAbsOrigin(player);
Vector vel = client->GetLocalVelocity(player);

if (info == 1) {
// Info type 1 prints everything
console->Print("Player triggered rule '%s':\n", name.c_str());
console->Print(" Position: %.2f %.2f %.2f\n", pos.x, pos.y, pos.z);
console->Print(" Velocity: %.2f %.2f %.2f\n", vel.x, vel.y, vel.z);
} else if (info == 2) {
// Info type 2 prints just the horizontal velocity
console->Print("Player velocity on last rule: %.2f\n", vel.Length2D());
}
}

ON_EVENT(PRE_TICK) {
Expand Down

0 comments on commit d15c37b

Please sign in to comment.