Skip to content

Commit

Permalink
Added new variable
Browse files Browse the repository at this point in the history
// Continue match automatically at halftime if minimum players is in teams
// Disable to always start ready system at halftime state
//
// 0 Disabled
// 1 Enabled
//
// Default "1"
mb_ready_auto_continue "1"
  • Loading branch information
SmileYzn committed Jan 23, 2024
1 parent f21049c commit 29a3a5c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
26 changes: 16 additions & 10 deletions MatchBot/MatchBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ void CMatchBot::ServerActivate()
// Ready System timer delay in seconds
this->m_ReadyTime = gMatchUtil.CvarRegister("mb_ready_time", "60.0");

// Continue match automatically at halftime if minimum players is in teams
this->m_ReadyAuto = gMatchUtil.CvarRegister("mb_ready_auto_continue", "1");

// Team Pickup Type (-1 Enable vote, 0 Leaders, 1 Random, 2 None, 3 Skill Balanced, 4 Swap Teams, 5 Knife Round)
this->m_TeamPickupType = gMatchUtil.CvarRegister("mb_team_pick_type", "-1");

Expand Down Expand Up @@ -315,10 +318,10 @@ void CMatchBot::SetState(int State)
gMatchWarmup.Stop();

// Clear Scores
memset(this->m_Score, 0, sizeof(this->m_Score));
this->m_Score.fill({});

// Clear OT Scores
memset(this->m_ScoreOT, 0, sizeof(this->m_ScoreOT));
this->m_ScoreOT.fill(0);

// If is set to play knife round
if (this->m_PlayKnifeRound)
Expand Down Expand Up @@ -367,8 +370,8 @@ void CMatchBot::SetState(int State)
// If ready mode is enabled or timer system is enabled
if (this->m_ReadyType->value)
{
// If has less players than minimum required
if ((int)gMatchUtil.GetPlayers(true, true).size() < this->m_PlayersMin->value)
// If auto continue ready is not enabled, or if has less players than minimum required
if (static_cast<int>(this->m_ReadyAuto->value) == 0 || (static_cast<int>(gMatchUtil.GetPlayers(true, true).size()) < static_cast<int>(this->m_PlayersMin->value)))
{
// Send message
gMatchUtil.SayText(nullptr, PRINT_TEAM_DEFAULT, _T("^3%s^1 started, Get Ready!"), this->GetState(this->m_State));
Expand Down Expand Up @@ -575,7 +578,7 @@ void CMatchBot::SwapScores()
if (this->GetScore(TERRORIST) == this->GetScore(CT))
{
// Reset Overtime scores (We are restarting OT)
memset(this->m_ScoreOT, 0, sizeof(this->m_ScoreOT));
this->m_ScoreOT.fill(0);

// Do not swap teams or scores in first Overtime Half
return;
Expand Down Expand Up @@ -608,6 +611,9 @@ void CMatchBot::SwapTeams(int ShowMessage)
{
CSGameRules()->SwapAllPlayers();
}

// Restart Round
gMatchUtil.ServerCommand("sv_restart 1");
}

// Get Knife Round Mode
Expand Down Expand Up @@ -1128,10 +1134,10 @@ void CMatchBot::UpdateGameName()
if (g_pGameRules)
{
// Store original game description
if (!this->m_GameDesc[0])
if (!this->m_GameDesc.empty())
{
// Get default game name
Q_strncpy(this->m_GameDesc, CSGameRules()->GetGameDescription(), sizeof(this->m_GameDesc));
this->m_GameDesc = CSGameRules()->GetGameDescription();
}

// If is enabled
Expand All @@ -1144,7 +1150,7 @@ void CMatchBot::UpdateGameName()
if (State == STATE_DEAD)
{
// Restore default game name
Q_strcpy_s(CSGameRules()->m_GameDesc, this->m_GameDesc);
Q_strcpy(CSGameRules()->m_GameDesc, this->m_GameDesc.c_str());
}
else if (State == STATE_WARMUP || State == STATE_START)
{
Expand All @@ -1166,7 +1172,7 @@ void CMatchBot::UpdateGameName()
else
{
// Restore default game name
Q_strcpy_s(CSGameRules()->m_GameDesc, this->m_GameDesc);
Q_strcpy(CSGameRules()->m_GameDesc, this->m_GameDesc.c_str());
}
}
}
Expand Down Expand Up @@ -1479,7 +1485,7 @@ void CMatchBot::EndMatch(TeamName Loser, TeamName Winner)
auto HalfRounds = (int)(this->m_PlayRounds->value / 2.0f);

// Clear Scores
memset(this->m_Score, 0, sizeof(this->m_Score));
this->m_Score.fill({});

// Set Score winner
this->m_Score[Winner][STATE_FIRST_HALF] = HalfRounds;
Expand Down
9 changes: 5 additions & 4 deletions MatchBot/MatchBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ class CMatchBot
bool m_PlayKnifeRound = false;

// Scores
int m_Score[SPECTATOR + 1][STATE_END];
std::array<std::array<int, SPECTATOR + 1U>, STATE_END + 1U> m_Score;

// Overtime Scores
int m_ScoreOT[SPECTATOR + 1];
std::array<int, SPECTATOR + 1U> m_ScoreOT;

// Defaut game description
char m_GameDesc[32] = { 0 };
std::string m_GameDesc = "";

// Match Bot Config Variables
cvar_t* m_Config[STATE_END + 1];
std::array<cvar_t*, STATE_END + 1U> m_Config;

public:
// Match Bot Variables
Expand All @@ -178,6 +178,7 @@ class CMatchBot
cvar_t* m_PlayMode = nullptr;
cvar_t* m_ReadyType = nullptr;
cvar_t* m_ReadyTime = nullptr;
cvar_t* m_ReadyAuto = nullptr;
cvar_t* m_TeamPickupType = nullptr;
cvar_t* m_TeamPickMenu = nullptr;
cvar_t* m_VotePercent = nullptr;
Expand Down
9 changes: 9 additions & 0 deletions cstrike/addons/matchbot/cfg/matchbot.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ mb_ready_type "1"
// Default "60.0"
mb_ready_time "60.0"

// Continue match automatically at halftime if minimum players is in teams
// Disable to always start ready system at halftime state
//
// 0 Disabled
// 1 Enabled
//
// Default "1"
mb_ready_auto_continue "1"

// Team Pickup Type when match begin
//
// -1 Enable vote
Expand Down

0 comments on commit 29a3a5c

Please sign in to comment.