Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement sar_speedrun_triggers_info #301

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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