From d15c37bc5080a3d87056c104a0051604c323d4ec Mon Sep 17 00:00:00 2001 From: p2r3 <41925384+p2r3@users.noreply.github.com> Date: Wed, 15 Jan 2025 08:08:31 +0200 Subject: [PATCH] feat: implement `sar_speedrun_triggers_info` (#301) * 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 --- docs/cvars.md | 1 + src/Features/Speedrun/Categories.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/cvars.md b/docs/cvars.md index c3ef9bc8..5d92ae16 100644 --- a/docs/cvars.md +++ b/docs/cvars.md @@ -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.
1 - position and velocity
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.| diff --git a/src/Features/Speedrun/Categories.cpp b/src/Features/Speedrun/Categories.cpp index b276154e..06e21264 100644 --- a/src/Features/Speedrun/Categories.cpp +++ b/src/Features/Speedrun/Categories.cpp @@ -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" @@ -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> extractPartialArgs(const char *str, const char *cmd) { while (*cmd) { @@ -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) {