@@ -24,6 +24,7 @@ static rf::Player* g_spectate_mode_target;
24
24
static rf::Camera* g_old_target_camera = nullptr ;
25
25
static bool g_spectate_mode_enabled = false ;
26
26
static bool g_spawned_in_current_level = false ;
27
+ static bool g_spectate_mode_follow_killer = false ;
27
28
28
29
void player_fpgun_set_player (rf::Player* pp);
29
30
@@ -203,6 +204,18 @@ bool multi_spectate_execute_action(rf::ControlConfigAction action, bool was_pres
203
204
return false ;
204
205
}
205
206
207
+ void multi_spectate_on_player_kill (rf::Player* victim, rf::Player* killer)
208
+ {
209
+ if (!g_spectate_mode_enabled) {
210
+ return ;
211
+ }
212
+ if (g_spectate_mode_follow_killer && g_spectate_mode_target == victim && killer != rf::local_player) {
213
+ // spectate killer if we were spectating victim
214
+ // avoid spectating ourselves if we somehow managed to kill the victim
215
+ multi_spectate_set_target_player (killer);
216
+ }
217
+ }
218
+
206
219
void multi_spectate_on_destroy_player (rf::Player* player)
207
220
{
208
221
if (player != rf::local_player) {
@@ -272,6 +285,15 @@ static ConsoleCommand2 spectate_mode_minimal_ui_cmd{
272
285
" Toggles spectate mode minimal UI" ,
273
286
};
274
287
288
+ static ConsoleCommand2 spectate_mode_follow_killer_cmd{
289
+ " spectate_mode_follow_killer" ,
290
+ []() {
291
+ g_spectate_mode_follow_killer = !g_spectate_mode_follow_killer;
292
+ rf::console::printf (" Follow killer mode is %s" , g_spectate_mode_follow_killer ? " enabled" : " disabled" );
293
+ },
294
+ " When a player you're spectating dies, automatically spectate their killer" ,
295
+ };
296
+
275
297
#if SPECTATE_MODE_SHOW_WEAPON
276
298
277
299
static void player_render_new (rf::Player* player)
@@ -322,6 +344,7 @@ void multi_spectate_appy_patch()
322
344
323
345
spectate_cmd.register_cmd ();
324
346
spectate_mode_minimal_ui_cmd.register_cmd ();
347
+ spectate_mode_follow_killer_cmd.register_cmd ();
325
348
326
349
// Note: HUD rendering doesn't make sense because life and armor isn't synced
327
350
0 commit comments