Skip to content

Commit d15c37b

Browse files
authored
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
1 parent 8942ec4 commit d15c37b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

docs/cvars.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@
524524
|sar_speedrun_stop|cmd|sar_speedrun_stop - stop the speedrun timer|
525525
|sar_speedrun_stop_in_menu|0|Automatically stop the speedrun timer when the menu is loaded.|
526526
|sar_speedrun_time_pauses|0|Include time spent paused in the speedrun timer.|
527+
|sar_speedrun_triggers_info|0|Print player velocity (and position) upon mtrigger activation.<br>1 - position and velocity<br>2 - only horizontal velocity|
527528
|sar_sr_hud|0|Draws speedrun timer.|
528529
|sar_sr_hud_font_color|255 255 255 255|RGBA font color of speedrun timer HUD.|
529530
|sar_sr_hud_font_index|70|Font index of speedrun timer HUD.|

src/Features/Speedrun/Categories.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Event.hpp"
55
#include "Features/Demo/DemoGhostPlayer.hpp"
66
#include "Features/Hud/Hud.hpp"
7+
#include "Modules/Client.hpp"
78
#include "Modules/Engine.hpp"
89
#include "Modules/Server.hpp"
910
#include "SpeedrunTimer.hpp"
@@ -20,6 +21,7 @@
2021
#endif
2122

2223
Variable sar_speedrun_draw_triggers("sar_speedrun_draw_triggers", "0", "Draw the triggers associated with speedrun rules in the world.\n");
24+
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");
2325

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

118120
rule->fired = true;
121+
122+
// Handle `sar_speedrun_triggers_info`
123+
int info = sar_speedrun_triggers_info.GetInt();
124+
if (info == 0) return;
125+
126+
void *player = client->GetPlayer(GET_SLOT() + 1);
127+
if (!player) return;
128+
129+
Vector pos = client->GetAbsOrigin(player);
130+
Vector vel = client->GetLocalVelocity(player);
131+
132+
if (info == 1) {
133+
// Info type 1 prints everything
134+
console->Print("Player triggered rule '%s':\n", name.c_str());
135+
console->Print(" Position: %.2f %.2f %.2f\n", pos.x, pos.y, pos.z);
136+
console->Print(" Velocity: %.2f %.2f %.2f\n", vel.x, vel.y, vel.z);
137+
} else if (info == 2) {
138+
// Info type 2 prints just the horizontal velocity
139+
console->Print("Player velocity on last rule: %.2f\n", vel.Length2D());
140+
}
119141
}
120142

121143
ON_EVENT(PRE_TICK) {

0 commit comments

Comments
 (0)