Skip to content

Commit 537e7c5

Browse files
authored
New spectate commands (#1611)
* init * find player client side * commands to select players and spectate the selected player * example config, spectate left right of current spectate target * fastest player * add last hurt/shooter/event/attacker/killer/ghoster commands and move all command checks to neo_player * added some more comands to the example config, changed observer mode for recent commands if player not in a observer mode that follows the player * cleanup * make and sort the list regardless, just write down all the possible commands, this config is meant to be copied and changed
1 parent 15a0796 commit 537e7c5

File tree

10 files changed

+566
-25
lines changed

10 files changed

+566
-25
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// set the following to ensure players dont move around the hud when changing star or class or dying
2+
// cl_neo_squad_hud_sort_players_by_class_alive_and_star to 0
3+
4+
bind 1 "spec_player_by_hud_position 0"
5+
bind 2 "spec_player_by_hud_position 1"
6+
bind 3 "spec_player_by_hud_position 2"
7+
bind 4 "spec_player_by_hud_position 3"
8+
bind 5 "spec_player_by_hud_position 4"
9+
bind 6 "spec_player_by_hud_position 5"
10+
bind 7 "spec_player_by_hud_position 6"
11+
bind 8 "spec_player_by_hud_position 7"
12+
bind 9 "spec_player_by_hud_position 8"
13+
bind 0 "spec_player_by_hud_position 9"
14+
15+
// The following do not make much sense in the old hud
16+
// cl_neo_squad_hud_original 0
17+
18+
bind mwheelup select_next_alive_player_in_hud
19+
bind mwheeldown select_previous_alive_player_in_hud
20+
bind mouse3 spectate_player_selected_in_hud
21+
// Ideally these replace spec_next and spec_previous
22+
bind mouse2 spec_next_entity_in_hud
23+
bind mouse1 spec_previous_entity_in_hud
24+
25+
bind mouse5 spec_player_under_mouse
26+
bind mouse4 spec_fastest_player
27+
28+
bind i spec_last_event
29+
bind o spec_last_hurt
30+
bind p spec_last_shooter
31+
bind j spec_last_attacker
32+
bind k spec_last_killer
33+
bind l spec_last_ghoster

src/game/client/c_baseplayer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,12 @@ bool C_BasePlayer::IsValidObserverTarget(CBaseEntity* target)
736736

737737
if (player->m_lifeState == LIFE_DEAD || player->m_lifeState == LIFE_DYING)
738738
{
739+
#ifdef NEO
740+
constexpr int DEATH_SPEC_TIME = 3.0f; // OGNT switches spectator targets much faster than the DEATH_ANIMATION_TIME
741+
if ((player->m_flDeathTime + DEATH_SPEC_TIME) < gpGlobals->curtime)
742+
#else
739743
if ((player->m_flDeathTime + DEATH_ANIMATION_TIME) < gpGlobals->curtime)
744+
#endif // NEO
740745
{
741746
return false; // allow watching until 3 seconds after death to see death animation
742747
}

src/game/client/game_controls/SpectatorGUI.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,5 +986,50 @@ CON_COMMAND_F( spec_player, "Spectate player by partial name, steamid, or userid
986986
}
987987
}
988988

989+
#ifdef NEO
990+
CON_COMMAND_F( spec_player_under_mouse, "Spectate player by partial name, steamid, or userid", FCVAR_CLIENTCMD_CAN_EXECUTE )
991+
{
992+
C_NEO_Player *pNeoPlayer = C_NEO_Player::GetLocalNEOPlayer();
993+
if ( !pNeoPlayer || !pNeoPlayer->IsObserver() )
994+
return;
995+
996+
if (!engine->IsHLTV() || !HLTVCamera()->IsPVSLocked())
997+
{
998+
C_BaseEntity* currentTarget = pNeoPlayer->GetObserverTarget();
999+
C_NEO_Player *target = nullptr;
1000+
float targetDotProduct = -1;
1001+
for (int i = 1; i < gpGlobals->maxClients; i++)
1002+
{
1003+
C_NEO_Player* pPlayer = ToNEOPlayer(UTIL_PlayerByIndex(i));
1004+
if (currentTarget != pPlayer && pNeoPlayer->IsValidObserverTarget(pPlayer) && pPlayer->IsAlive())
1005+
{
1006+
Vector vecForward;
1007+
AngleVectors( pNeoPlayer->EyeAngles(), &vecForward );
1008+
1009+
Vector vecToTarget = pPlayer->WorldSpaceCenter() - pNeoPlayer->EyePosition();
1010+
vecToTarget.NormalizeInPlace();
1011+
float dotProduct = DotProduct(vecForward, vecToTarget);
1012+
if (dotProduct > targetDotProduct && dotProduct > 0.5)
1013+
{
1014+
targetDotProduct = dotProduct;
1015+
target = pPlayer;
1016+
}
1017+
}
1018+
}
1019+
1020+
if (target)
1021+
{
1022+
if (engine->IsHLTV())
1023+
{
1024+
HLTVCamera()->SetPrimaryTarget(target->entindex());
1025+
}
1026+
else
1027+
{
1028+
engine->ClientCmd( VarArgs("spec_player_entity_number %d", target->entindex()) );
1029+
}
1030+
}
1031+
}
1032+
}
1033+
#endif // NEO
9891034

9901035

0 commit comments

Comments
 (0)