Add /unspec command

This commit is contained in:
KebsCS 2024-09-10 00:16:55 +02:00
parent b5d662622c
commit 34871095dc
No known key found for this signature in database
GPG key ID: 5A8C0761A75E7309
5 changed files with 40 additions and 0 deletions

View file

@ -376,6 +376,37 @@ void CGameContext::ConToggleSpec(IConsole::IResult *pResult, void *pUserData)
ToggleSpecPause(pResult, pUserData, g_Config.m_SvPauseable ? CPlayer::PAUSE_SPEC : CPlayer::PAUSE_PAUSED);
}
void CGameContext::ConUnspec(IConsole::IResult *pResult, void *pUserData)
{
if(!CheckClientId(pResult->m_ClientId))
return;
CGameContext *pSelf = (CGameContext *)pUserData;
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId];
if(!pPlayer)
return;
int PauseState = pPlayer->IsPaused();
int PauseType = g_Config.m_SvPauseable ? CPlayer::PAUSE_SPEC : CPlayer::PAUSE_PAUSED;
if(PauseState > 0)
{
IServer *pServ = pSelf->Server();
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "You are force-paused for %d seconds.", (PauseState - pServ->Tick()) / pServ->TickSpeed());
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chatresp", aBuf);
}
else
{
if(-PauseState != CPlayer::PAUSE_NONE && PauseType != CPlayer::PAUSE_NONE)
{
pPlayer->Pause(CPlayer::PAUSE_NONE, false);
if(pPlayer->m_SpectatorId != pResult->m_ClientId)
pPlayer->SpectateFreeView();
}
}
}
void CGameContext::ConToggleSpecVoted(IConsole::IResult *pResult, void *pUserData)
{
ToggleSpecPauseVoted(pResult, pUserData, g_Config.m_SvPauseable ? CPlayer::PAUSE_SPEC : CPlayer::PAUSE_PAUSED);

View file

@ -3747,6 +3747,7 @@ void CGameContext::RegisterChatCommands()
Console()->Register("converse", "r[message]", CFGFLAG_CHAT | CFGFLAG_SERVER | CFGFLAG_NONTEEHISTORIC, ConConverse, this, "Converse with the last person you whispered to (private message)");
Console()->Register("pause", "?r[player name]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTogglePause, this, "Toggles pause");
Console()->Register("spec", "?r[player name]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConToggleSpec, this, "Toggles spec (if not available behaves as /pause)");
Console()->Register("unspec", "", CFGFLAG_CHAT | CFGFLAG_SERVER, ConUnspec, this, "Stops spectating the current player and returns to free view mode");
Console()->Register("pausevoted", "", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTogglePauseVoted, this, "Toggles pause on the currently voted player");
Console()->Register("specvoted", "", CFGFLAG_CHAT | CFGFLAG_SERVER, ConToggleSpecVoted, this, "Toggles spec on the currently voted player");
Console()->Register("dnd", "?i['0'|'1']", CFGFLAG_CHAT | CFGFLAG_SERVER | CFGFLAG_NONTEEHISTORIC, ConDND, this, "Toggle Do Not Disturb (no chat and server messages)");

View file

@ -426,6 +426,7 @@ private:
static void ConTogglePause(IConsole::IResult *pResult, void *pUserData);
static void ConTogglePauseVoted(IConsole::IResult *pResult, void *pUserData);
static void ConToggleSpec(IConsole::IResult *pResult, void *pUserData);
static void ConUnspec(IConsole::IResult *pResult, void *pUserData);
static void ConToggleSpecVoted(IConsole::IResult *pResult, void *pUserData);
static void ConForcePause(IConsole::IResult *pResult, void *pUserData);
static void ConTeamTop5(IConsole::IResult *pResult, void *pUserData);

View file

@ -867,6 +867,12 @@ void CPlayer::SpectatePlayerName(const char *pName)
}
}
void CPlayer::SpectateFreeView()
{
if(m_SpectatorId >= 0)
m_SpectatorId = SPEC_FREEVIEW;
}
void CPlayer::ProcessScoreResult(CScorePlayerResult &Result)
{
if(Result.m_Success) // SQL request was successful

View file

@ -67,6 +67,7 @@ public:
const CCharacter *GetCharacter() const;
void SpectatePlayerName(const char *pName);
void SpectateFreeView();
//---------------------------------------------------------
// this is used for snapping so we know how we can clip the view for the player